-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ps1
34 lines (27 loc) · 1.63 KB
/
test.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
[System.Reflection.Assembly]::LoadFrom("C:\Program Files (x86)\Open XML SDK\V2.0\lib\DocumentFormat.OpenXml.dll") | out-null
[Reflection.Assembly]::LoadWithPartialName("DocumentFormat.OpenXml") | out-null
[Reflection.Assembly]::LoadWithPartialName("DocumentFormat.OpenXml.Packaging") | out-null
[Reflection.Assembly]::LoadWithPartialName("DocumentFormat.OpenXml.Spreadsheet") | out-null
[Reflection.Assembly]::LoadWithPartialName("OpenXmlPowerTools") | out-null
[DocumentFormat.OpenXml.Packaging.SpreadsheetDocument]$Document = $null
$Document = [DocumentFormat.OpenXml.Packaging.SpreadsheetDocument]::Open("test5.xlsx", $false)
$Document
[DocumentFormat.OpenXml.Packaging.WorkbookPart]$WorkBookPart = $Document.WorkbookPart
[DocumentFormat.OpenXml.Spreadsheet.Workbook]$WorkBook = $WorkBookPart.Workbook
"count sheets $($Workbook.Sheets.Count)"
foreach($sheet in $Workbook.Sheets) {
"here"
[DocumentFormat.OpenXml.Packaging.WorksheetPart]$workSheetPart = $workBookPart.GetPartById($sheet.Id)
$cells = Invoke-GenericMethod -InputObject $workSheetPart.Worksheet -MethodName Descendants -GenericType DocumentFormat.OpenXml.Spreadsheet.Cell
foreach ($cell in $cells) {
if ($cell.DataType.Value -eq "SharedString") {
$stringTable = Invoke-GenericMethod -InputObject $workBookPart -MethodName GetPartsOfType -GenericType DocumentFormat.OpenXml.Packaging.SharedStringTablePart
$value = $stringTable.SharedStringTable.InnerText
} else {
[String]$value = $cell.InnerText
}
"Value at {0}: {1}" -f $cell.CellReference, $value
[DocumentFormat.OpenXml.Packaging.SharedStringTablePart]$sharedTablePart = $null
}
}
$Document.Close()