Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 创建电子表格,并使用NPOI库创建具有彩色背景的单元格_Vb.net_Excel_Npoi - Fatal编程技术网

Vb.net 创建电子表格,并使用NPOI库创建具有彩色背景的单元格

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

我正在尝试使用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 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是如何定义的。这样,您就可以从您想要的东西开始,并从那里创建相应的代码