using NPOI.XSSF.UserModel;
using NPOI.XSSF.Model;
using NPOI.HSSF.UserModel;
using NPOI.HSSF.Model;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
(...)
XSSFWorkbook hssfwb;
using (FileStream file = new FileStream(@"D:\VB\XLSX teste com NPOI\XLSX 1\Book1.xlsx",
FileMode.Open, FileAccess.Read))
{
hssfwb = new XSSFWorkbook(file);
file.Close();
}
ISheet sheet = hssfwb.GetSheetAt(0);
IRow row = sheet.GetRow(0);
ICell cell = row.CreateCell(5);
cell.SetCellValue("test");
cell.CellStyle.FillBackgroundColor = IndexedColors.BrightGreen.Index;
cell.CellStyle.FillPattern = FillPattern.SolidForeground;
using (FileStream file = new FileStream(@"D:\VB\XLSX teste com NPOI\XLSX 1\Book1ee22.xlsx",
FileMode.Create, FileAccess.Write))
{
hssfwb.Write(file);
file.Close();
}
Versione di NPOI: 2.1.3.1 Ho questo codice e sta cambiando il colore per il foglio di buco e non solo la cella di ... Qual è il modo corretto di cambiare il colore di riempimento della cella?Come cambiare il colore delle celle con NPOI
Ecco il codice di lavoro, in base alla risposta che viene contrassegnata come corretta di seguito:
XSSFWorkbook hssfwb;
using (FileStream file = new FileStream(@"D:\Copy D\Tech\VB\XLSX teste com NPOI\XLSX 1\Book1.xlsx", FileMode.Open, FileAccess.Read))
{
hssfwb = new XSSFWorkbook(file);
file.Close();
}
ISheet sheet = hssfwb.GetSheetAt(0);
IRow row = sheet.GetRow(0);
ICellStyle testeStyle = hssfwb.CreateCellStyle();
testeStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Medium;
testeStyle.FillForegroundColor = IndexedColors.BrightGreen.Index;
testeStyle.FillPattern = FillPattern.SolidForeground;
ICell cell = row.CreateCell(5);
cell.SetCellValue("testeeerere");
cell.CellStyle = testeStyle;
using (FileStream file = new FileStream(@"D:\Copy D\Tech\VB\XLSX teste com NPOI\XLSX 1\Book1ee22.xlsx", FileMode.Create, FileAccess.Write))
{
hssfwb.Write(file);
file.Close();
}
Non riesco a dichiarare un CellStyle .. – meme
CellStyle è nello spazio dei nomi 'NPOI.SS.UserModel'. Ho modificato la mia risposta. – Nino
ancora non posso dichiararlo. aggiunte le importazioni alla domanda – meme