Skip to main content

IXlDocument.SetSheetPosition(String, Int32) Method

Changes the position of the specified worksheet within a workbook.

Namespace: DevExpress.Export.Xl

Assembly: DevExpress.Printing.v23.2.Core.dll

NuGet Package: DevExpress.Printing.Core

Declaration

void SetSheetPosition(
    string name,
    int position
)

Parameters

Name Type Description
name String

A String value specifying the name of the worksheet to be moved.

position Int32

A zero-based integer that is the position at which the worksheet should be inserted.

Remarks

The SetSheetPosition method locates a worksheet by its name in the document and moves it to the specified position. The position parameter should be between 0 and N-1, where N is the number of worksheets generated using the IXlDocument.CreateSheet method.

IXlExporter exporter = XlExport.CreateExporter(XlDocumentFormat.Xlsx);
using (FileStream stream = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite)) {
    using (IXlDocument document = exporter.CreateDocument(stream)) {
        // Create the first worksheet.
        using (IXlSheet sheet = document.CreateSheet()) {
            sheet.Name = "Sheet1"
            // ...
        }
        // Create the second worksheet.
        using (IXlSheet sheet = document.CreateSheet()) {
            sheet.Name = "Sheet2"
            // ...
        }
        // Create the third worksheet.
        using (IXlSheet sheet = document.CreateSheet()) {
            sheet.Name = "Sheet3"
            // ...
        }
        // Move the last worksheet to the first position within the document.
        document.SetSheetPosition("Sheet3", 0);
    }
}
See Also