Excel电子表格到色单元的一整列下面是我使用色单元在Excel文件中使用NPOI C#程序:尝试使用NPOI
string pathSource = @"C:\Users\mvmurthy\Downloads\VOExportTemplate (2).xlsx";
HSSFWorkbook templateWorkbook;
HSSFSheet sheet;
HSSFRow dataRow;
using (var fs = new FileStream(pathSource, FileMode.Open, FileAccess.ReadWrite))
{
templateWorkbook = new HSSFWorkbook(fs, true);
sheet = (HSSFSheet)templateWorkbook.GetSheet("ImportTemplate");
int num = sheet.PhysicalNumberOfRows;
for (int i=1; i<num; i++)
{
dataRow = (HSSFRow)sheet.GetRow(i);
HSSFCellStyle hStyle = (HSSFCellStyle)templateWorkbook.CreateCellStyle();
hStyle = (HSSFCellStyle)templateWorkbook.CreateCellStyle();
hStyle.FillForegroundColor = IndexedColors.Red.Index;
hStyle.FillPattern = FillPattern.SolidForeground;
dataRow.Cells[9].CellStyle = hStyle;
}
}
using (var fs = new FileStream(pathSource, FileMode.Open, FileAccess.ReadWrite))
{
templateWorkbook.Write(fs);
}
当运行上述代码我正在以下的输出,但我要的颜色仅列K:
我在做什么错?