SheetData.LocalName Property

Gets the local name of the element.

Namespace:  DocumentFormat.OpenXml.Spreadsheet
Assembly:  DocumentFormat.OpenXml (in DocumentFormat.OpenXml.dll)

Syntax

'Declaration
Public Overrides ReadOnly Property LocalName As String
    Get
'Usage
Dim instance As SheetData
Dim value As String

value = instance.LocalName
public override string LocalName { get; }

Property Value

Type: System.String
Returns String.

Examples

The following example creates a spreadsheet document, adds a workbook, and adds worksheet and named “mySheet.”

using System;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;

namespace SheetDataEx
{
    class Program
    {
        // Create a spreadsheet, and and a sheet into it.
        static void Main(string[] args)
        {
            string fileName = @"C:\Users\Public\Documents\SheetDataEx.xlsx";

           // Create a spreadsheet document by using the file path.
           SpreadsheetDocument spreadsheetDocument =
                SpreadsheetDocument.Create(fileName, SpreadsheetDocumentType.Workbook);

           // Add a WorkbookPart and Workbook objects.
            WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart();
            workbookpart.Workbook = new Workbook();

            // Add a WorksheetPart.
            WorksheetPart worksheetPart = workbookpart.AddNewPart<WorksheetPart>();

            // Create Worksheet and SheetData objects.
            worksheetPart.Worksheet = new Worksheet(new SheetData());

            // Add a Sheets object.
            Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook
                .AppendChild<Sheets>(new Sheets());

            // Append the new worksheet named "mySheet" and associate it 
            // with the workbook.
            Sheet sheet = new Sheet() { Id = spreadsheetDocument.WorkbookPart
                .GetIdOfPart(worksheetPart), SheetId = 1, Name = "mySheet" };
            sheets.Append(sheet);

            // Close the file.
            spreadsheetDocument.Close();

            Console.WriteLine("The Spreadsheet file is created. Press a key");
            Console.ReadKey();
        }
    }
}
Imports System
Imports DocumentFormat.OpenXml
Imports DocumentFormat.OpenXml.Packaging
Imports DocumentFormat.OpenXml.Spreadsheet

Module Module1

    Sub Main()
        Dim fileName As String = "C:\Users\Public\Documents\SheetDataEx.xlsx"

        ' Create a spreadsheet document by using the file path.
        Dim spreadsheetDocument As SpreadsheetDocument = _
            spreadsheetDocument.Create(fileName, SpreadsheetDocumentType.Workbook)

        ' Add a WorkbookPart and Workbook objects.
        Dim workbookpart As WorkbookPart = spreadsheetDocument.AddWorkbookPart()
        workbookpart.Workbook = New Workbook()

        ' Add a WorksheetPart.
        Dim worksheetPart As WorksheetPart = workbookpart.AddNewPart(Of WorksheetPart)()
        worksheetPart.Worksheet = New Worksheet(New SheetData())

        ' Create Worksheet and SheetData objects.
        worksheetPart.Worksheet = New Worksheet(New SheetData())

        ' Add a Sheets object.
        Dim sheets As Sheets = spreadsheetDocument.WorkbookPart.Workbook _
        .AppendChild(Of Sheets)(New Sheets())

        ' Append the new worksheet named "mySheet" and associate it 
        ' with the workbook.
        Dim sheet As New Sheet() With { _
         .Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), _
         .SheetId = 1, .Name = "mySheet"}

        sheets.Append(sheet)

        ' Close the file.
        spreadsheetDocument.Close()

        Console.WriteLine("The Spreadsheet file is created. Press a key")
        Console.ReadKey()
    End Sub 'Main
End Module

See Also

Reference

SheetData Class

SheetData Members

DocumentFormat.OpenXml.Spreadsheet Namespace