Freigeben über


SheetData.LocalName Eigenschaft

Definition

Ruft den lokalen Namen des Elements ab.

public override string LocalName { get; }
member this.LocalName : string
Public Overrides ReadOnly Property LocalName As String

Eigenschaftswert

Gibt zurück String.

Beispiele

Im folgenden Beispiel wird ein Tabellenkalkulationsdokument erstellt, eine Arbeitsmappe und ein Arbeitsblatt mit dem Namen "mySheet" hinzugefügt.

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  

Gilt für: