Aspose,如何用一个模板来导出到Excel

本文介绍如何使用 C# 向已存在的 Excel 文件中添加新的工作表。首先通过 FileStream 打开目标文件,然后利用 Workbook 类加载该文件。接着调用 Worksheets 的 Add 方法创建新工作表,并设置其名称。最后保存更改并关闭文件流。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2. Adding Worksheets to a Designer Spreadsheet

The process of adding worksheets to a designer spreadsheet is entirely same as that of the above approach except that the Excel file is already created and we need to open that Excel file first before adding worksheet to it. A designer spreadsheet can be opened by the Workbook class.

Example:

[C#]
//Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream("C:\\book1.xls", FileMode.Open);

//Instantiating a Workbook object
//Opening the Excel file through the file stream
Workbook workbook = new Workbook(fstream);

//Adding a new worksheet to the Workbook object
int i = workbook.Worksheets.Add();

//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[i];

//Setting the name of the newly added worksheet
worksheet.Name = "My Worksheet";

//Saving the Excel file
workbook.Save(saveFileDialog1.FileName);

//Closing the file stream to free all resources
fstream.Close();
 

 

转载于:https://www.cnblogs.com/MyFlora/archive/2012/04/13/2445285.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值