zoukankan      html  css  js  c++  java
  • 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);

     

  • 相关阅读:
    标准部件工具箱概述
    从数据库和文件夹中读取图片并且resize
    控件的Lookup
    分隔字符串并以List返回(strSplit函数)
    窗体中的选中数据传递给报表
    对筛选之后的grid进行求和统计
    动态添加图片控件例子
    利用CSV文件导入数据的例子
    调用打开文件的对话框
    ax设置数据源的操作
  • 原文地址:https://www.cnblogs.com/MyFlora/p/2445268.html
Copyright © 2011-2022 走看看