[英]Microsoft Office Interop Excel - Specify name of Excel file
I use Microsoft Office Interop Excel for create excel file. 我使用Microsoft Office Interop Excel创建Excel文件。 My problem is that I dont know how specify name of excel file.
我的问题是我不知道如何指定Excel文件的名称。
Variables: 变量:
// Excel object references.
private Application _excelApp;
private Workbooks _books;
private _Workbook _book;
private Sheets _sheets;
private _Worksheet _sheet;
Create excel file: 创建Excel文件:
_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? 创建Excel文件时如何指定Excel文件名? Sorry for my english.
对不起我的英语不好。
EDIT: 编辑:
I know that I can use 我知道我可以用
_book.SaveAs(fileName)
Once you have created the Excel workbook and copies the data you want, you can simply save it as such 创建Excel工作簿并复制所需的数据后,只需将其保存为
_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. Type.Missing参数适用于我从中摘录的代码,但是您可能需要包含这些参数。
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
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.