diff --git a/Export-Excel.ps1 b/Export-Excel.ps1 index cea61c2..ca86ed2 100644 --- a/Export-Excel.ps1 +++ b/Export-Excel.ps1 @@ -381,6 +381,16 @@ 0..360 | ForEach-Object {[pscustomobject][ordered]@{X=$_; Sinx="=Sin(Radians(x)) "} } | Export-Excel -now -LineChart -AutoNameRange Creates a line chart showing the value of Sine(x) for values of X between 0 and 360 degrees. + + .EXAMPLE + > + PS> Invoke-Sqlcmd -ServerInstance localhost\DEFAULT -Database AdventureWorks2014 -Query "select * from sys.tables" -OutputAs DataRows | + Export-Excel -Path .\SysTables_AdventureWorks2014.xlsx -WorksheetName Tables + + Runs a query against a SQL Server database and outputs the resulting rows DataRows using the -OutputAs parameter. + The results are then piped to the Export-Excel function. + NOTE: You need to install the SqlServer module from the PowerShell Gallery in oder to get the -OutputAs parameter for the Invoke-Sqlcmd cmdlet. + .LINK https://github.com/dfinke/ImportExcel #> diff --git a/ImportExcel.psm1 b/ImportExcel.psm1 index a2c9821..ed889d1 100644 --- a/ImportExcel.psm1 +++ b/ImportExcel.psm1 @@ -221,7 +221,7 @@ function Import-Excel { Notice that empty rows and empty columns are not imported. -.EXAMPLE + .EXAMPLE Import data from an Excel worksheet. One object is created for each row. The property names are provided with the ‘-HeaderName’ parameter. The import will start from row 2 and empty columns and rows are not imported. ---------------------------------------------------------- @@ -241,6 +241,16 @@ function Import-Excel { Notice that only 1 object is imported with only 3 properties. Column B and row 2 are empty and have been disregarded by using the switch '-DataOnly'. The property names have been named with the values provided with the parameter '-HeaderName'. Row number 1 with ‘Chuck Norris’ has not been imported, because we started the import from row 2 with the parameter ‘-StartRow 2’. + .EXAMPLE + > + PS> ,(Import-Excel -Path .\SysTables_AdventureWorks2014.xlsx) | + Write-SqlTableData -ServerInstance localhost\DEFAULT -Database BlankDB -SchemaName dbo -TableName MyNewTable_fromExcel -Force + + Imports data from an Excel file and pipe the data to the Write-SqlTableData to be INSERTed into a table in a SQL Server database. + The ",( ... )" around the Import-Excel command allows all rows to be imported from the Excel file, prior to pipelining to the Write-SqlTableData cmdlet. This helps prevent a RBAR scenario and is important when trying to import thousands of rows. + The -Force parameter will be ignored if the table already exists. However, if a table is not found that matches the values provided by -SchemaName and -TableName parameters, it will create a new table in SQL Server database. The Write-SqlTableData cmdlet will inherit the column names & datatypes for the new table from the object being piped in. + NOTE: You need to install the SqlServer module from the PowerShell Gallery in oder to get the Write-SqlTableData cmdlet. + .LINK https://github.com/dfinke/ImportExcel