You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 15, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: docs/how-to-retrieve-a-dictionary-of-all-named-ranges-in-a-spreadsheet.md
+3-4Lines changed: 3 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -112,9 +112,8 @@ The code starts by creating a variable named **returnValue** that the method wil
112
112
ReturnreturnValue
113
113
```
114
114
115
-
The code continues by opening the spreadsheet document, using the <span sdata="cer"
116
-
target="M:DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.Open(System.String,System.Boolean)">**Open**</span> method and indicating that the
117
-
document should be open for read-only access (the final false parameter). Given the open workbook, the code uses the <spansdata="cer"target="P:DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.WorkbookPart">**WorkbookPart**</span> property to navigate to the main workbook part. The code stores this reference in a variable named **wbPart**.
115
+
The code continues by opening the spreadsheet document, using the **Open** method and indicating that the
116
+
document should be open for read-only access (the final false parameter). Given the open workbook, the code uses the **WorkbookPart** property to navigate to the main workbook part. The code stores this reference in a variable named **wbPart**.
118
117
119
118
```csharp
120
119
// Open the spreadsheet document for read-only access.
@@ -141,7 +140,7 @@ document should be open for read-only access (the final false parameter). Given
141
140
## Retrieving the Defined Names
142
141
143
142
Given the workbook part, the next step is simple. The code uses the
144
-
<spansdata="cer"target="P:DocumentFormat.OpenXml.Packaging.WorkbookPart.Workbook">**Workbook**</span> property of the workbook part to retrieve a reference to the content of the workbook, and then retrieves the <spansdata="cer"target="P:DocumentFormat.OpenXml.Spreadsheet.Workbook.DefinedNames">**DefinedNames**</span> collection provided by the Open XML SDK 2.5. This property returns a collection of all of the
143
+
**Workbook** property of the workbook part to retrieve a reference to the content of the workbook, and then retrieves the **DefinedNames** collection provided by the Open XML SDK 2.5. This property returns a collection of all of the
145
144
defined names that are contained within the workbook. If the property returns a non-null value, the code then iterates through the collection, retrieving information about each named part and adding the key name) and value (range description) to the dictionary for each defined name.
The method works with the workbook you specify, filling a <spansdata="cer"target="T:System.Collections.Generic.List`1">**[List\<T\>](https://msdn2.microsoft.com/library/6sh2ey19)** instance with a reference to each hidden <spansdata="cer"target="T:DocumentFormat.OpenXml.Spreadsheet.Sheet">**Sheet**</span> object.
53
+
The method works with the workbook you specify, filling a **[List\<T\>](https://msdn2.microsoft.com/library/6sh2ey19)** instance with a reference to each hidden **Sheet** object.
54
54
55
55
## Calling the GetHiddenSheets method
56
56
@@ -89,7 +89,7 @@ The following code starts by creating a generic list that will contain informati
89
89
DimreturnValAsNewList(OfSheet)
90
90
```
91
91
92
-
Next, the following code opens the specified workbook by using the <spansdata="cer"target="M:DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.Open(System.String,System.Boolean)">**SpreadsheetDocument.Open**</span> method and indicating that the document should be open for read-only access (the final **false** parameter value). Given the open workbook, the code uses the <spansdata="cer"target="P:DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.WorkbookPart">**WorkbookPart**</span> property to navigate to the main workbook part, storing the reference in a variable named **wbPart**.
92
+
Next, the following code opens the specified workbook by using the **SpreadsheetDocument.Open** method and indicating that the document should be open for read-only access (the final **false** parameter value). Given the open workbook, the code uses the **WorkbookPart** property to navigate to the main workbook part, storing the reference in a variable named **wbPart**.
93
93
94
94
```csharp
95
95
using (SpreadsheetDocumentdocument=
@@ -111,8 +111,8 @@ Next, the following code opens the specified workbook by using the <span sdata="
111
111
112
112
## Retrieve the collection of worksheets
113
113
114
-
The <spansdata="cer"target="T:DocumentFormat.OpenXml.Packaging.WorkbookPart">**WorkbookPart**</span> class provides a <spansdata="cer"target="P:DocumentFormat.OpenXml.Packaging.WorkbookPart.Workbook">**Workbook**</span> property, which in turn contains the XML content of the workbook. Although the Open XML SDK 2.5 provides the <spansdata="cer"target="P:DocumentFormat.OpenXml.Spreadsheet.Workbook.Sheets">**Sheets**</span> property, which returns a collection of the **Sheet** parts, all the information that you need is provided by the **Sheet** elements within the **Workbook** XML content.
115
-
The following code uses the <spansdata="cer"target="M:DocumentFormat.OpenXml.OpenXmlElement.Descendants``1">**Descendants**</span> generic method of the **Workbook** object to retrieve a collection of **Sheet** objects that contain information about all the sheet child elements of the workbook's XML content.
114
+
The **WorkbookPart** class provides a **Workbook** property, which in turn contains the XML content of the workbook. Although the Open XML SDK 2.5 provides the **Sheets** property, which returns a collection of the **Sheet** parts, all the information that you need is provided by the **Sheet** elements within the **Workbook** XML content.
115
+
The following code uses the **Descendants** generic method of the **Workbook** object to retrieve a collection of **Sheet** objects that contain information about all the sheet child elements of the workbook's XML content.
116
116
117
117
```csharp
118
118
varsheets=wbPart.Workbook.Descendants<Sheet>();
@@ -125,9 +125,9 @@ The following code uses the <span sdata="cer" target="M:DocumentFormat.OpenXml.O
125
125
## Retrieve hidden sheets
126
126
127
127
It's important to be aware that Excel supports two levels of worksheets. You can hide a worksheet by using the Excel user interface by right-clicking the worksheets tab and opting to hide the worksheet.
128
-
For these worksheets, the <spansdata="cer"target="P:DocumentFormat.OpenXml.Spreadsheet.Sheet.State">**State**</span> property of the **Sheet** object contains an enumerated value of <spansdata="cer"target="F:DocumentFormat.OpenXml.Spreadsheet.SheetStateValues.Hidden">**Hidden**</span>. You can also make a worksheet very hidden by writing code (either in VBA or in another language) that sets the sheet's **Visible** property to the enumerated value **xlSheetVeryHidden**. For worksheets hidden in this manner, the **State** property of the **Sheet** object contains the enumerated value <spansdata="cer"target="F:DocumentFormat.OpenXml.Spreadsheet.SheetStateValues.VeryHidden">**VeryHidden**</span>.
128
+
For these worksheets, the **State** property of the **Sheet** object contains an enumerated value of **Hidden**. You can also make a worksheet very hidden by writing code (either in VBA or in another language) that sets the sheet's **Visible** property to the enumerated value **xlSheetVeryHidden**. For worksheets hidden in this manner, the **State** property of the **Sheet** object contains the enumerated value **VeryHidden**.
129
129
130
-
Given the collection that contains information about all the sheets, the following code uses the <spansdata="cer"target="M:System.Linq.Enumerable.Where``1(System.Collections.Generic.IEnumerable{``0},System.Func{``0,System.Int32,System.Boolean})">**[Where](https://msdn2.microsoft.com/library/bb301979)**</span> function to filter the collection so that it contains only the sheets in which the **State** property is not null. If the **State** property is not null, the code looks for the **Sheet** objects in which the **State** property as a value, and where the value is either **SheetStateValues.Hidden** or **SheetStateValues.VeryHidden**.
130
+
Given the collection that contains information about all the sheets, the following code uses the **[Where](https://msdn2.microsoft.com/library/bb301979)** function to filter the collection so that it contains only the sheets in which the **State** property is not null. If the **State** property is not null, the code looks for the **Sheet** objects in which the **State** property as a value, and where the value is either **SheetStateValues.Hidden** or **SheetStateValues.VeryHidden**.
@@ -143,7 +143,7 @@ Given the collection that contains information about all the sheets, the followi
143
143
item.State.Value=SheetStateValues.VeryHidden))
144
144
```
145
145
146
-
Finally, the following code calls the <spansdata="cer"target="M:System.Linq.Enumerable.ToList``1(System.Collections.Generic.IEnumerable{``0})">**[ToList\<TSource\>](https://msdn2.microsoft.com/library/bb342261)**</span> method to execute the LINQ query that retrieves the list of hidden sheets, placing the result into the return value for the function.
146
+
Finally, the following code calls the **[ToList\<TSource\>](https://msdn2.microsoft.com/library/bb342261)** method to execute the LINQ query that retrieves the list of hidden sheets, placing the result into the return value for the function.
0 commit comments