mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-14 23:33:18 +00:00
Added Import-Html support and examples
This commit is contained in:
2
Examples/ImportHtml/DemoGraphics.ps1
Normal file
2
Examples/ImportHtml/DemoGraphics.ps1
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
Import-Html "http://en.wikipedia.org/wiki/Demographics_of_India" 4
|
||||||
1
Examples/ImportHtml/PeriodicElements.ps1
Normal file
1
Examples/ImportHtml/PeriodicElements.ps1
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Import-Html "http://www.science.co.il/PTelements.asp" 1
|
||||||
1
Examples/ImportHtml/StarTrek.ps1
Normal file
1
Examples/ImportHtml/StarTrek.ps1
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Import-Html "https://en.wikipedia.org/wiki/List_of_Star_Trek:_The_Original_Series_episodes" 2
|
||||||
38
Get-HtmlTable.ps1
Normal file
38
Get-HtmlTable.ps1
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
function Get-HtmlTable {
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
$url,
|
||||||
|
$tableIndex=0
|
||||||
|
)
|
||||||
|
|
||||||
|
$r = (Invoke-WebRequest $url)
|
||||||
|
$table = $r.ParsedHtml.getElementsByTagName("table")[$tableIndex]
|
||||||
|
$propertyNames = @()
|
||||||
|
$totalRows=@($table.rows).count-1
|
||||||
|
|
||||||
|
for ($idx = 0; $idx -lt $totalRows; $idx++) {
|
||||||
|
|
||||||
|
$row = $table.rows[$idx]
|
||||||
|
$cells = @($row.cells)
|
||||||
|
|
||||||
|
if(!$propertyNames) {
|
||||||
|
if($cells[0].tagName -eq 'th') {
|
||||||
|
$propertyNames = @($cells | foreach {$_.innertext -replace ' ',''})
|
||||||
|
} else {
|
||||||
|
$propertyNames = @(1..($cells.Count + 2) | % { "P$_" })
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = [ordered]@{}
|
||||||
|
|
||||||
|
for($counter = 0; $counter -lt $cells.Count; $counter++) {
|
||||||
|
$propertyName = $propertyNames[$counter]
|
||||||
|
|
||||||
|
if(!$propertyName) { $propertyName= '[missing]'}
|
||||||
|
$result.$propertyName= $cells[$counter].InnerText
|
||||||
|
}
|
||||||
|
|
||||||
|
[PSCustomObject]$result
|
||||||
|
}
|
||||||
|
}
|
||||||
15
Import-Html.ps1
Normal file
15
Import-Html.ps1
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
function Import-Html {
|
||||||
|
[CmdletBinding()]
|
||||||
|
param(
|
||||||
|
$url,
|
||||||
|
$index
|
||||||
|
)
|
||||||
|
|
||||||
|
$xlFile = (New-TemporaryFile).fullname -replace "tmp","xlsx"
|
||||||
|
rm $xlFile -ErrorAction Ignore
|
||||||
|
|
||||||
|
Write-Verbose "Exporting to Excel file $($xlFile)"
|
||||||
|
|
||||||
|
Get-HtmlTable $url $index |
|
||||||
|
Export-Excel $xlFile -Show -AutoSize
|
||||||
|
}
|
||||||
@@ -13,6 +13,8 @@ Add-Type -Path "$($PSScriptRoot)\EPPlus.dll"
|
|||||||
. $PSScriptRoot\New-PSItem.ps1
|
. $PSScriptRoot\New-PSItem.ps1
|
||||||
. $PSScriptRoot\Pivot.ps1
|
. $PSScriptRoot\Pivot.ps1
|
||||||
. $PSScriptRoot\Get-ExcelSheetInfo.ps1
|
. $PSScriptRoot\Get-ExcelSheetInfo.ps1
|
||||||
|
. $PSScriptRoot\Get-HtmlTable.ps1
|
||||||
|
. $PSScriptRoot\Import-Html.ps1
|
||||||
|
|
||||||
function Import-Excel {
|
function Import-Excel {
|
||||||
param(
|
param(
|
||||||
|
|||||||
19
Install.ps1
19
Install.ps1
@@ -1,6 +1,23 @@
|
|||||||
param([string]$InstallDirectory)
|
param([string]$InstallDirectory)
|
||||||
|
|
||||||
$fileList = echo EPPlus.dll ImportExcel.psd1 ImportExcel.psm1 Export-Excel.ps1 New-ConditionalFormattingIconSet.ps1 Export-ExcelSheet.ps1 New-ExcelChart.ps1 Invoke-Sum.ps1 InferData.ps1 Get-ExcelColumnName.ps1 Get-XYRange.ps1 Charting.ps1 New-PSItem.ps1 Pivot.ps1 New-ConditionalText.ps1
|
$fileList = echo `
|
||||||
|
EPPlus.dll `
|
||||||
|
ImportExcel.psd1 `
|
||||||
|
ImportExcel.psm1 `
|
||||||
|
Export-Excel.ps1 `
|
||||||
|
New-ConditionalFormattingIconSet.ps1 `
|
||||||
|
Export-ExcelSheet.ps1 `
|
||||||
|
New-ExcelChart.ps1 `
|
||||||
|
Invoke-Sum.ps1 `
|
||||||
|
InferData.ps1 `
|
||||||
|
Get-ExcelColumnName.ps1 `
|
||||||
|
Get-XYRange.ps1 `
|
||||||
|
Charting.ps1 `
|
||||||
|
New-PSItem.ps1 `
|
||||||
|
Pivot.ps1 `
|
||||||
|
New-ConditionalText.ps1 `
|
||||||
|
Get-HtmlTable.ps1 `
|
||||||
|
Import-Html.ps1
|
||||||
|
|
||||||
if ('' -eq $InstallDirectory)
|
if ('' -eq $InstallDirectory)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,11 +4,27 @@ $TargetPath = "$($ModulePath)\$($ModuleName)"
|
|||||||
|
|
||||||
if(!(Test-Path $TargetPath)) { md $TargetPath | out-null}
|
if(!(Test-Path $TargetPath)) { md $TargetPath | out-null}
|
||||||
|
|
||||||
Get-HtmlTable.ps1
|
$targetFiles = echo `
|
||||||
Import-Html.ps1
|
*.psm1 `
|
||||||
|
*.psd1 `
|
||||||
|
*.dll `
|
||||||
|
New-ConditionalFormattingIconSet.ps1 `
|
||||||
|
Export-Excel.ps1 `
|
||||||
|
Export-ExcelSheet.ps1 `
|
||||||
|
New-ExcelChart.ps1 `
|
||||||
|
Invoke-Sum.ps1 `
|
||||||
|
InferData.ps1 `
|
||||||
|
Get-ExcelColumnName.ps1 `
|
||||||
|
Get-XYRange.ps1 `
|
||||||
|
Charting.ps1 `
|
||||||
|
New-PSItem.ps1 `
|
||||||
|
Pivot.ps1 `
|
||||||
|
Get-ExcelSheetInfo.ps1 `
|
||||||
|
New-ConditionalText.ps1 `
|
||||||
|
Get-HtmlTable.ps1 `
|
||||||
|
Import-Html.ps1
|
||||||
|
|
||||||
$FilesToCopy = dir -erroraction ignore *.psm1, *.psd1, *.dll, New-ConditionalFormattingIconSet.ps1, Export-Excel.ps1, Export-ExcelSheet.ps1, New-ExcelChart.ps1, Invoke-Sum.ps1, InferData.ps1, Get-ExcelColumnName.ps1, Get-XYRange.ps1, Charting.ps1, New-PSItem.ps1, Pivot.ps1, Get-ExcelSheetInfo.ps1, New-ConditionalText.ps1
|
ls $targetFiles |
|
||||||
|
ForEach {
|
||||||
$FilesToCopy | ForEach {
|
Copy-Item -Verbose -Path $_.FullName -Destination "$($TargetPath)\$($_.name)"
|
||||||
Copy-Item -Verbose -Path $_.FullName -Destination "$($TargetPath)\$($_.name)"
|
}
|
||||||
}
|
|
||||||
28
README.md
28
README.md
@@ -16,6 +16,22 @@ To install in your personal modules folder (e.g. ~\Documents\WindowsPowerShell\M
|
|||||||
iex (new-object System.Net.WebClient).DownloadString('https://raw.github.com/dfinke/ImportExcel/master/Install.ps1')
|
iex (new-object System.Net.WebClient).DownloadString('https://raw.github.com/dfinke/ImportExcel/master/Install.ps1')
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Known Issues
|
||||||
|
-
|
||||||
|
* Using `-IncludePivotTable`, if that pivot table name exists, you'll get an error.
|
||||||
|
* Investigating a solution
|
||||||
|
* *Workaround* delete the Excel file first, then do the export
|
||||||
|
|
||||||
|
What's new
|
||||||
|
|
||||||
|
#### 2/22/2016
|
||||||
|
* `Import-Html` leveraged Lee Holmes [Extracting Tables from PowerShell’s Invoke-WebRequest](http://www.leeholmes.com/blog/2015/01/05/extracting-tables-from-powershells-invoke-webrequest/)
|
||||||
|
|
||||||
|
|
||||||
|
#### 2/17/2016
|
||||||
|
* Added Conditional Text types of `Equal` and `NotEqual`
|
||||||
|
* Phone #'s like '+33 011 234 34' will be now be handled correctly
|
||||||
|
|
||||||
## Try *PassThru*
|
## Try *PassThru*
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
@@ -46,18 +62,6 @@ Invoke-Item $file
|
|||||||
## Result
|
## Result
|
||||||

|

|
||||||
|
|
||||||
Known Issues
|
|
||||||
-
|
|
||||||
* Using `-IncludePivotTable`, if that pivot table name exists, you'll get an error.
|
|
||||||
* Investigating a solution
|
|
||||||
* *Workaround* delete the Excel file first, then do the export
|
|
||||||
|
|
||||||
What's new
|
|
||||||
|
|
||||||
#### 2/17/2016
|
|
||||||
* Added Conditional Text types of `Equal` and `NotEqual`
|
|
||||||
* Phone #'s like '+33 011 234 34' will be now be handled correctly
|
|
||||||
|
|
||||||
#### 1/18/2016
|
#### 1/18/2016
|
||||||
|
|
||||||
* Added `Conditional Text Formatting`. [Boe Prox](https://twitter.com/proxb) posted about [HTML Reporting, Part 2: Take Your Reporting a Step Further](https://mcpmag.com/articles/2016/01/14/html-reporting-part-2.aspx) and colorized cells. Great idea, now part of the PowerShell Excel module.
|
* Added `Conditional Text Formatting`. [Boe Prox](https://twitter.com/proxb) posted about [HTML Reporting, Part 2: Take Your Reporting a Step Further](https://mcpmag.com/articles/2016/01/14/html-reporting-part-2.aspx) and colorized cells. Great idea, now part of the PowerShell Excel module.
|
||||||
|
|||||||
Reference in New Issue
Block a user