次の方法で共有


SheetData.LocalName プロパティ

定義

要素のローカル名を取得します。

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

プロパティ値

を返します String

次の例では、スプレッドシート ドキュメントを作成し、ブックを追加し、ワークシートを追加し、"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  

適用対象