Microsoft Office Interop Excel - 指定 Excel 文件的名称

发布于 2024-11-26 22:24:06 字数 672 浏览 0 评论 0原文

我使用 Microsoft Office Interop Excel 创建 Excel 文件。我的问题是我不知道如何指定 Excel 文件的名称。

变量:

// Excel object references.
private Application _excelApp;
private Workbooks _books;
private _Workbook _book;
private Sheets _sheets;
private _Worksheet _sheet;

创建Excel文件:

_excelApp = new Application();
_books = _excelApp.Workbooks;

_book = _books.Add(_optionalValue);

_sheets = _book.Worksheets;
_sheet = (_Worksheet)(_sheets.Item[1]);
_sheet.Name = sheetName;

创建Excel文件时如何指定Excel文件的名称?对不起我的英语。

编辑:

我知道我可以使用

_book.SaveAs(fileName)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

友谊不毕业 2024-12-03 22:24:06

创建 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);

Type.Missing 参数,该参数适合我从中获取此代码段的代码,但您可能需要包含在内。

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.

简单 2024-12-03 22:24:06

我认为你应该检查这个< /a>.从链接页面:

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
)

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
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文