File tree Expand file tree Collapse file tree 1 file changed +24
-8
lines changed
Types/OpenXML.Excel.Worksheet Expand file tree Collapse file tree 1 file changed +24
-8
lines changed Original file line number Diff line number Diff line change 1- $excelCells = [Ordered ]@ {
2-
3- }
4- $sharedStrings = $this.OpenXML.Parts [' /xl/sharedStrings.xml' ].Content
1+ <#
2+ . SYNOPSIS
3+ Gets cells from Excel
4+ . DESCRIPTION
5+ Gets individual cells in an Excel worksheet.
6+ . EXAMPLE
7+ Get-OpenXML ./Examples/Sum.xlsx |
8+ Select-Object -ExpandProperty Worksheets |
9+ Select-Object -ExpandProperty Cell
10+ #>
11+ param ()
12+ $excelCells = [Ordered ]@ {}
13+ # Get each row from our sheet data
514foreach ($worksheetRow in $this.content.worksheet.sheetdata.row ) {
15+ # and get each column from each row
616 foreach ($worksheetColumn in $worksheetRow.c ) {
7-
8- $excelCells [$worksheetColumn.r ] =
17+ # The `r` attribute contains the cell coordinate
18+ $excelCells [$worksheetColumn.r ] =
19+ # Excel cells are always numbers.
20+ # If the cell contains a string, it is actually stored as an index in "sharedStrings"
921 if ($worksheetColumn.t -eq ' s' ) {
10- $this.OpenXML.SharedStrings [$worksheetColumn.v -as [int ]]
22+ # which makes indexing awfully easy (and has the side-effect of reducing the total file size for worksheets with similar text)
23+ $this.OpenXML.SharedStrings [$worksheetColumn.v ]
1124 } else {
25+ # Otherwise, the value should be `v`.
1226 $worksheetColumn.v
1327 }
1428 }
1529}
16- $excelCells
30+
31+ # Return our cells as dictionary
32+ return $excelCells
You can’t perform that action at this time.
0 commit comments