mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-10 13:23:29 +00:00
Updates to Help text - mostly layout, inc making it VSCode freindly
This commit is contained in:
@@ -32,14 +32,14 @@
|
|||||||
[Parameter(Mandatory = $true, ParameterSetName = "FourIconSet")]
|
[Parameter(Mandatory = $true, ParameterSetName = "FourIconSet")]
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "FiveIconSet")]
|
[Parameter(Mandatory = $true, ParameterSetName = "FiveIconSet")]
|
||||||
[OfficeOpenXml.ExcelAddress]$Range ,
|
[OfficeOpenXml.ExcelAddress]$Range ,
|
||||||
#One or more row(s), Column(s) and/or block(s) of cells to format
|
#One or more row(s), column(s) and/or block(s) of cells to format
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "NamedRuleAddress")]
|
[Parameter(Mandatory = $true, ParameterSetName = "NamedRuleAddress")]
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "DataBarAddress")]
|
[Parameter(Mandatory = $true, ParameterSetName = "DataBarAddress")]
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "ThreeIconSetAddress")]
|
[Parameter(Mandatory = $true, ParameterSetName = "ThreeIconSetAddress")]
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "FourIconSetAddress")]
|
[Parameter(Mandatory = $true, ParameterSetName = "FourIconSetAddress")]
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "FiveIconSetAddress")]
|
[Parameter(Mandatory = $true, ParameterSetName = "FiveIconSetAddress")]
|
||||||
$Address ,
|
$Address ,
|
||||||
#One of the standard named rules - Top / Bottom / Less than / Greater than / Contains etc
|
#One of the standard named rules - Top / Bottom / Less than / Greater than / Contains etc.
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "NamedRule", Position = 3)]
|
[Parameter(Mandatory = $true, ParameterSetName = "NamedRule", Position = 3)]
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "NamedRuleAddress", Position = 3)]
|
[Parameter(Mandatory = $true, ParameterSetName = "NamedRuleAddress", Position = 3)]
|
||||||
[OfficeOpenXml.ConditionalFormatting.eExcelConditionalFormattingRuleType]$RuleType ,
|
[OfficeOpenXml.ConditionalFormatting.eExcelConditionalFormattingRuleType]$RuleType ,
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
[OfficeOpenXml.ConditionalFormatting.eExcelconditionalFormatting5IconsSetType]$FiveIconsSet,
|
[OfficeOpenXml.ConditionalFormatting.eExcelconditionalFormatting5IconsSetType]$FiveIconsSet,
|
||||||
#A value for the condition (e.g. "2000" if the test is 'lessthan 2000')
|
#A value for the condition (e.g. "2000" if the test is 'lessthan 2000')
|
||||||
[string]$ConditionValue,
|
[string]$ConditionValue,
|
||||||
#A second value for the conditions like between x and Y
|
#A second value for the conditions like "between x and Y"
|
||||||
[string]$ConditionValue2,
|
[string]$ConditionValue2,
|
||||||
#Background colour for matching items
|
#Background colour for matching items
|
||||||
[System.Drawing.Color]$BackgroundColor,
|
[System.Drawing.Color]$BackgroundColor,
|
||||||
|
|||||||
@@ -1,53 +1,53 @@
|
|||||||
Function Convert-XlRangeToImage {
|
Function Convert-XlRangeToImage {
|
||||||
<#
|
<#
|
||||||
.Synopsis
|
.Synopsis
|
||||||
Gets the specified part of an Excel file and exports it as an image
|
Gets the specified part of an Excel file and exports it as an image
|
||||||
.Description
|
.Description
|
||||||
Excel allows charts to be exported directly to a file, but can't do this with the rest of a sheet. To work round this this function
|
Excel allows charts to be exported directly to a file, but can't do this with the rest of a sheet. To work round this this function
|
||||||
* Opens a copy of Excel and loads a file
|
* Opens a copy of Excel and loads a file
|
||||||
* Selects a worksheet and then a range of cells in that worksheet
|
* Selects a worksheet and then a range of cells in that worksheet
|
||||||
* Copies the select to the clipboard
|
* Copies the select to the clipboard
|
||||||
* Saves the clipboard contents as an image file (it will save as .JPG unless the file name ends .BMP or .PNG)
|
* Saves the clipboard contents as an image file (it will save as .JPG unless the file name ends .BMP or .PNG)
|
||||||
* Copies a single cell to the clipboard (to prevent the "you have put a lot in the clipboard" message appearing)
|
* Copies a single cell to the clipboard (to prevent the "you have put a lot in the clipboard" message appearing)
|
||||||
* Closes Excel
|
* Closes Excel
|
||||||
#>
|
#>
|
||||||
Param (
|
Param (
|
||||||
#Path to the Excel file
|
#Path to the Excel file
|
||||||
[parameter(Mandatory=$true)]
|
[parameter(Mandatory=$true)]
|
||||||
$Path,
|
$Path,
|
||||||
#Worksheet name - if none is specified "Sheet1" will be assumed
|
#Worksheet name - if none is specified "Sheet1" will be assumed
|
||||||
$workSheetname = "Sheet1" ,
|
$workSheetname = "Sheet1" ,
|
||||||
#Range of cells within the sheet, e.g "A1:Z99"
|
#Range of cells within the sheet, e.g "A1:Z99"
|
||||||
[parameter(Mandatory=$true)]
|
[parameter(Mandatory=$true)]
|
||||||
$range,
|
$range,
|
||||||
#A bmp, png or jpg file where the result will be saved
|
#A bmp, png or jpg file where the result will be saved
|
||||||
$destination = "$pwd\temp.png",
|
$destination = "$pwd\temp.png",
|
||||||
#If specified opens the image in the default viewer.
|
#If specified opens the image in the default viewer.
|
||||||
[switch]$show
|
[switch]$show
|
||||||
)
|
)
|
||||||
$extension = $destination -replace '^.*\.(\w+)$' ,'$1'
|
$extension = $destination -replace '^.*\.(\w+)$' ,'$1'
|
||||||
if ($extension -in @('JPEG','BMP','PNG')) {
|
if ($extension -in @('JPEG','BMP','PNG')) {
|
||||||
$Format = [system.Drawing.Imaging.ImageFormat]$extension
|
$Format = [system.Drawing.Imaging.ImageFormat]$extension
|
||||||
} #if we don't recognise the extension OR if it is JPG with an E, use JPEG format
|
} #if we don't recognise the extension OR if it is JPG with an E, use JPEG format
|
||||||
else { $Format = [system.Drawing.Imaging.ImageFormat]::Jpeg}
|
else { $Format = [system.Drawing.Imaging.ImageFormat]::Jpeg}
|
||||||
Write-Progress -Activity "Exporting $range of $workSheetname in $Path" -Status "Starting Excel"
|
Write-Progress -Activity "Exporting $range of $workSheetname in $Path" -Status "Starting Excel"
|
||||||
$xlApp = New-Object -ComObject "Excel.Application"
|
$xlApp = New-Object -ComObject "Excel.Application"
|
||||||
Write-Progress -Activity "Exporting $range of $workSheetname in $Path" -Status "Opening Workbook and copying data"
|
Write-Progress -Activity "Exporting $range of $workSheetname in $Path" -Status "Opening Workbook and copying data"
|
||||||
$xlWbk = $xlApp.Workbooks.Open($Path)
|
$xlWbk = $xlApp.Workbooks.Open($Path)
|
||||||
$xlWbk.Worksheets($workSheetname).Select()
|
$xlWbk.Worksheets($workSheetname).Select()
|
||||||
$xlWbk.ActiveSheet.Range($range).Select() | Out-Null
|
$xlWbk.ActiveSheet.Range($range).Select() | Out-Null
|
||||||
$xlApp.Selection.Copy() | Out-Null
|
$xlApp.Selection.Copy() | Out-Null
|
||||||
Write-Progress -Activity "Exporting $range of $workSheetname in $Path" -Status "Saving copied data"
|
Write-Progress -Activity "Exporting $range of $workSheetname in $Path" -Status "Saving copied data"
|
||||||
# Get-Clipboard came in with PS5. Older versions can use [System.Windows.Clipboard] but it is ugly.
|
# Get-Clipboard came in with PS5. Older versions can use [System.Windows.Clipboard] but it is ugly.
|
||||||
$image = Get-Clipboard -Format Image
|
$image = Get-Clipboard -Format Image
|
||||||
$image.Save($destination, $Format)
|
$image.Save($destination, $Format)
|
||||||
Write-Progress -Activity "Exporting $range of $workSheetname in $Path" -Status "Closing Excel"
|
Write-Progress -Activity "Exporting $range of $workSheetname in $Path" -Status "Closing Excel"
|
||||||
$xlWbk.ActiveSheet.Range("a1").Select() | Out-Null
|
$xlWbk.ActiveSheet.Range("a1").Select() | Out-Null
|
||||||
$xlApp.Selection.Copy() | Out-Null
|
$xlApp.Selection.Copy() | Out-Null
|
||||||
$xlApp.Quit()
|
$xlApp.Quit()
|
||||||
Write-Progress -Activity "Exporting $range of $workSheetname in $Path" -Completed
|
Write-Progress -Activity "Exporting $range of $workSheetname in $Path" -Completed
|
||||||
if ($show) {Start-Process -FilePath $destination}
|
if ($show) {Start-Process -FilePath $destination}
|
||||||
else {Get-Item -Path $destination}
|
else {Get-Item -Path $destination}
|
||||||
}
|
}
|
||||||
<#
|
<#
|
||||||
del demo*.xlsx
|
del demo*.xlsx
|
||||||
|
|||||||
@@ -1,25 +1,25 @@
|
|||||||
function ConvertFrom-ExcelData {
|
function ConvertFrom-ExcelData {
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Reads data from a sheet, and for each row, calls a custom scriptblock with a list of property names and the row of data.
|
Reads data from a sheet, and for each row, calls a custom scriptblock with a list of property names and the row of data.
|
||||||
|
|
||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
ConvertFrom-ExcelData .\testSQLGen.xlsx {
|
ConvertFrom-ExcelData .\testSQLGen.xlsx {
|
||||||
param($propertyNames, $record)
|
param($propertyNames, $record)
|
||||||
|
|
||||||
$reportRecord = @()
|
$reportRecord = @()
|
||||||
foreach ($pn in $propertyNames) {
|
foreach ($pn in $propertyNames) {
|
||||||
$reportRecord += "{0}: {1}" -f $pn, $record.$pn
|
$reportRecord += "{0}: {1}" -f $pn, $record.$pn
|
||||||
|
}
|
||||||
|
$reportRecord +=""
|
||||||
|
$reportRecord -join "`r`n"
|
||||||
}
|
}
|
||||||
$reportRecord +=""
|
|
||||||
$reportRecord -join "`r`n"
|
|
||||||
}
|
|
||||||
|
|
||||||
First: John
|
First: John
|
||||||
Last: Doe
|
Last: Doe
|
||||||
The Zip: 12345
|
The Zip: 12345
|
||||||
....
|
....
|
||||||
#>
|
#>
|
||||||
param(
|
param(
|
||||||
[Alias("FullName")]
|
[Alias("FullName")]
|
||||||
|
|||||||
@@ -1,51 +1,34 @@
|
|||||||
function ConvertFrom-ExcelToSQLInsert {
|
function ConvertFrom-ExcelToSQLInsert {
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Generate SQL insert statements from Excel spreadsheet.
|
Generate SQL insert statements from Excel spreadsheet.
|
||||||
|
.DESCRIPTION
|
||||||
.DESCRIPTION
|
|
||||||
Generate SQL insert statements from Excel spreadsheet.
|
Generate SQL insert statements from Excel spreadsheet.
|
||||||
|
.PARAMETER TableName
|
||||||
.PARAMETER TableName
|
|
||||||
Name of the target database table.
|
Name of the target database table.
|
||||||
|
.PARAMETER Path
|
||||||
.PARAMETER Path
|
|
||||||
Path to an existing .XLSX file
|
Path to an existing .XLSX file
|
||||||
|
|
||||||
This parameter is passed to Import-Excel as is.
|
This parameter is passed to Import-Excel as is.
|
||||||
|
.PARAMETER WorkSheetname
|
||||||
.PARAMETER WorkSheetname
|
|
||||||
Specifies the name of the worksheet in the Excel workbook to import. By default, if no name is provided, the first worksheet will be imported.
|
Specifies the name of the worksheet in the Excel workbook to import. By default, if no name is provided, the first worksheet will be imported.
|
||||||
|
|
||||||
This parameter is passed to Import-Excel as is.
|
This parameter is passed to Import-Excel as is.
|
||||||
|
.PARAMETER StartRow
|
||||||
.PARAMETER StartRow
|
|
||||||
The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row.
|
The row from where we start to import data, all rows above the StartRow are disregarded. By default this is the first row.
|
||||||
|
|
||||||
When the parameters ‘-NoHeader’ and ‘-HeaderName’ are not provided, this row will contain the column headers that will be used as property names. When one of both parameters are provided, the property names are automatically created and this row will be treated as a regular row containing data.
|
When the parameters ‘-NoHeader’ and ‘-HeaderName’ are not provided, this row will contain the column headers that will be used as property names. When one of both parameters are provided, the property names are automatically created and this row will be treated as a regular row containing data.
|
||||||
|
.PARAMETER Header
|
||||||
.PARAMETER Header
|
|
||||||
Specifies custom property names to use, instead of the values defined in the column headers of the TopRow.
|
Specifies custom property names to use, instead of the values defined in the column headers of the TopRow.
|
||||||
|
If you provide fewr header names than there is data in the worksheet, then only the data with a corresponding header name will be imported and the data without header name will be disregarded.
|
||||||
In case you provide less header names than there is data in the worksheet, then only the data with a corresponding header name will be imported and the data without header name will be disregarded.
|
If you provide more header names than there is data in the worksheet, then all data will be imported and all objects will have all the property names you defined in the header names. As such, the last properties will be blank as there is no data for them.
|
||||||
|
.PARAMETER NoHeader
|
||||||
In case you provide more header names than there is data in the worksheet, then all data will be imported and all objects will have all the property names you defined in the header names. As such, the last properties will be blanc as there is no data for them.
|
|
||||||
|
|
||||||
.PARAMETER NoHeader
|
|
||||||
Automatically generate property names (P1, P2, P3, ..) instead of the ones defined in the column headers of the TopRow.
|
Automatically generate property names (P1, P2, P3, ..) instead of the ones defined in the column headers of the TopRow.
|
||||||
|
|
||||||
This switch is best used when you want to import the complete worksheet ‘as is’ and are not concerned with the property names.
|
This switch is best used when you want to import the complete worksheet ‘as is’ and are not concerned with the property names.
|
||||||
|
.PARAMETER DataOnly
|
||||||
.PARAMETER DataOnly
|
|
||||||
Import only rows and columns that contain data, empty rows and empty columns are not imported.
|
Import only rows and columns that contain data, empty rows and empty columns are not imported.
|
||||||
|
.PARAMETER ConvertEmptyStringsToNull
|
||||||
|
|
||||||
.PARAMETER ConvertEmptyStringsToNull
|
|
||||||
If specified, cells without any data are replaced with NULL, instead of an empty string.
|
If specified, cells without any data are replaced with NULL, instead of an empty string.
|
||||||
|
|
||||||
This is to address behviors in certain DBMS where an empty string is insert as 0 for INT column, instead of a NULL value.
|
This is to address behviors in certain DBMS where an empty string is insert as 0 for INT column, instead of a NULL value.
|
||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Generate SQL insert statements from Movies.xlsx file, leaving blank cells as empty strings:
|
Generate SQL insert statements from Movies.xlsx file, leaving blank cells as empty strings:
|
||||||
|
|
||||||
----------------------------------------------------------
|
----------------------------------------------------------
|
||||||
@@ -65,7 +48,7 @@ function ConvertFrom-ExcelToSQLInsert {
|
|||||||
INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('Skyfall', '2012', '9');
|
INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('Skyfall', '2012', '9');
|
||||||
INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Avengers', '2012', '');
|
INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Avengers', '2012', '');
|
||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Generate SQL insert statements from Movies.xlsx file, specify NULL instead of an empty string.
|
Generate SQL insert statements from Movies.xlsx file, specify NULL instead of an empty string.
|
||||||
|
|
||||||
----------------------------------------------------------
|
----------------------------------------------------------
|
||||||
@@ -85,7 +68,6 @@ function ConvertFrom-ExcelToSQLInsert {
|
|||||||
INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('Skyfall', '2012', '9');
|
INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('Skyfall', '2012', '9');
|
||||||
INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Avengers', '2012', NULL);
|
INSERT INTO Movies ('Movie Name', 'Year', 'Rating') Values('The Avengers', '2012', NULL);
|
||||||
|
|
||||||
.NOTES
|
|
||||||
#>
|
#>
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param(
|
param(
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
.Synopsis
|
.Synopsis
|
||||||
Exports the charts in an Excel spreadSheet
|
Exports the charts in an Excel spreadSheet
|
||||||
.Example
|
.Example
|
||||||
Export-Charts .\test,xlsx
|
Export-Charts .\test.xlsx
|
||||||
Exports the charts in test.xlsx to JPEG files in the current directory.
|
Exports the charts in test.xlsx to JPEG files in the current directory.
|
||||||
|
|
||||||
.Example
|
.Example
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
Param (
|
Param (
|
||||||
#Path to the Excel file whose chars we will export.
|
#Path to the Excel file whose chars we will export.
|
||||||
$Path = "C:\Users\public\Documents\stats.xlsx",
|
$Path = "C:\Users\public\Documents\stats.xlsx",
|
||||||
#If specified, output file objects representing the image files.
|
#If specified, output file objects representing the image files
|
||||||
[switch]$Passthru,
|
[switch]$Passthru,
|
||||||
#Format to write - JPG by default
|
#Format to write - JPG by default
|
||||||
[ValidateSet("JPG","PNG","GIF")]
|
[ValidateSet("JPG","PNG","GIF")]
|
||||||
|
|||||||
@@ -1,24 +1,20 @@
|
|||||||
Function Get-ExcelSheetInfo {
|
Function Get-ExcelSheetInfo {
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Get worksheet names and their indices of an Excel workbook.
|
Get worksheet names and their indices of an Excel workbook.
|
||||||
|
.DESCRIPTION
|
||||||
.DESCRIPTION
|
|
||||||
The Get-ExcelSheetInfo cmdlet gets worksheet names and their indices of an Excel workbook.
|
The Get-ExcelSheetInfo cmdlet gets worksheet names and their indices of an Excel workbook.
|
||||||
|
.PARAMETER Path
|
||||||
.PARAMETER Path
|
|
||||||
Specifies the path to the Excel file. This parameter is required.
|
Specifies the path to the Excel file. This parameter is required.
|
||||||
|
.EXAMPLE
|
||||||
.EXAMPLE
|
|
||||||
Get-ExcelSheetInfo .\Test.xlsx
|
Get-ExcelSheetInfo .\Test.xlsx
|
||||||
|
|
||||||
.NOTES
|
.NOTES
|
||||||
CHANGELOG
|
CHANGELOG
|
||||||
2016/01/07 Added Created by Johan Akerstrom (https://github.com/CosmosKey)
|
2016/01/07 Added Created by Johan Akerstrom (https://github.com/CosmosKey)
|
||||||
|
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/dfinke/ImportExcel
|
https://github.com/dfinke/ImportExcel
|
||||||
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
Function Get-ExcelWorkbookInfo {
|
Function Get-ExcelWorkbookInfo {
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Retrieve information of an Excel workbook.
|
Retrieve information of an Excel workbook.
|
||||||
|
.DESCRIPTION
|
||||||
.DESCRIPTION
|
|
||||||
The Get-ExcelWorkbookInfo cmdlet retrieves information (LastModifiedBy, LastPrinted, Created, Modified, ...) fron an Excel workbook. These are the same details that are visible in Windows Explorer when right clicking the Excel file, selecting Properties and check the Details tabpage.
|
The Get-ExcelWorkbookInfo cmdlet retrieves information (LastModifiedBy, LastPrinted, Created, Modified, ...) fron an Excel workbook. These are the same details that are visible in Windows Explorer when right clicking the Excel file, selecting Properties and check the Details tabpage.
|
||||||
|
.PARAMETER Path
|
||||||
.PARAMETER Path
|
|
||||||
Specifies the path to the Excel file. This parameter is required.
|
Specifies the path to the Excel file. This parameter is required.
|
||||||
|
.EXAMPLE
|
||||||
.EXAMPLE
|
|
||||||
Get-ExcelWorkbookInfo .\Test.xlsx
|
Get-ExcelWorkbookInfo .\Test.xlsx
|
||||||
|
|
||||||
CorePropertiesXml : #document
|
CorePropertiesXml : #document
|
||||||
@@ -32,11 +29,11 @@
|
|||||||
Modified : 10/02/2017 12:45:37
|
Modified : 10/02/2017 12:45:37
|
||||||
CustomPropertiesXml : #document
|
CustomPropertiesXml : #document
|
||||||
|
|
||||||
.NOTES
|
.NOTES
|
||||||
CHANGELOG
|
CHANGELOG
|
||||||
2016/01/07 Added Created by Johan Akerstrom (https://github.com/CosmosKey)
|
2016/01/07 Added Created by Johan Akerstrom (https://github.com/CosmosKey)
|
||||||
|
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/dfinke/ImportExcel
|
https://github.com/dfinke/ImportExcel
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
|||||||
@@ -1,31 +1,32 @@
|
|||||||
Function Set-Column {
|
Function Set-Column {
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Adds a column to the existing data area in an Excel sheet, fills values and sets formatting
|
Adds a column to the existing data area in an Excel sheet, fills values and sets formatting
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
Set-Column takes a value which is either string containing a value or formula or a scriptblock
|
Set-Column takes a value which is either string containing a value or formula or a scriptblock
|
||||||
which evaluates to a string, and optionally a column number and fills that value down the column.
|
which evaluates to a string, and optionally a column number and fills that value down the column.
|
||||||
A column name can be specified and the new column can be made a named range.
|
A column name can be specified and the new column can be made a named range.
|
||||||
The column can be formatted.
|
The column can be formatted.
|
||||||
.Example
|
.Example
|
||||||
C:> Set-Column -Worksheet $ws -Heading "WinsToFastLaps" -Value {"=E$row/C$row"} -Column 7 -AutoSize -AutoNameRange
|
C:> Set-Column -Worksheet $ws -Heading "WinsToFastLaps" -Value {"=E$row/C$row"} -Column 7 -AutoSize -AutoNameRange
|
||||||
Here $WS already contains a worksheet which contains counts of races won and fastest laps recorded by racing drivers (in columns C and E)
|
Here $WS already contains a worksheet which contains counts of races won and fastest laps recorded by racing drivers (in columns C and E)
|
||||||
Set-Column specifies that Column 7 should have a heading of "WinsToFastLaps" and the data cells should contain =E2/C2 , =E3/C3
|
Set-Column specifies that Column 7 should have a heading of "WinsToFastLaps" and the data cells should contain =E2/C2 , =E3/C3
|
||||||
the data celss should become a named range, which will also be "WinsToFastLaps" the column width will be set automatically
|
the data cells should become a named range, which will also be "WinsToFastLaps" the column width will be set automatically
|
||||||
|
#>
|
||||||
#>
|
[cmdletbinding()]
|
||||||
[cmdletbinding()]
|
|
||||||
Param (
|
Param (
|
||||||
[Parameter(ParameterSetName="Package",Mandatory=$true)]
|
[Parameter(ParameterSetName="Package",Mandatory=$true)]
|
||||||
[OfficeOpenXml.ExcelPackage]$ExcelPackage,
|
[OfficeOpenXml.ExcelPackage]$ExcelPackage,
|
||||||
#Sheet to update
|
#The sheet to update can be a given as a name or an Excel Worksheet object - this sets it by name
|
||||||
[Parameter(ParameterSetName="Package")]
|
[Parameter(ParameterSetName="Package")]
|
||||||
|
#The sheet to update can be a given as a name or an Excel Worksheet object - $workSheet contains the object
|
||||||
$Worksheetname = "Sheet1",
|
$Worksheetname = "Sheet1",
|
||||||
[Parameter(ParameterSetName="sheet",Mandatory=$true)]
|
[Parameter(ParameterSetName="sheet",Mandatory=$true)]
|
||||||
[OfficeOpenXml.ExcelWorksheet]
|
[OfficeOpenXml.ExcelWorksheet]
|
||||||
$Worksheet,
|
$Worksheet,
|
||||||
#Column to fill down - first column is 1. 0 will be interpreted as first unused column
|
#Column to fill down - first column is 1. 0 will be interpreted as first unused column
|
||||||
$Column = 0 ,
|
$Column = 0 ,
|
||||||
|
#First row to fill data in
|
||||||
[Int]$StartRow ,
|
[Int]$StartRow ,
|
||||||
#value, formula or script block for to fill in. Script block can use $row, $column [number], $ColumnName [letter(s)], $startRow, $startColumn, $endRow, $endColumn
|
#value, formula or script block for to fill in. Script block can use $row, $column [number], $ColumnName [letter(s)], $startRow, $startColumn, $endRow, $endColumn
|
||||||
[parameter(Mandatory=$true)]
|
[parameter(Mandatory=$true)]
|
||||||
@@ -76,8 +77,9 @@
|
|||||||
[Switch]$AutoSize,
|
[Switch]$AutoSize,
|
||||||
#Set cells to a fixed width, ignored if Autosize is specified
|
#Set cells to a fixed width, ignored if Autosize is specified
|
||||||
[float]$Width,
|
[float]$Width,
|
||||||
#Set the inserted data to be a named range (ignored if header is not specified) d
|
#Set the inserted data to be a named range (ignored if header is not specified)
|
||||||
[Switch]$AutoNameRange,
|
[Switch]$AutoNameRange,
|
||||||
|
#If Specified, return an ExcelPackage object to allow further work to be done on the file.
|
||||||
[switch]$PassThru
|
[switch]$PassThru
|
||||||
)
|
)
|
||||||
#if we were passed a package object and a worksheet name , get the worksheet.
|
#if we were passed a package object and a worksheet name , get the worksheet.
|
||||||
@@ -125,7 +127,7 @@
|
|||||||
if ($HorizontalAlignment) { $Worksheet.Column( $Column).Style.HorizontalAlignment = $HorizontalAlignment}
|
if ($HorizontalAlignment) { $Worksheet.Column( $Column).Style.HorizontalAlignment = $HorizontalAlignment}
|
||||||
if ($VerticalAlignment) { $Worksheet.Column( $Column).Style.VerticalAlignment = $VerticalAlignment }
|
if ($VerticalAlignment) { $Worksheet.Column( $Column).Style.VerticalAlignment = $VerticalAlignment }
|
||||||
if ($FontColor) { $Worksheet.Column( $Column).Style.Font.Color.SetColor( $FontColor ) }
|
if ($FontColor) { $Worksheet.Column( $Column).Style.Font.Color.SetColor( $FontColor ) }
|
||||||
if ($BorderAround) { $Worksheet.Column( $Column).Style.Border.BorderAround( $BorderAround ) }
|
if ($BorderAround) { $Worksheet.Column( $Column).Style.Border.BorderAround( $BorderAround ) }
|
||||||
if ($BackgroundColor) {
|
if ($BackgroundColor) {
|
||||||
$Worksheet.Column( $Column).Style.Fill.PatternType = $BackgroundPattern
|
$Worksheet.Column( $Column).Style.Fill.PatternType = $BackgroundPattern
|
||||||
$Worksheet.Column( $Column).Style.Fill.BackgroundColor.SetColor($BackgroundColor )
|
$Worksheet.Column( $Column).Style.Fill.BackgroundColor.SetColor($BackgroundColor )
|
||||||
|
|||||||
39
Set-Row.ps1
39
Set-Row.ps1
@@ -1,24 +1,22 @@
|
|||||||
Function Set-Row {
|
Function Set-Row {
|
||||||
<#
|
<#
|
||||||
.Synopsis
|
.Synopsis
|
||||||
Fills values into a row in a Excel spreadsheet
|
Fills values into a row in a Excel spreadsheet
|
||||||
.Description
|
.Description
|
||||||
Set-Row accepts either a Worksheet object or an Excel package object returned by Export-Excel and the name of a sheet,
|
Set-Row accepts either a Worksheet object or an Excel package object returned by Export-Excel and the name of a sheet,
|
||||||
and inserts the chosen contents into a row of the sheet.
|
and inserts the chosen contents into a row of the sheet.
|
||||||
The contents can be a constant "42" , a formula or a script block which is converted into a constant or formula.
|
The contents can be a constant "42" , a formula or a script block which is converted into a constant or formula.
|
||||||
The first cell of the row can optional be given a heading.
|
The first cell of the row can optional be given a heading.
|
||||||
.Example
|
.Example
|
||||||
Set-row -Worksheet $ws -Heading Total -Value {"=sum($columnName`2:$columnName$endrow)" }
|
Set-row -Worksheet $ws -Heading Total -Value {"=sum($columnName`2:$columnName$endrow)" }
|
||||||
|
|
||||||
$Ws contains a worksheet object, and no Row number is specified so Set-Row will select the next row after the end of the data in the sheet
|
$Ws contains a worksheet object, and no Row number is specified so Set-Row will select the next row after the end of the data in the sheet
|
||||||
The first cell will contain "Total", and each other cell will contain
|
The first cell will contain "Total", and each other cell will contain
|
||||||
=Sum(xx2:xx99) - where xx is the column name, and 99 is the last row of data.
|
=Sum(xx2:xx99) - where xx is the column name, and 99 is the last row of data.
|
||||||
Note the use of `2 to Prevent 2 becoming part of the variable "ColumnName"
|
Note the use of `2 to Prevent 2 becoming part of the variable "ColumnName"
|
||||||
The script block can use $row, $column, $ColumnName, $startRow/Column $endRow/Column
|
The script block can use $row, $column, $ColumnName, $startRow/Column $endRow/Column
|
||||||
|
#>
|
||||||
|
[cmdletbinding()]
|
||||||
#>
|
|
||||||
[cmdletbinding()]
|
|
||||||
Param (
|
Param (
|
||||||
#An Excel package object - e.g. from Export-Excel -passthru - requires a sheet name
|
#An Excel package object - e.g. from Export-Excel -passthru - requires a sheet name
|
||||||
[Parameter(ParameterSetName="Package",Mandatory=$true)]
|
[Parameter(ParameterSetName="Package",Mandatory=$true)]
|
||||||
@@ -75,11 +73,12 @@
|
|||||||
[OfficeOpenXml.Style.ExcelHorizontalAlignment]$HorizontalAlignment,
|
[OfficeOpenXml.Style.ExcelHorizontalAlignment]$HorizontalAlignment,
|
||||||
#Position cell contents to top bottom or centre
|
#Position cell contents to top bottom or centre
|
||||||
[OfficeOpenXml.Style.ExcelVerticalAlignment]$VerticalAlignment,
|
[OfficeOpenXml.Style.ExcelVerticalAlignment]$VerticalAlignment,
|
||||||
#Degrees to rotate text. Up to +90 for anti-clockwise ("upwards"), or to -90 for clockwise.
|
#Degrees to rotate text. Up to +90 for anti-clockwise ("upwards"), or to -90 for clockwise
|
||||||
[ValidateRange(-90, 90)]
|
[ValidateRange(-90, 90)]
|
||||||
[int]$TextRotation ,
|
[int]$TextRotation ,
|
||||||
#Set cells to a fixed hieght
|
#Set cells to a fixed hieght
|
||||||
[float]$Height,
|
[float]$Height,
|
||||||
|
#If Specified, return an ExcelPackage object to allow further work to be done on the file
|
||||||
[switch]$PassThru
|
[switch]$PassThru
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,8 @@ Function Update-FirstObjectProperties {
|
|||||||
|
|
||||||
.NOTES
|
.NOTES
|
||||||
CHANGELOG
|
CHANGELOG
|
||||||
2017/06/08 Function born #>
|
2017/06/08 Function born
|
||||||
|
#>
|
||||||
|
|
||||||
Try {
|
Try {
|
||||||
$Union = @()
|
$Union = @()
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
Function Add-ConditionalFormatting {
|
Function Add-ConditionalFormatting {
|
||||||
<#
|
<#
|
||||||
.Synopsis
|
.Synopsis
|
||||||
Adds contitional formatting to worksheet
|
Adds contitional formatting to worksheet
|
||||||
.Example
|
.Example
|
||||||
$excel = $avdata | Export-Excel -Path (Join-path $FilePath "\Machines.XLSX" ) -WorksheetName "Server Anti-Virus" -AutoSize -FreezeTopRow -AutoFilter -PassThru
|
$excel = $avdata | Export-Excel -Path (Join-path $FilePath "\Machines.XLSX" ) -WorksheetName "Server Anti-Virus" -AutoSize -FreezeTopRow -AutoFilter -PassThru
|
||||||
|
|
||||||
Add-ConditionalFormatting -WorkSheet $excel.Workbook.Worksheets[1] -Address "b":b1048576" -ForeGroundColor "RED" -RuleType ContainsText -ConditionValue "2003"
|
Add-ConditionalFormatting -WorkSheet $excel.Workbook.Worksheets[1] -Address "b":b1048576" -ForeGroundColor "RED" -RuleType ContainsText -ConditionValue "2003"
|
||||||
Add-ConditionalFormatting -WorkSheet $excel.Workbook.Worksheets[1] -Address "i2:i1048576" -ForeGroundColor "RED" -RuleType ContainsText -ConditionValue "Disabled"
|
Add-ConditionalFormatting -WorkSheet $excel.Workbook.Worksheets[1] -Address "i2:i1048576" -ForeGroundColor "RED" -RuleType ContainsText -ConditionValue "Disabled"
|
||||||
$excel.Workbook.Worksheets[1].Cells["D1:G1048576"].Style.Numberformat.Format = [cultureinfo]::CurrentCulture.DateTimeFormat.ShortDatePattern
|
$excel.Workbook.Worksheets[1].Cells["D1:G1048576"].Style.Numberformat.Format = [cultureinfo]::CurrentCulture.DateTimeFormat.ShortDatePattern
|
||||||
$excel.Workbook.Worksheets[1].Row(1).style.font.bold = $true
|
$excel.Workbook.Worksheets[1].Row(1).style.font.bold = $true
|
||||||
$excel.Save() ; $excel.Dispose()
|
$excel.Save() ; $excel.Dispose()
|
||||||
|
|
||||||
Here Export-Excel is called with the -passThru parameter so the Excel Package object is stored in $Excel
|
Here Export-Excel is called with the -passThru parameter so the Excel Package object is stored in $Excel
|
||||||
The desired worksheet is selected and the then columns B and i are conditially formatted (excluding the top row) to show
|
The desired worksheet is selected and the then columns B and i are conditially formatted (excluding the top row) to show
|
||||||
Fixed formats are then applied to dates in columns D..G and the top row is formatted
|
Fixed formats are then applied to dates in columns D..G and the top row is formatted
|
||||||
Finally the workbook is saved and the Excel closed.
|
Finally the workbook is saved and the Excel closed.
|
||||||
|
|
||||||
#>
|
#>
|
||||||
Param (
|
Param (
|
||||||
#The worksheet where the format is to be applied
|
#The worksheet where the format is to be applied
|
||||||
[OfficeOpenXml.ExcelWorksheet]$WorkSheet ,
|
[OfficeOpenXml.ExcelWorksheet]$WorkSheet ,
|
||||||
@@ -89,17 +89,17 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
Function Set-Format {
|
Function Set-Format {
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Applies Number, font, alignment and colour formatting to a range of Excel Cells
|
Applies Number, font, alignment and colour formatting to a range of Excel Cells
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
$sheet.Column(3) | Set-Format -HorizontalAlignment Right -NumberFormat "#,###"
|
$sheet.Column(3) | Set-Format -HorizontalAlignment Right -NumberFormat "#,###"
|
||||||
Selects column 3 from a sheet object (within a workbook object, which is a child of the ExcelPackage object) and passes it to Set-Format which formats as an integer with comma seperated groups
|
Selects column 3 from a sheet object (within a workbook object, which is a child of the ExcelPackage object) and passes it to Set-Format which formats as an integer with comma seperated groups
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Set-Format -Address $sheet.Cells["E1:H1048576"] -HorizontalAlignment Right -NumberFormat "#,###"
|
Set-Format -Address $sheet.Cells["E1:H1048576"] -HorizontalAlignment Right -NumberFormat "#,###"
|
||||||
Instead of piping the address in this version specifies a block of cells and applies similar formatting
|
Instead of piping the address in this version specifies a block of cells and applies similar formatting
|
||||||
|
|
||||||
#>
|
#>
|
||||||
Param (
|
Param (
|
||||||
#One or more row(s), Column(s) and/or block(s) of cells to format
|
#One or more row(s), Column(s) and/or block(s) of cells to format
|
||||||
[Parameter(ValueFromPipeline=$true)]
|
[Parameter(ValueFromPipeline=$true)]
|
||||||
|
|||||||
Reference in New Issue
Block a user