Document.CreateWorksheet(Int32) Method

Creates a new worksheet and adds it to the specified position in the current document.

Namespace: SpreadsheetCloudAPI.SpreadsheetSDK
Assembly: SpreadsheetSDK.dll


public Worksheet CreateWorksheet( 
   int index 


Type: Int32
A zero-based integer value, specifying the worksheet index.

Return value

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


If the current document already contains a worksheet with the specified index, a new worksheet is added to the position specified by the index and all of the remaining worksheets are moved to the end of a document.

A new worksheet is created with the "SheetN" name, where N is a number following the largest number used in existing worksheet names of the same type.


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.

using System;
using System.Collections.Generic;
using SpreadsheetSDK;

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

            // SDK initialization

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

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

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

            // Terminate the session and save changes

See Also