@@ -10,22 +10,22 @@ ms.suite: office
1010ms.author : o365devx
1111author : o365devx
1212ms.topic : conceptual
13- ms.date : 11/20/2023
13+ ms.date : 01/10/2025
1414ms.localizationpriority : high
1515---
1616
1717# Retrieve the values of cells in a spreadsheet document
1818
1919This topic shows how to use the classes in the Open XML SDK for
2020Office to programmatically retrieve the values of cells in a spreadsheet
21- document. It contains an example ** GetCellValue** method to illustrate
21+ document. It contains an example ` GetCellValue ` method to illustrate
2222this task.
2323
2424
2525
2626## GetCellValue Method
2727
28- You can use the ** GetCellValue** method to
28+ You can use the ` GetCellValue ` method to
2929retrieve the value of a cell in a workbook. The method requires the
3030following three parameters:
3131
@@ -62,7 +62,7 @@ initializes it to null.
6262## Accessing the Cell
6363
6464Next, the code opens the document by using the < xref:DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.Open* > method, indicating that the document
65- should be open for read-only access (the final ** false** parameter). Next, the code retrieves a
65+ should be open for read-only access (the final ` false ` parameter). Next, the code retrieves a
6666reference to the workbook part by using the < xref:DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.WorkbookPart* > property of the document.
6767
6868### [ C#] ( #tab/cs-3 )
@@ -111,8 +111,8 @@ the corresponding <xref:DocumentFormat.OpenXml.Spreadsheet.Worksheet.WorksheetPa
111111Just as when locating the named sheet, when locating the named cell, the
112112code uses the < xref:DocumentFormat.OpenXml.OpenXmlElement.Descendants* > method, searching for the first
113113match in which the < xref:DocumentFormat.OpenXml.Spreadsheet.CellType.CellReference* > property equals the specified
114- ** addressName**
115- parameter. After this method call, the variable named ** theCell** will either contain a reference to the cell,
114+ ` addressName `
115+ parameter. After this method call, the variable named ` theCell ` will either contain a reference to the cell,
116116or will contain a null reference.
117117
118118### [ C#] ( #tab/cs-6 )
@@ -125,9 +125,9 @@ or will contain a null reference.
125125
126126## Retrieving the Value
127127
128- At this point, the variable named ** theCell**
128+ At this point, the variable named ` theCell `
129129contains either a null reference, or a reference to the cell that you
130- requested. If you examine the Open XML content (that is, ** theCell.OuterXml** ) for the cell, you will find XML
130+ requested. If you examine the Open XML content (that is, ` theCell.OuterXml ` ) for the cell, you will find XML
131131such as the following.
132132
133133``` xml
@@ -151,9 +151,9 @@ Now, the sample method must interpret the value. As it is, the code
151151handles numeric and date, string, and Boolean values. You can extend the
152152sample as necessary. The < xref:DocumentFormat.OpenXml.Spreadsheet.Cell > type provides a
153153< xref:DocumentFormat.OpenXml.Spreadsheet.CellType.DataType* > property that indicates the type
154- of the data within the cell. The value of the ** DataType** property is null for numeric and date
155- types. It contains the value ** CellValues.SharedString** for strings, and ** CellValues.Boolean** for Boolean values. If the
156- ** DataType** property is null, the code returns
154+ of the data within the cell. The value of the ` DataType ` property is null for numeric and date
155+ types. It contains the value ` CellValues.SharedString ` for strings, and ` CellValues.Boolean ` for Boolean values. If the
156+ ` DataType ` property is null, the code returns
157157the value of the cell (it is a numeric value). Otherwise, the code
158158continues by branching based on the data type.
159159
@@ -165,7 +165,7 @@ continues by branching based on the data type.
165165***
166166
167167
168- If the ** DataType** property contains ** CellValues.SharedString** , the code must retrieve a
168+ If the ` DataType ` property contains ` CellValues.SharedString ` , the code must retrieve a
169169reference to the single < xref:DocumentFormat.OpenXml.Packaging.WorkbookPart.SharedStringTablePart* > .
170170
171171### [ C#] ( #tab/cs-9 )
@@ -178,7 +178,7 @@ reference to the single <xref:DocumentFormat.OpenXml.Packaging.WorkbookPart.Shar
178178
179179Next, if the string table exists (and if it does not, the workbook is
180180damaged and the sample code returns the index into the string table
181- instead of the string itself) the code returns the ** InnerText** property of the element it finds at the
181+ instead of the string itself) the code returns the ` InnerText ` property of the element it finds at the
182182specified index (first converting the value property to an integer).
183183
184184### [ C#] ( #tab/cs-10 )
@@ -189,7 +189,7 @@ specified index (first converting the value property to an integer).
189189***
190190
191191
192- If the ** DataType** property contains ** CellValues.Boolean** , the code converts the 0 or 1
192+ If the ` DataType ` property contains ` CellValues.Boolean ` , the code converts the 0 or 1
193193it finds in the cell value into the appropriate text string.
194194
195195### [ C#] ( #tab/cs-11 )
@@ -200,17 +200,18 @@ it finds in the cell value into the appropriate text string.
200200***
201201
202202
203- Finally, the procedure returns the variable ** value** , which contains the requested information.
203+ Finally, the procedure returns the variable ` value ` , which contains the requested information.
204204
205205## Sample Code
206206
207- The following is the complete ** GetCellValue** code sample in C\# and Visual Basic.
207+ The following is the complete ` GetCellValue ` code sample in C\# and Visual Basic.
208208
209209### [ C#] ( #tab/cs )
210210[ !code-csharp[ ] ( ../../samples/spreadsheet/retrieve_the_values_of_cells/cs/Program.cs#snippet0 )]
211211
212212### [ Visual Basic] ( #tab/vb )
213213[ !code-vb[ ] ( ../../samples/spreadsheet/retrieve_the_values_of_cells/vb/Program.vb#snippet0 )]
214+ ***
214215
215216## See also
216217
0 commit comments