Skip to content

Commit 3aa05a4

Browse files
committed
clean up docs\spreadsheet\structure-of-a-spreadsheetml-document.md
1 parent 169f3d8 commit 3aa05a4

File tree

3 files changed

+47
-49
lines changed

3 files changed

+47
-49
lines changed

docs/spreadsheet/structure-of-a-spreadsheetml-document.md

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ ms.suite: office
1111
ms.author: o365devx
1212
author: o365devx
1313
ms.topic: conceptual
14-
ms.date: 11/01/2017
14+
ms.date: 01/14/2025
1515
ms.localizationpriority: high
1616
---
1717
# Structure of a SpreadsheetML document
1818

19-
The document structure of a **SpreadsheetML**
20-
document consists of the \<**workbook**\>
21-
element that contains \<**sheets**\> and
22-
\<**sheet**\> elements that reference the
19+
The document structure of a `SpreadsheetML`
20+
document consists of the `<workbook/>`
21+
element that contains `<sheets/>` and
22+
`<sheet/>` elements that reference the
2323
worksheets in the workbook. A separate XML file is created for each
2424
worksheet. These elements are the minimum elements required for a valid
2525
spreadsheet document. In addition, a spreadsheet document might contain
26-
\<**table**\>, \<**chartsheet**\>, \<**pivotTableDefinition**\>, or other spreadsheet
26+
`<table/>`, `<chartsheet/>`, `<pivotTableDefinition/>`, or other spreadsheet
2727
related elements.
2828

2929
[!include[Add-ins note](../includes/addinsnote.md)]
@@ -32,25 +32,25 @@ related elements.
3232
## Important Spreadsheet Parts
3333

3434
Using the Open XML SDK for Office, you can create document structure
35-
and content that uses strongly-typed classes that correspond to **SpreadsheetML** elements. You can find these
36-
classes in the **DocumentFormat.OpenXML.Spreadsheet** namespace. The
35+
and content that uses strongly-typed classes that correspond to `SpreadsheetML` elements. You can find these
36+
classes in the `DocumentFormat.OpenXML.Spreadsheet` namespace. The
3737
following table lists the class names of the classes that correspond to
3838
some of the important spreadsheet elements.
3939

4040

4141
| Package Part| Top Level SpreadsheetML Element | Open XML SDK Class | Description|
4242
|:------------|:--------------------------------|:-----------------------|:-----------|
43-
| Workbook | workbook | <xref:DocumentFormat.OpenXml.Spreadsheet.Workbook> | The root element for the main document part.|
44-
| Worksheet | worksheet | <xref:DocumentFormat.OpenXml.Spreadsheet.Worksheet> | A type of sheet that represent a grid of cells that contains text, numbers, dates or formulas. For more information, see [Working with sheets](working-with-sheets.md). |
45-
|Chart Sheet | chartsheet | <xref:DocumentFormat.OpenXml.Spreadsheet.Chartsheet> | A sheet that represents a chart that is stored as its own sheet. For more information, see [Working with sheets](working-with-sheets.md). |
46-
| Table | table | <xref:DocumentFormat.OpenXml.Spreadsheet.Table> | A logical construct that specifies that a range of data belongs to a single dataset. For more information, see [Working with SpreadsheetML tables](overview.md). |
47-
|Pivot Table | <xref:DocumentFormat.OpenXml.Spreadsheet.PivotTableDefinition> | <xref:DocumentFormat.OpenXml.Spreadsheet.PivotTableDefinition> | A logical construct that displays aggregated view of data in an understandable layout. For more information, see [Working with PivotTables](working-with-pivottables.md). |
48-
|Pivot Cache | pivotCacheDefinition | <xref:DocumentFormat.OpenXml.Spreadsheet.PivotCacheDefinition> | A construct that defines the source of the data in the PivotTable. For more information, see [Working with PivotTables](working-with-pivottables.md). |
49-
|Pivot Cache Records | pivotCacheRecords | <xref:DocumentFormat.OpenXml.Spreadsheet.PivotCacheRecords> | A cache of the source data of the PivotTable. For more information, see [Working with PivotTables](working-with-pivottables.md). |
50-
| Calculation Chain | calcChain | <xref:DocumentFormat.OpenXml.Spreadsheet.CalculationChain> | A construct that specifies the order in which cells in the workbook were last calculated. For more information, see [Working with the calculation chain](working-with-the-calculation-chain.md). |
51-
|Shared String Table | sst | <xref:DocumentFormat.OpenXml.Spreadsheet.SharedStringTable> | A construct that contains one occurrence of each unique string that occurs on all worksheets in a workbook. For more information, see [Working with the shared string table](working-with-the-shared-string-table.md). |
52-
|Conditional Formatting | conditionalFormatting | <xref:DocumentFormat.OpenXml.Spreadsheet.ConditionalFormatting> | A construct that defines a format applied to a cell or series of cells. For more information, see [Working with conditional formatting](working-with-conditional-formatting.md). |
53-
| Formulas | f | <xref:DocumentFormat.OpenXml.Spreadsheet.CellFormula> | A construct that defines the formula text for a cell that contains a formula. For more information, see [Working with formulas](working-with-formulas.md). |
43+
| Workbook | `<workbook/>` | <xref:DocumentFormat.OpenXml.Spreadsheet.Workbook> | The root element for the main document part.|
44+
| Worksheet | `<worksheet/>` | <xref:DocumentFormat.OpenXml.Spreadsheet.Worksheet> | A type of sheet that represent a grid of cells that contains text, numbers, dates or formulas. For more information, see [Working with sheets](working-with-sheets.md). |
45+
|Chart Sheet | `<chartsheet/>` | <xref:DocumentFormat.OpenXml.Spreadsheet.Chartsheet> | A sheet that represents a chart that is stored as its own sheet. For more information, see [Working with sheets](working-with-sheets.md). |
46+
| Table | `<table/>` | <xref:DocumentFormat.OpenXml.Spreadsheet.Table> | A logical construct that specifies that a range of data belongs to a single dataset. For more information, see [Working with SpreadsheetML tables](overview.md). |
47+
|Pivot Table | `<pivotTableDefinition/>` | <xref:DocumentFormat.OpenXml.Spreadsheet.PivotTableDefinition> | A logical construct that displays aggregated view of data in an understandable layout. For more information, see [Working with PivotTables](working-with-pivottables.md). |
48+
|Pivot Cache | `<pivotCacheDefinition/>` | <xref:DocumentFormat.OpenXml.Spreadsheet.PivotCacheDefinition> | A construct that defines the source of the data in the PivotTable. For more information, see [Working with PivotTables](working-with-pivottables.md). |
49+
|Pivot Cache Records | `<pivotCacheRecords/>` | <xref:DocumentFormat.OpenXml.Spreadsheet.PivotCacheRecords> | A cache of the source data of the PivotTable. For more information, see [Working with PivotTables](working-with-pivottables.md). |
50+
| Calculation Chain | `<calcChain/>` | <xref:DocumentFormat.OpenXml.Spreadsheet.CalculationChain> | A construct that specifies the order in which cells in the workbook were last calculated. For more information, see [Working with the calculation chain](working-with-the-calculation-chain.md). |
51+
|Shared String Table | `<sst/>` | <xref:DocumentFormat.OpenXml.Spreadsheet.SharedStringTable> | A construct that contains one occurrence of each unique string that occurs on all worksheets in a workbook. For more information, see [Working with the shared string table](working-with-the-shared-string-table.md). |
52+
|Conditional Formatting | `<conditionalFormatting/>` | <xref:DocumentFormat.OpenXml.Spreadsheet.ConditionalFormatting> | A construct that defines a format applied to a cell or series of cells. For more information, see [Working with conditional formatting](working-with-conditional-formatting.md). |
53+
| Formulas | `<f/>` | <xref:DocumentFormat.OpenXml.Spreadsheet.CellFormula> | A construct that defines the formula text for a cell that contains a formula. For more information, see [Working with formulas](working-with-formulas.md). |
5454

5555
--------------------------------------------------------------------------------
5656
## Minimum Workbook Scenario
@@ -74,10 +74,10 @@ This code example uses the classes in the Open XML SDK to create a
7474
minimum, blank workbook.
7575

7676
### [C#](#tab/cs)
77-
[!code-csharp[](../../samples/spreadsheet/structure_ofml/cs/Program.cs)]
77+
[!code-csharp[](../../samples/spreadsheet/structure_ofml/cs/Program.cs#snippet0)]
7878

7979
### [Visual Basic](#tab/vb)
80-
[!code-vb[](../../samples/spreadsheet/structure_ofml/vb/Program.vb)]
80+
[!code-vb[](../../samples/spreadsheet/structure_ofml/vb/Program.vb#snippet0)]
8181

8282
### Generated SpreadsheetML
8383

@@ -95,11 +95,12 @@ Figure 1. .zip folder structure
9595

9696

9797
![Structure of a minimum workbook](../media/odc_oxml_xl_documentstructure_fig02.gif)
98-
The **workbook.xml** file contains \<**sheet**\> elements that reference the worksheets in
98+
99+
The **workbook.xml** file contains `<sheet/>` elements that reference the worksheets in
99100
the workbook. Each worksheet is associated to the workbook via a Sheet
100-
ID and a relationship ID. The **sheetID** is
101+
ID and a relationship ID. The `sheetID` is
101102
the ID used within the package to identify a sheet and must be unique
102-
within the workbook. The **id** is the
103+
within the workbook. The `id` is the
103104
relationship ID that identifies the sheet part definition associated
104105
with a sheet.
105106

@@ -117,7 +118,7 @@ the Open XML SDK code to create a minimum workbook.
117118
```
118119

119120
The **workbook.xml.rels** file contains the
120-
\<**Relationship**\> elements that define the
121+
`<Relationship/>` elements that define the
121122
relationships between the workbook and the worksheets it contains.
122123

123124
The following XML code is the spreadsheetML that represents the
@@ -131,9 +132,9 @@ when you run the Open XML SDK to create a minimum workbook.
131132
</Relationships>
132133
```
133134

134-
The **sheet.xml** file contains the \<**sheetData**\> element that represents the cell
135-
table. In this example, the workbook is blank, so the \<**sheetData**\> element is empty. For more
136-
information about sheets, see [Working with sheets](working-with-sheets.md)**.
135+
The **sheet.xml** file contains the `<sheetData/>` element that represents the cell
136+
table. In this example, the workbook is blank, so the `<sheetData/>` element is empty. For more
137+
information about sheets, see [Working with sheets](working-with-sheets.md).
137138

138139
The following XML code is the spreadsheetML that represents the
139140
worksheet part of the spreadsheet document. This code is generated when
@@ -148,6 +149,7 @@ you run the Open XML SDK to create a minimum workbook.
148149

149150
--------------------------------------------------------------------------------
150151
## Typical Workbook Scenario
152+
151153
A typical workbook will not be a blank, minimum workbook. A typical
152154
workbook might contain numbers, text, charts, tables, and pivot tables.
153155
Each of these additional parts is contained within the .zip package of

samples/spreadsheet/structure_ofml/cs/Program.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using DocumentFormat.OpenXml.Spreadsheet;
44

55
CreateSpreadsheetWorkbook(args[0]);
6-
6+
// <Snippet0>
77
static void CreateSpreadsheetWorkbook(string filepath)
88
{
99
// Create a spreadsheet document by supplying the filepath.
@@ -24,7 +24,6 @@ static void CreateSpreadsheetWorkbook(string filepath)
2424
// Append a new worksheet and associate it with the workbook.
2525
Sheet sheet = new Sheet() { Id = workbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "mySheet" };
2626
sheets.Append(sheet);
27-
28-
workbookPart.Workbook.Save();
2927
}
3028
}
29+
// </Snippet0>

samples/spreadsheet/structure_ofml/vb/Program.vb

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,35 @@ Imports DocumentFormat.OpenXml
22
Imports DocumentFormat.OpenXml.Packaging
33
Imports DocumentFormat.OpenXml.Spreadsheet
44

5-
Module MyModule
6-
5+
Module Program
76
Sub Main(args As String())
8-
Dim filepath As String = args(0)
9-
CreateSpreadsheetWorkbook(filepath)
7+
CreateSpreadsheetWorkbook(args(0))
108
End Sub
119

12-
Public Sub CreateSpreadsheetWorkbook(ByVal filepath As String)
10+
' <Snippet0>
11+
Sub CreateSpreadsheetWorkbook(filepath As String)
1312
' Create a spreadsheet document by supplying the filepath.
1413
' By default, AutoSave = true, Editable = true, and Type = xlsx.
1514
Using spreadsheetDocument As SpreadsheetDocument = SpreadsheetDocument.Create(filepath, SpreadsheetDocumentType.Workbook)
16-
1715
' Add a WorkbookPart to the document.
18-
Dim workbookpart As WorkbookPart = spreadsheetDocument.AddWorkbookPart
19-
workbookpart.Workbook = New Workbook
16+
Dim workbookPart As WorkbookPart = spreadsheetDocument.AddWorkbookPart()
17+
workbookPart.Workbook = New Workbook()
2018

2119
' Add a WorksheetPart to the WorkbookPart.
22-
Dim worksheetPart As WorksheetPart = workbookpart.AddNewPart(Of WorksheetPart)()
20+
Dim worksheetPart As WorksheetPart = workbookPart.AddNewPart(Of WorksheetPart)()
2321
worksheetPart.Worksheet = New Worksheet(New SheetData())
2422

2523
' Add Sheets to the Workbook.
26-
Dim sheets As Sheets = spreadsheetDocument.WorkbookPart.Workbook.AppendChild(Of Sheets)(New Sheets())
24+
Dim sheets As Sheets = workbookPart.Workbook.AppendChild(Of Sheets)(New Sheets())
2725

2826
' Append a new worksheet and associate it with the workbook.
29-
Dim sheet As Sheet = New Sheet
30-
sheet.Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart)
31-
sheet.SheetId = 1
32-
sheet.Name = "mySheet"
33-
27+
Dim sheet As Sheet = New Sheet() With {
28+
.Id = workbookPart.GetIdOfPart(worksheetPart),
29+
.SheetId = 1,
30+
.Name = "mySheet"
31+
}
3432
sheets.Append(sheet)
35-
36-
workbookpart.Workbook.Save()
3733
End Using
3834
End Sub
39-
End Module
35+
' </Snippet0>
36+
End Module

0 commit comments

Comments
 (0)