Help updates after more proof-reading

This commit is contained in:
jhoneill
2018-10-19 11:12:46 +01:00
parent 61173d5e40
commit 0fdaeb977b
3 changed files with 94 additions and 69 deletions

View File

@@ -1,47 +1,57 @@
Function Set-ExcelColumn {
<#
.SYNOPSIS
Adds or modifies a column in an Excel sheet, filling values, settings formatting and/or creating named ranges.
Adds or modifies a column in an Excel worksheet, filling values, setting formatting and/or creating named ranges.
.DESCRIPTION
Set-ExcelColumn can take a value which is either a 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.
Set-ExcelColumn can take a value which is either a 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.
A column heading can be specified, and the column can be made a named range.
The column can be formatted in the same operation.
.EXAMPLE
Set-ExcelColumn -Worksheet $ws -Column 5 -NumberFormat 'Currency'
$ws contains a worksheet object - and column E is set to use the local currency format.
Intelisense will complete predefined number formats. You can see how currency is interpreted on the local computer with the command
$ws contains a worksheet object - and column "E" is set to use the
local currency format. Intelisense will complete the names of predefined
number formats. You can see how currency is interpreted on the
local computer with the command
Expand-NumberFormat currency
.EXAMPLE
Set-ExcelColumn -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).
Set-ExcelColumn specifies that Column 7 should have a heading of "WinsToFastLaps" and the data cells should contain =E2/C2 , =E3/C3 etc
the new data cells should become a named range, which will also be named "WinsToFastLaps" the column width will be set automatically.
.EXAMPLE.
Here, $WS already contains a worksheet which holds counts of races won
and fastest laps recorded by racing drivers (in columns C and E).
Set-ExcelColumn specifies that Column 7 should have a heading of
"WinsToFastLaps" and the data cells should contain =E2/C2 , =E3/C3 etc
the new data cells should become a named range, which will also be
named "WinsToFastLaps" and the column width will be set automatically.
.EXAMPLE
Set-ExcelColumn -Worksheet $ws -Heading "Link" -Value {"https://en.wikipedia.org" + $worksheet.cells["B$Row"].value } -AutoSize
In this example, the worksheet in $ws has partial links to wikipedia pages in column B.
The -Value parameter is is a script block and it outputs a string which begins https... and ends with the value of cell at
column B in the current row. When given a valid URI, Set-ExcelColumn makes it a hyperlink. The column will be autosized to fit the links.
In this example, the worksheet in $ws has partial links to Wikipedia
pages in column B. The -Value parameter is a script block which
outputs a string beginning "https..." and ending with the value of
the cell at column B in the current row.
When given a valid URI, Set-ExcelColumn makes it a hyperlink.
The column will be autosized to fit the links.
.EXAMPLE
4..6 | Set-ExcelColumn -Worksheet $ws -AutoNameRange
Again $ws contains a worksheet. Here columns 4 to 6 are made into named ranges, row 1 is used for the range name
Again $ws contains a worksheet. Here columns 4 to 6 are made into
named ranges, row 1 is used for the range name
and the rest of the column becomes the range.
#>
[cmdletbinding()]
[Alias("Set-Column")]
[OutputType([OfficeOpenXml.ExcelColumn],[String])]
Param (
#If specifying the worksheet by name, the ExcelPackage object which contains the Sheet also needs to be passed.
#If specifying the worksheet by name, the ExcelPackage object which contains the worksheet also needs to be passed.
[Parameter(ParameterSetName="Package",Mandatory=$true)]
[OfficeOpenXml.ExcelPackage]$ExcelPackage,
#The sheet to update can be a given as a name or an Excel Worksheet object - this sets it by name.
#The sheet to update can be given as a name or an Excel Worksheet object - this sets it by name.
[Parameter(ParameterSetName="Package")]
[String]$Worksheetname = "Sheet1",
#This passes the worksheet object instead of passing a sheet name and a package.
#This passes the worksheet object instead of passing a sheet name and an Excelpackage object.
[Parameter(ParameterSetName="sheet",Mandatory=$true)]
[OfficeOpenXml.ExcelWorksheet]$Worksheet,
#Column to fill down - the first column is 1. 0 will be interpreted as first empty column.
@@ -68,9 +78,9 @@
[Switch]$Italic,
#Underline the text using the underline style in -UnderlineType; use -Underline:$false to remove underlining.
[Switch]$Underline,
#Should Underline use single or double, normal or accounting mode ? the default is single normal.
#Specifies whether underlining should be single or double, normal or accounting mode. The default is "Single".
[OfficeOpenXml.Style.ExcelUnderLineType]$UnderLineType = [OfficeOpenXml.Style.ExcelUnderLineType]::Single,
#Strike through text; use -Strikethru:$false to remove Strike through.
#Strike through text; use -StrikeThru:$false to remove strike through.
[Switch]$StrikeThru,
#Subscript or Superscript (or None).
[OfficeOpenXml.Style.ExcelVerticalAlignmentFont]$FontShift,
@@ -80,32 +90,32 @@
[float]$FontSize,
#Change background color.
[System.Drawing.Color]$BackgroundColor,
#Background pattern - Solid by default.
#Background pattern - "Solid" by default.
[OfficeOpenXml.Style.ExcelFillStyle]$BackgroundPattern = [OfficeOpenXml.Style.ExcelFillStyle]::Solid ,
#Secondary color for background pattern.
[Alias("PatternColour")]
[System.Drawing.Color]$PatternColor,
#Turn on text wrapping; use -WrapText:$false to turn off word wrapping.
#Turn on Text-Wrapping; use -WrapText:$false to turn off wrapping.
[Switch]$WrapText,
#Position cell contents to Left, Right, Center etc. Default is 'General'.
#Position cell contents to Left, Right, Center etc. Default is "General".
[OfficeOpenXml.Style.ExcelHorizontalAlignment]$HorizontalAlignment,
#Position cell contents to Top, Bottom or Center.
[OfficeOpenXml.Style.ExcelVerticalAlignment]$VerticalAlignment,
#Degrees to rotate text. Up to +90 for anti-clockwise ("upwards"), or to -90 for clockwise.
[ValidateRange(-90, 90)]
[int]$TextRotation ,
#Autofit cells to width.
#Attempt to auto-fit cells to the width their contents.
[Alias("AutoFit")]
[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,
#Set the inserted data to be a named range.
[Switch]$AutoNameRange,
#Hide the column.
[Switch]$Hide,
#If Sepecified, returns the range of cells which were affected.
#If specified, returns the range of cells which were affected.
[Switch]$Specified,
#If Specified, return the Column to allow further work to be done on it.
#If specified, return an object representing the Column, to allow further work to be done on it.
[Switch]$PassThru
)