mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-12 14:23:14 +00:00
Two things, checks for $Chart.DataLabel and if the directory for the xlsx path does not exist, it creates it
This commit is contained in:
@@ -548,7 +548,12 @@
|
||||
Else {
|
||||
$Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path)
|
||||
|
||||
if (Test-Path $Path) {
|
||||
$targetPath = Split-Path $Path
|
||||
if (!(Test-Path $targetPath)) {
|
||||
Write-Debug "Base path $($targetPath) does not exist, creating"
|
||||
$null = mkdir $targetPath -ErrorAction Ignore
|
||||
}
|
||||
elseif (Test-Path $Path) {
|
||||
Write-Debug "Path '$Path' already exists"
|
||||
}
|
||||
|
||||
@@ -572,7 +577,8 @@
|
||||
$row = $ws.Dimension.Rows
|
||||
Write-Debug -Message ("Appending: headers are " + ($script:Header -join ", ") + "Start row $row")
|
||||
}
|
||||
elseif($Title) { #Can only add a title if not appending
|
||||
elseif ($Title) {
|
||||
#Can only add a title if not appending
|
||||
$Row = $StartRow
|
||||
Add-Title
|
||||
$Row ++ ; $startRow ++
|
||||
@@ -587,7 +593,8 @@
|
||||
$pattern = 'string|bool|byte|char|decimal|double|float|int|long|sbyte|short|uint|ulong|ushort'
|
||||
}
|
||||
Catch {
|
||||
if ($AlreadyExists) { #Is this set anywhere ?
|
||||
if ($AlreadyExists) {
|
||||
#Is this set anywhere ?
|
||||
throw "Failed exporting worksheet '$WorkSheetname' to '$Path': The worksheet '$WorkSheetname' already exists."
|
||||
}
|
||||
else {
|
||||
@@ -769,8 +776,10 @@
|
||||
$chart = $wsPivot.Drawings.AddChart('PivotChart', $ChartType, $pivotTable)
|
||||
$chart.SetPosition(0, 0, 4, 0) #Changed position to top row, next to a chart which doesn't pivot on columns
|
||||
$chart.SetSize(600, 400)
|
||||
if ($chart.DataLabel) {
|
||||
$chart.DataLabel.ShowCategory = [boolean]$item.value.ShowCategory
|
||||
$chart.DataLabel.ShowPercent = [boolean]$item.value.ShowPercent
|
||||
}
|
||||
if ([boolean]$item.value.NoLegend) {$chart.Legend.Remove()}
|
||||
if ($item.value.ChartTitle) {$chart.Title.Text = $item.value.chartTitle}
|
||||
}
|
||||
@@ -778,7 +787,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
if ($IncludePivotTable -or $IncludePivotChart) { #changed so -includePivotChart Implies -includePivotTable.
|
||||
if ($IncludePivotTable -or $IncludePivotChart) {
|
||||
#changed so -includePivotChart Implies -includePivotTable.
|
||||
$pivotTableName = $WorkSheetname + 'PivotTable'
|
||||
#Make sure the Pivot table sheet doesn't already exist
|
||||
try { $pkg.Workbook.Worksheets.Delete( $pivotTableName) } catch {}
|
||||
@@ -822,8 +832,10 @@
|
||||
|
||||
if ($IncludePivotChart) {
|
||||
$chart = $wsPivot.Drawings.AddChart('PivotChart', $ChartType, $pivotTable)
|
||||
if ($chart.DataLabel) {
|
||||
$chart.DataLabel.ShowCategory = $ShowCategory
|
||||
$chart.DataLabel.ShowPercent = $ShowPercent
|
||||
}
|
||||
$chart.SetPosition(0, 26, 2, 26) # if Pivot table is rows+data only it will be 2 columns wide if has pivot columns we don't know how wide it will be
|
||||
if ($NoLegend) {
|
||||
$chart.Legend.Remove()
|
||||
|
||||
Reference in New Issue
Block a user