我正在使用 EPPlus 创建 Excel 文档。它正在工作,但我无法更改单元格的背景颜色。我使用以下代码:
Worksheet.Cells[row,column].Style.Fill.BackgroundColor.rgb = (255,0,0)
每次我执行脚本时,它都会说:
“rgb”是只读属性
当我尝试设置
Worksheet.Cells.Style.Fill.BackgroundColor = xxx
我犯了同样的错误:
“BackgroundColor”是只读属性
我没有找到更多选项,您可以在其中更改颜色或将属性更改为可写...有没有人有想法?
试试我的 PowerShell Excel 模块,它封装了 EPPlus 并使交互变得非常简单。
https://www.powershellgallery.com/packages/ImportExcel/
$xlfile = "$env:TEMP\test.xlsx"
rm $xlfile -ErrorAction Ignore
$pkg = ps | select company, Handles| Export-Excel $xlfile -PassThru
$ws = $pkg.Workbook.Worksheets["Sheet1"]
Set-Format -WorkSheet $ws -Range "B2:B2" -BackgroundColor Red
Set-Format -WorkSheet $ws -Range "B5:B5" -BackgroundColor Green
Close-ExcelPackage $pkg -Show
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句