EvotecIT / PSWriteExcel

PSWriteExcel is very basic (at the moment) PowerShell module to create Microsoft Excel workbooks without Microsoft Excel installed.
61 stars 12 forks source link

Set-ExcelWorkSheetCellStyleFont doesn't work to change the color of a cell #8

Closed GiriSudh closed 4 years ago

GiriSudh commented 4 years ago

Following code gives error : Set-ExcelWorkSheetCellStyleFont -ExcelWorksheet $ExcelWorkSheet -CellRow 2 -CellColumn 3 -Bold $True -Family 3 -Size 20 -Color Red

Set-ExcelWorkSheetCellStyleFont : Cannot process argument transformation on parameter 'Color'. Cannot convert the "Red" value of type "System.String" to type "System.Nullable". At line:24 char:129

PrzemyslawKlys commented 4 years ago

I've rewritten the cmdlet.

This example works now. You need to update pswriteexcel to new version.

$FilePath = "$Env:USERPROFILE\Desktop\PSWriteExcel-Example-SetExcelWorkSheetCell.xlsx"

$Excel = New-ExcelDocument -Verbose

$ExcelWorkSheet = Add-ExcelWorkSheet -ExcelDocument $Excel -WorksheetName 'Test 1' -Suppress $False -Option 'Replace'

$myitems0 = @(
    [pscustomobject]@{name = "Joe"; age = 32; info = "Cat lover" },
    [pscustomobject]@{name = "Sue"; age = 29; info = "Dog lover" },
    [pscustomobject]@{name = "Jason another one"; age = 42; info = "Food lover"
    }
)
Add-ExcelWorksheetData -ExcelWorksheet $ExcelWorkSheet -DataTable $myitems0 -AutoFit -AutoFilter -Suppress $True

Set-ExcelWorkSheetCellStyle -ExcelWorksheet $ExcelWorkSheet -CellRow 1 -CellColumn 2 -Name 'Arial' -Size 20 -Color Red -Bold -Italic -UnderLine -UnderLineType Double

Save-ExcelDocument -ExcelDocument $Excel -FilePath $FilePath -OpenWorkBook