Document.CreateWorksheet(String) Method

Creates a new worksheet with the specified name and adds the worksheet to the end of the current document.

Namespace: SpreadsheetCloudAPI.SpreadsheetSDK
Assembly: SpreadsheetSDK.dll

Syntax

C#
VB
public Worksheet CreateWorksheet( 
   string name 
)

Parameters

name
Type: String
A string value specifying the worksheet name.

Return value

Type: Worksheet
The Worksheet object that provides access to the created worksheet.

Remarks

To change the worksheet name, use the Worksheet.Name property. To change the worksheet position within the document, use the Worksheet.Index property.

Example

This example demonstrates how to add a new worksheet to a document. To do this, use the CreateWorksheet method.

To create a new worksheet and specify where it should be inserted, call the CreateWorksheet method with the zero-based worksheet index passed as a parameter.

To specify a worksheet name, use the Worksheet.Name property, or pass the worksheet name to the CreateWorksheet method as a parameter.

C#
using System;
using System.Collections.Generic;
using SpreadsheetSDK;

namespace SpreadsheetExample {
    class Program {
        static void Main() {

            // SDK initialization
            SpreadsheetSDK.Initialize("SPECIFY_YOUR_API_KEY_HERE");

            // Access the document that has been uploaded to the server
            Document doc = Document.Load("MyApplicationFile", "xlsx");

            // Add a new worksheet to the document
            // The worksheet will be inserted into the end of the document
            // Worksheet name is "SheetN", where N is a number following the largest number used in existing worksheet names of the same type
            doc.CreateWorksheet();

            // Add a new worksheet under the specified name
            doc.CreateWorksheet().Name = "TestSheet1";
            doc.CreateWorksheet("TestSheet2");

            // Add a new worksheet at the specified position in the collection of worksheets
            doc.CreateWorksheet("TestSheet3", 1);
            doc.CreateWorksheet(3);

            // Terminate the session and save changes
            doc.Close(true);
        }
    }
}

See Also