SheetData.LocalName Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient le nom local de l’élément.
public override string LocalName { get; }
member this.LocalName : string
Public Overrides ReadOnly Property LocalName As String
Valeur de propriété
Retourne String.
Exemples
L’exemple suivant crée un document de feuille de calcul, ajoute un classeur et ajoute une feuille de calcul nommée « 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