-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract code snippets from how-to-retrieve-a-list-of-the-hidden-worksheets-in-a-spreadsheet.md #293
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 15 additions & 2 deletions
17
samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/cs/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,46 @@ | ||
// <Snippet0> | ||
using DocumentFormat.OpenXml.Packaging; | ||
using DocumentFormat.OpenXml.Spreadsheet; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
GetHiddenSheets(args[0]); | ||
|
||
static List<Sheet> GetHiddenSheets(string fileName) | ||
{ | ||
List<Sheet> returnVal = new List<Sheet>(); | ||
|
||
using (SpreadsheetDocument document = SpreadsheetDocument.Open(fileName, false)) | ||
{ | ||
// <Snippet1> | ||
WorkbookPart? wbPart = document.WorkbookPart; | ||
|
||
if (wbPart is not null) | ||
{ | ||
var sheets = wbPart.Workbook.Descendants<Sheet>(); | ||
// </Snippet1> | ||
|
||
// Look for sheets where there is a State attribute defined, | ||
// where the State has a value, | ||
// and where the value is either Hidden or VeryHidden. | ||
|
||
// <Snippet2> | ||
var hiddenSheets = sheets.Where((item) => item.State is not null && | ||
item.State.HasValue && | ||
(item.State.Value == SheetStateValues.Hidden || | ||
item.State.Value == SheetStateValues.VeryHidden)); | ||
// </Snippet2> | ||
|
||
returnVal = hiddenSheets.ToList(); | ||
} | ||
} | ||
|
||
return returnVal; | ||
} | ||
// </Snippet0> | ||
|
||
var sheets = GetHiddenSheets(args[0]); | ||
|
||
foreach (var sheet in sheets) | ||
{ | ||
Console.WriteLine(sheet.Name); | ||
} |
27 changes: 20 additions & 7 deletions
27
samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/vb/Program.vb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,44 @@ | ||
' <Snippet0> | ||
Imports DocumentFormat.OpenXml.Spreadsheet | ||
Imports DocumentFormat.OpenXml.Packaging | ||
|
||
Module Program ` | ||
Sub Main(args As String())` | ||
End Sub` | ||
Module Program | ||
Sub Main(args As String()) | ||
Dim fileName As String = args(0) | ||
Dim hiddenSheets As List(Of Sheet) = GetHiddenSheets(fileName) | ||
|
||
For Each sheet As Sheet In hiddenSheets | ||
Console.WriteLine("Sheet ID: {0} Name: {1}", sheet.Id, sheet.Name) | ||
Next | ||
End Sub | ||
|
||
|
||
|
||
|
||
|
||
Public Function GetHiddenSheets(ByVal fileName As String) As List(Of Sheet) | ||
Dim returnVal As New List(Of Sheet) | ||
|
||
Using document As SpreadsheetDocument = | ||
SpreadsheetDocument.Open(fileName, False) | ||
|
||
' <Snippet1> | ||
Dim wbPart As WorkbookPart = document.WorkbookPart | ||
Dim sheets = wbPart.Workbook.Descendants(Of Sheet)() | ||
' </Snippet1> | ||
|
||
' Look for sheets where there is a State attribute defined, | ||
' where the State has a value, | ||
' and where the value is either Hidden or VeryHidden: | ||
|
||
' <Snippet2> | ||
Dim hiddenSheets = sheets.Where(Function(item) item.State IsNot | ||
Nothing AndAlso item.State.HasValue _ | ||
AndAlso (item.State.Value = SheetStateValues.Hidden Or _ | ||
AndAlso (item.State.Value = SheetStateValues.Hidden Or | ||
item.State.Value = SheetStateValues.VeryHidden)) | ||
' </Snippet2> | ||
|
||
returnVal = hiddenSheets.ToList() | ||
End Using | ||
Return returnVal | ||
End Function | ||
End Module | ||
End Module | ||
' </Snippet0> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do a pass to convert all these to more modern links (and then to xrefs if we can get that enabled) later