Skip to content

Commit 381125d

Browse files
feat: OpenXML.Excel.File.get_Formula ( Fixes #26 )
2 parents b14b256 + 8ce8f10 commit 381125d

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

OpenXML.types.ps1xml

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff 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+
&lt;#
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+
#&gt;
216+
param()
217+
$excelCells = [Ordered]@{}
218+
# Get each row from our sheet data
210219
foreach ($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>

0 commit comments

Comments
 (0)