File tree Expand file tree Collapse file tree 1 file changed +24
-8
lines changed Expand file tree Collapse file tree 1 file changed +24
-8
lines changed Original file line number Diff line number Diff line change @@ -203,22 +203,38 @@ foreach ($worksheet in $worksheetsInOrder) {
203203 <ScriptProperty >
204204 <Name >Cell</Name >
205205 <GetScriptBlock >
206- $excelCells = [Ordered]@{
207-
208- }
209- $sharedStrings = $this.OpenXML.Parts['/xl/sharedStrings.xml'].Content
206+ < #
207+ .SYNOPSIS
208+ Gets cells from Excel
209+ .DESCRIPTION
210+ Gets individual cells in an Excel worksheet.
211+ .EXAMPLE
212+ Get-OpenXML ./Examples/Sum.xlsx |
213+ Select-Object -ExpandProperty Worksheets |
214+ Select-Object -ExpandProperty Cell
215+ #>
216+ param()
217+ $excelCells = [Ordered]@{}
218+ # Get each row from our sheet data
210219foreach ($worksheetRow in $this.content.worksheet.sheetdata.row) {
220+ # and get each column from each row
211221 foreach ($worksheetColumn in $worksheetRow.c) {
212-
213- $excelCells[$worksheetColumn.r] =
222+ # The `r` attribute contains the cell coordinate
223+ $excelCells[$worksheetColumn.r] =
224+ # Excel cells are always numbers.
225+ # If the cell contains a string, it is actually stored as an index in "sharedStrings"
214226 if ($worksheetColumn.t -eq 's') {
215- $this.OpenXML.SharedStrings[$worksheetColumn.v -as [int]]
227+ # which makes indexing awfully easy (and has the side-effect of reducing the total file size for worksheets with similar text)
228+ $this.OpenXML.SharedStrings[$worksheetColumn.v]
216229 } else {
230+ # Otherwise, the value should be `v`.
217231 $worksheetColumn.v
218232 }
219233 }
220234}
221- $excelCells
235+
236+ # Return our cells as dictionary
237+ return $excelCells
222238 </GetScriptBlock >
223239 </ScriptProperty >
224240 </Members >
You can’t perform that action at this time.
0 commit comments