Reputation:
I use Microsoft Office Interop Excel for create excel file. My problem is that I dont know how specify name of excel file.
Variables:
// Excel object references.
private Application _excelApp;
private Workbooks _books;
private _Workbook _book;
private Sheets _sheets;
private _Worksheet _sheet;
Create excel file:
_excelApp = new Application();
_books = _excelApp.Workbooks;
_book = _books.Add(_optionalValue);
_sheets = _book.Worksheets;
_sheet = (_Worksheet)(_sheets.Item[1]);
_sheet.Name = sheetName;
How can I specify name of excel file during creating excel file? Sorry for my english.
EDIT:
I know that I can use
_book.SaveAs(fileName)
Upvotes: 1
Views: 5855
Reputation: 8871
i think you should check this. From the linked page:
public virtual void SaveAs (
[OptionalAttribute] Object Filename,
[OptionalAttribute] Object FileFormat,
[OptionalAttribute] Object Password,
[OptionalAttribute] Object WriteResPassword,
[OptionalAttribute] Object ReadOnlyRecommended,
[OptionalAttribute] Object CreateBackup,
[OptionalAttribute] XlSaveAsAccessMode AccessMode,
[OptionalAttribute] Object ConflictResolution,
[OptionalAttribute] Object AddToMru,
[OptionalAttribute] Object TextCodepage,
[OptionalAttribute] Object TextVisualLayout,
[OptionalAttribute] Object Local
)
Upvotes: 0
Reputation: 11090
Once you have created the Excel workbook and copies the data you want, you can simply save it as such
_book.SaveAs(outputPath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
The Type.Missing parameters were appropriate to my code that I took this snippet from, but you may have need for inclusion.
Upvotes: 4