Vb.net 创建电子表格,并使用NPOI库创建具有彩色背景的单元格
我正在尝试使用NPOI库从vb.net应用程序创建Excel电子表格。我正在使用以下代码:Vb.net 创建电子表格,并使用NPOI库创建具有彩色背景的单元格,vb.net,excel,npoi,Vb.net,Excel,Npoi,我正在尝试使用NPOI库从vb.net应用程序创建Excel电子表格。我正在使用以下代码: Imports NPOI.HSSF.UserModel Imports NPOI.SS.UserModel Imports NPOI.SS.Util Imports NPOI.HSSF.Util Imports NPOI.POIFS.FileSystem Imports NPOI.HPSF Imports NPOI.HSSF.Util.HSSFColor 'create a background col
Imports NPOI.HSSF.UserModel
Imports NPOI.SS.UserModel
Imports NPOI.SS.Util
Imports NPOI.HSSF.Util
Imports NPOI.POIFS.FileSystem
Imports NPOI.HPSF
Imports NPOI.HSSF.Util.HSSFColor
'create a background color of red
Dim styleCellRedBackGround As HSSFCellStyle = workbook.CreateCellStyle()
styleCellRedBackGround.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.RED.index
Dim styleCellRedBackGroundFont = workbook.CreateFont()
styleCellRedBackGroundFont.FontName = "Red Background"
styleCellRedBackGround.SetFont(styleCellRedBackGroundFont)
row = sheet.CreateRow(2)
cell = row.CreateCell(0)
cell.CellStyle = styleCellRedBackGround
cell.SetCellValue("<<COMPETITIVE REBATES>>")
将创建电子表格,但单元格没有红色背景。如果我创建了一个单元格并指定了红色背景,但没有向该单元格写入任何内容,这似乎是可行的。关于如何做到这一点,似乎只有有限的文档。有什么建议吗
谢谢请设置styleCellRedBackGround.FillPattern=FillPattern.SOLID 您可能希望在现有电子表格中创建样式,使用NPOI打开它,然后查看CellStyle是如何定义的。这样,您就可以从您想要的东西开始,并从那里创建相应的代码