Skip to content

Commit 397732d

Browse files
committed
clean up docs\spreadsheet\working-with-sheets.md
1 parent 4ffbce6 commit 397732d

File tree

3 files changed

+59
-47
lines changed

3 files changed

+59
-47
lines changed

docs/spreadsheet/working-with-sheets.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ 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
# Working with sheets
@@ -25,7 +25,7 @@ SpreadsheetML document, see [Structure of a SpreadsheetML document](structure-of
2525
## Sheets in SpreadsheetML
2626

2727
The following information from the [!include[ISO/IEC 29500 URL](../includes/iso-iec-29500-link.md)]
28-
specification introduces the **sheet** (\<**sheet**\>) element.
28+
specification introduces the **sheet** (`<sheet/>`) element.
2929

3030
Sheets are the central structures within a workbook, and are where the
3131
user does most of their spreadsheet work. The most common type of sheet
@@ -45,12 +45,12 @@ Other types of sheets include chart sheets and dialog sheets.
4545

4646
## Open XML SDK Worksheet Class
4747

48-
The Open XML SDK**Worksheet** class
49-
represents the **worksheet** (\<**worksheet**\>) element defined in the Open XML File
50-
Format schema for SpreadsheetML documents. Use the **Worksheet** class to manipulate individual \<**worksheet**\> elements in a SpreadsheetML document.
48+
The Open XML SDK `Worksheet` class
49+
represents the `worksheet` (`<worksheet/>`) element defined in the Open XML File
50+
Format schema for SpreadsheetML documents. Use the `Worksheet` class to manipulate individual `<worksheet/>` elements in a SpreadsheetML document.
5151

5252
The following information from the ISO/IEC 29500 specification
53-
introduces the **worksheet** (\<**worksheet**\>) element.
53+
introduces the `worksheet` (`<worksheet/>`) element.
5454

5555
An instance of this part type contains all the data, formulas, and
5656
characteristics associated with a given worksheet.
@@ -83,23 +83,23 @@ when empty.
8383
&copy; [!include[ISO/IEC 29500 version](../includes/iso-iec-29500-version.md)]
8484

8585
A typical spreadsheet has at least one worksheet. The worksheet contains
86-
a table like structure for defining data, represented by the **sheetData** element. A sheet that contains data
87-
uses the **worksheet** element as the root
86+
a table like structure for defining data, represented by the `sheetData` element. A sheet that contains data
87+
uses the `worksheet` element as the root
8888
element for defining worksheets. Inside a worksheet the data is split up
8989
into three distinct sections. The first section contains optional sheet
9090
properties. The second section contains the data, using the required
91-
**sheetData** element. The third section contains optional supporting
91+
`sheetData` element. The third section contains optional supporting
9292
features such as sheet protection and filter information. To define an
93-
empty worksheet you only have to use the **worksheet** and **sheetData** elements. The **sheetData** element can be empty.
94-
95-
To create new values for the worksheet you define rows inside the **sheetData** element. These rows contain cells,
96-
which contain values. The **row** element
97-
defines a new row. Normally the first row in the **sheetData** is the first row in the visible sheet.
98-
Inside the row you create new **cells** using the \<**c**\> element. Values for cells can be provided by
99-
storing a \<**v**\> element inside the cell.
100-
Usually the \<**v**\> element contains the
93+
empty worksheet you only have to use the `worksheet` and `sheetData` elements. The `sheetData` element can be empty.
94+
95+
To create new values for the worksheet you define rows inside the `sheetData` element. These rows contain cells,
96+
which contain values. The `row` element
97+
defines a new row. Normally the first row in the `sheetData` is the first row in the visible sheet.
98+
Inside the row you create new `cells` using the `<c/>` element. Values for cells can be provided by
99+
storing a `<v/>` element inside the cell.
100+
Usually the `<v/>` element contains the
101101
current value of the worksheet cell. If the value is a numeric value, it
102-
is stored directly in the \<**v**\> element in
102+
is stored directly in the `<v/>` element in
103103
the XML file. If the value is a string value, it is stored in a shared
104104
string table. For more information about using the shared string table
105105
to store string values, see [Working with the shared string table](working-with-the-shared-string-table.md).
@@ -109,10 +109,10 @@ working with the <xref:DocumentFormat.OpenXml.Spreadsheet.Worksheet> class.
109109

110110
| **SpreadsheetML Element** | **Open XML SDK Class** |
111111
|---|---|
112-
| sheetData | <xref:DocumentFormat.OpenXml.Spreadsheet.SheetData> |
113-
| row | <xref:DocumentFormat.OpenXml.Spreadsheet.Row> |
114-
| c | <xref:DocumentFormat.OpenXml.Spreadsheet.Cell> |
115-
| v | <xref:DocumentFormat.OpenXml.Spreadsheet.CellValue> |
112+
| `<sheetData/>` | <xref:DocumentFormat.OpenXml.Spreadsheet.SheetData> |
113+
| `<row/>` | <xref:DocumentFormat.OpenXml.Spreadsheet.Row> |
114+
| `<c/>` | <xref:DocumentFormat.OpenXml.Spreadsheet.Cell> |
115+
| `<v/>` | <xref:DocumentFormat.OpenXml.Spreadsheet.CellValue> |
116116

117117
For more information about optional spreadsheet elements, such as sheet
118118
properties and supporting sheet features, see the ISO/IEC 29500
@@ -121,7 +121,7 @@ specification.
121121
### SheetData Class
122122

123123
The following information from the ISO/IEC 29500 specification
124-
introduces the **sheet data** (\<**sheetData**\>) element.
124+
introduces the **sheet data** (`<sheetData/>`) element.
125125

126126
The cell table is the core structure of a worksheet. It consists of all
127127
the text, numbers, and formulas in the grid.
@@ -131,7 +131,7 @@ the text, numbers, and formulas in the grid.
131131
### Row Class
132132

133133
The following information from the ISO/IEC 29500 specification
134-
introduces the **row** (\<**row**\>) element.
134+
introduces the **row** (`<row/>`) element.
135135

136136
The cells in the cell table are organized by row. Each row has an index
137137
(attribute r) so that empty rows need not be written out. Each row
@@ -143,7 +143,7 @@ position in the sheet. In this example, the first row of data is row 2.
143143
### Cell Class
144144

145145
The following information from the ISO/IEC 29500 specification
146-
introduces the **cell** (\<**c**\>) element.
146+
introduces the **cell** (`<c/>`) element.
147147

148148
The cell itself is expressed by the c collection. Each cell indicates
149149
its location in the grid using A1-style reference notation. A cell can
@@ -157,14 +157,14 @@ written out.
157157
### CellValue Class
158158

159159
The following information from the ISO/IEC 29500 specification
160-
introduces the **cell value** (\<**v**\>) element.
160+
introduces the **cell value** (`<v/>`) element.
161161

162162
Cells contain values, whether the values were directly entered (e.g.,
163163
cell A2 in our example has the value External Link:) or are the result
164164
of a calculation (e.g., cell B3 in our example has the formula B2+1).
165165

166166
String values in a cell are not stored in the cell table unless they are
167-
the result of a calculation. Therefore, instead of seeing External Link:
167+
the result of a calculation. Therefore, instead of seeing External Link
168168
as the content of the cell's v node, instead you see a zero-based index
169169
into the shared string table where that string is stored uniquely. This
170170
is done to optimize load/save performance and to reduce duplication of
@@ -177,15 +177,15 @@ indicates string, then it is an index and not a numeric value.
177177
### Open XML SDK Code Example
178178

179179
The following code example creates a spreadsheet document with the
180-
specified file name and instantiates a **Worksheet** class, and then adds a row and adds a
180+
specified file name and instantiates a `Worksheet` class, and then adds a row and adds a
181181
cell to the cell table at position A1. Then the value of the cell in A1
182182
is set equal to the numeric value 100.
183183

184184
### [C#](#tab/cs)
185-
[!code-csharp[](../../samples/spreadsheet/working_with_sheets/cs/Program.cs)]
185+
[!code-csharp[](../../samples/spreadsheet/working_with_sheets/cs/Program.cs#snippet0)]
186186

187187
### [Visual Basic](#tab/vb)
188-
[!code-vb[](../../samples/spreadsheet/working_with_sheets/vb/Program.vb)]
188+
[!code-vb[](../../samples/spreadsheet/working_with_sheets/vb/Program.vb#snippet0)]
189189

190190
### Generated SpreadsheetML
191191

@@ -208,7 +208,7 @@ the "sheet.xml" file in the "worksheets" folder of the .zip file.
208208
## The Open XML SDK Chartsheet Class
209209

210210
The following information from the ISO/IEC 29500 specification
211-
introduces the **chartsheet** (\<**chartsheet**\>) element.
211+
introduces the **chartsheet** (`<chartsheet/>`) element.
212212

213213
An instance of this part type represents a chart that is stored in its
214214
own sheet.
@@ -234,12 +234,12 @@ working with the <xref:DocumentFormat.OpenXml.Spreadsheet.Chartsheet> class.
234234

235235
| **SpreadsheetML Element** | **Open XML SDK Class** |
236236
|---|---|
237-
| drawing | <xref:DocumentFormat.OpenXml.Spreadsheet.Drawing> |
237+
| `<drawing/>` | <xref:DocumentFormat.OpenXml.Spreadsheet.Drawing> |
238238

239239
### Drawing Class
240240

241241
The following information from the ISO/IEC 29500 specification
242-
introduces the **drawings** (\<**wsDr**\>) element.
242+
introduces the **drawings** (`<wsDr/>`) element.
243243

244244
An instance of this part type contains the presentation and layout
245245
information for one or more drawing elements that are present on this
@@ -256,7 +256,7 @@ be only one Drawings part per worksheet or chartsheet.
256256
## Open XML SDK Dialogsheet Class
257257

258258
The following information from the ISO/IEC 29500 specification
259-
introduces the **dialogsheet** (\<**dialogsheet**\>) element.
259+
introduces the **dialogsheet** (`<dialogsheet/>`) element.
260260

261261
An instance of this part type contains information about a legacy custom
262262
dialog box for a user form.

samples/spreadsheet/working_with_sheets/cs/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
CreateSpreadsheetWorkbook(args[0]);
66

7+
// <Snippet0>
78
static void CreateSpreadsheetWorkbook(string filepath)
89
{
910
// Use 'using' block to ensure proper disposal of the document
@@ -52,3 +53,4 @@ static void CreateSpreadsheetWorkbook(string filepath)
5253
newCell.DataType = new EnumValue<CellValues>(CellValues.Number);
5354
}
5455
}
56+
// </Snippet0>

samples/spreadsheet/working_with_sheets/vb/Program.vb

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,63 @@ 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())
7+
CreateSpreadsheetWorkbook(args(0))
88
End Sub
99

10-
Public Sub CreateSpreadsheetWorkbookWithNumValue(ByVal filepath As String)
10+
' <Snippet0>
11+
Sub CreateSpreadsheetWorkbook(filepath As String)
1112
' Use 'Using' block to ensure proper disposal of the document
1213
Using spreadsheetDocument As SpreadsheetDocument = SpreadsheetDocument.Create(filepath, SpreadsheetDocumentType.Workbook)
13-
1414
' Add a WorkbookPart to the document.
15-
Dim workbookpart As WorkbookPart = spreadsheetDocument.AddWorkbookPart()
16-
workbookpart.Workbook = New Workbook()
15+
Dim workbookPart As WorkbookPart = spreadsheetDocument.AddWorkbookPart()
16+
workbookPart.Workbook = New Workbook()
1717

1818
' Add a WorksheetPart to the WorkbookPart.
19-
Dim worksheetPart As WorksheetPart = workbookpart.AddNewPart(Of WorksheetPart)()
19+
Dim worksheetPart As WorksheetPart = workbookPart.AddNewPart(Of WorksheetPart)()
2020
worksheetPart.Worksheet = New Worksheet(New SheetData())
2121

2222
' Add Sheets to the Workbook.
23-
Dim sheets As Sheets = spreadsheetDocument.WorkbookPart.Workbook.AppendChild(Of Sheets)(New Sheets())
23+
Dim sheets As Sheets = workbookPart.Workbook.AppendChild(Of Sheets)(New Sheets())
2424

2525
' Append a new worksheet and associate it with the workbook.
26-
Dim sheet As New Sheet() With {.Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), .SheetId = 1, .Name = "mySheet"}
26+
Dim sheet As Sheet = New Sheet() With {
27+
.Id = workbookPart.GetIdOfPart(worksheetPart),
28+
.SheetId = 1,
29+
.Name = "mySheet"
30+
}
2731
sheets.Append(sheet)
2832

2933
' Get the sheetData cell table.
30-
Dim sheetData As SheetData = worksheetPart.Worksheet.GetFirstChild(Of SheetData)()
34+
Dim sheetData As SheetData = If(worksheetPart.Worksheet.GetFirstChild(Of SheetData)(), worksheetPart.Worksheet.AppendChild(Of SheetData)(New SheetData()))
3135

3236
' Add a row to the cell table.
33-
Dim row As New Row() With {.RowIndex = 1}
37+
Dim row As Row = New Row() With {
38+
.RowIndex = 1
39+
}
3440
sheetData.Append(row)
3541

3642
' In the new row, find the column location to insert a cell in A1.
3743
Dim refCell As Cell = Nothing
44+
3845
For Each cell As Cell In row.Elements(Of Cell)()
39-
If String.Compare(cell.CellReference.Value, "A1", True) > 0 Then
46+
If String.Compare(cell.CellReference?.Value, "A1", True) > 0 Then
4047
refCell = cell
4148
Exit For
4249
End If
4350
Next
4451

4552
' Add the cell to the cell table at A1.
46-
Dim newCell As New Cell() With {.CellReference = "A1"}
53+
Dim newCell As Cell = New Cell() With {
54+
.CellReference = "A1"
55+
}
4756
row.InsertBefore(newCell, refCell)
4857

4958
' Set the cell value to be a numeric value of 100.
5059
newCell.CellValue = New CellValue("100")
5160
newCell.DataType = New EnumValue(Of CellValues)(CellValues.Number)
5261
End Using
5362
End Sub
63+
' </Snippet0>
5464
End Module

0 commit comments

Comments
 (0)