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

     

  • 相关阅读:
    POJ3094 UVALive3594 HDU2734 ZOJ2812 Quicksum【进制】
    UVALive5583 UVA562 Dividing coins
    POJ1979 HDU1312 Red and Black【DFS】
    POJ1979 HDU1312 Red and Black【DFS】
    POJ2386 Lake Counting【DFS】
    POJ2386 Lake Counting【DFS】
    HDU4394 Digital Square
    HDU4394 Digital Square
    UVA213 UVALive5152 Message Decoding
    UVA213 UVALive5152 Message Decoding
  • 原文地址:https://www.cnblogs.com/MyFlora/p/2445268.html
Copyright © 2011-2022 走看看