Aspose如何用,第一步,Workbook

 

Worksheets

 

Managing worksheets using Aspose.Cells is as easy as ABC. In this section, we will describe that how can we:

  1. Create a new Excel file and add worksheet to it

 

Aspose.Cells provides a class, Workbook that represents an Excel file. Workbook class contains a Worksheets collection that allows to access each worksheet in the Excel file.

A worksheet is represented by the Worksheet class. Worksheet class provides a wide range of properties and methods to manage a worksheet. Let's see that how can we make use of these basic set of APIs.

  

1. Adding Worksheets to a New Excel File

 

To create a new Excel file programmatically, developers would need to create an object of Workbook class that represents an Excel file. Then developers can call Addmethod of the Worksheets collection. When we call Add method, an empty worksheet is added to the Excel file automatically, which can be referenced by passing the sheet index of the newly added worksheet to the Worksheets collection. After the worksheet reference is obtained, developers can work on their worksheets according to their requirements. After the work is done on the worksheets, developers can save their newly created Excel file with new worksheets by calling the Savemethod of the Workbook class.

Example:

[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();

//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);

 

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值