Skip to content

Commit 4604413

Browse files
feat: OpenXML.Excel.File.get_Cell ( Fixes #6 )
Adding docs
1 parent eecd6bc commit 4604413

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed
Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
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
514
foreach ($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

0 commit comments

Comments
 (0)