Add-WorkSheet Not Working
Here is my code:
$sql = @' SELECT s.BusinessEntityID ,p.FirstName ,p.PersonType ,s.Bonus
FROM [AdventureWorks2017].[Sales].[SalesPerson] s INNER JOIN [AdventureWorks2017].[Person].[Person] p ON p.BusinessEntityID = s.BusinessEntityID '@
$FilePath = "D:/test/test.xlsx"
$x1 = Invoke-Sqlcmd -ServerInstance localhost -Database "AdventureWorks2017" -Query $sql | Export-Excel $FilePath -AutoSize -ExcludeProperty HasErrors, RowError, RowState, Table, ItemArray $excel = Open-ExcelPackage $FilePath $ws = Add-WorkSheet -WorksheetName "Summary" -ExcelPackage $excel
Can you help check what is lacking in my code? I try to run each one of the functions but it is not working.
Did you close the package after adding the worksheet ?
Hi @jhoneill. I am new into this module. I have a working export-excel from a query the challenge is I need to create another sheet where I need to put the result of my second query. Can you guide me on how to properly do it?
Ah , OK, easier than you might think
Invoke-Sqlcmd <<SQL1>> | Export-Excel $FilePath -worksheetName "Query1" <<other options>>
Invoke-Sqlcmd <<SQL2>> | Export-Excel $FilePath -worksheetName "Query2" <<other options>>
@jhoneill its easy now. Thanks for this. I thought there are bunch of code I need to run.