WorksheetCollection.Add

Add(SheetType)

Adds a worksheet to the collection.

public int Add(SheetType type)
ParameterTypeDescription
typeSheetTypeWorksheet type.

Return Value

Worksheet object index.

Examples

using System;
using Aspose.Cells;
using Aspose.Cells.Charts;

namespace AsposeCellsExamples
{
    public class WorksheetCollectionMethodAddWithSheetTypeDemo
    {
        public static void Run()
        {
            Workbook workbook = new Workbook();
            
            // Add a new chart sheet using SheetType parameter
            workbook.Worksheets.Add(SheetType.Chart);
            
            // Add data to the first worksheet
            Cells cells = workbook.Worksheets[0].Cells;
            cells["C2"].PutValue(5000);
            cells["C3"].PutValue(3000);
            cells["C4"].PutValue(4000);
            cells["C5"].PutValue(5000);
            cells["C6"].PutValue(6000);
            
            // Create chart in the chart sheet
            Aspose.Cells.Charts.ChartCollection charts = workbook.Worksheets[1].Charts;
            int chartIndex = charts.Add(Aspose.Cells.Charts.ChartType.Column, 10, 10, 20, 20);
            Aspose.Cells.Charts.Chart chart = charts[chartIndex];
            chart.NSeries.Add("Sheet1!C2:C6", true);
            
            // Save the workbook (optional)
            // workbook.Save("output.xlsx");
        }
    }
}

See Also


Add()

Adds a worksheet to the collection.

public int Add()

Return Value

Worksheet object index.

See Also


Add(string)

Adds a worksheet to the collection.

public Worksheet Add(string sheetName)
ParameterTypeDescription
sheetNameStringWorksheet name

Return Value

Worksheet object.

Examples

using System;
using Aspose.Cells;

namespace AsposeCellsExamples
{
    public class WorksheetCollectionMethodAddWithStringDemo
    {
        public static void Run()
        {
            Workbook wb = new Workbook();
            Worksheet worksheet = wb.Worksheets.Add("NewSheet");
            
            // Add data to the new worksheet
            worksheet.Cells["A1"].PutValue("Worksheet added successfully!");
            
            // Save the workbook
            wb.Save("WorksheetCollectionMethodAddWithStringDemo_output.xlsx");
        }
    }
}

See Also