Exporting data to excel with the ImportExcel module with PowerShell

A little demonstration of what you can do with this great module if you need to export your data to MS Excel.

(Check out these posts about the ImportExcel module too.)

$srv = Get-Service

Import-Module importexcel


$myPath = "C:\Temp\Test.xlsx"

Export-Excel -Path $myPath -InputObject $srv -WorksheetName "Services" -MoveToStart -AutoSize



###

$excel = Open-ExcelPackage -Path $myPath

$excel.Workbook.Worksheets.Add("Sheet1")

$mySheet = $excel.Workbook.Worksheets["Sheet1"]

$mySheet.Name = "MyNewSheet"

$mySheet.Cells["A1"].Value = "Test"

$mySheet.Cells[2,1].Value = "Second row, first column"

$excel.Workbook.Worksheets.MoveToStart($mySheet)

$excel.Workbook.Worksheets.Add("Sheet1")


# Set-ExcelColumn -ExcelPackage $excel -WorksheetName $mySheet -Column 1 -AutoSize

$mySheet.Cells.AutoFitColumns()


$myRow = 1


$mySheet = $excel.Workbook.Worksheets["Services"]

Add-ConditionalFormatting -Worksheet $mySheet -Range "D2:D1048576" -RuleType ContainsText -ConditionValue "TRUE" -BackgroundColor Green

# or:

Set-ExcelRow -ExcelPackage $excel -WorksheetName $mySheet -Row $($myRow + 1) -BackgroundColor Yellow



$excel.Save()

Close-ExcelPackage $excel
PowerShell

Examples here:

ImportExcel/mdhelp/en/set-excelcolumn.md at master · roycoutts/ImportExcel · GitHub

To be continued…

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *