Open Xriuk opened 1 year ago
Is this file xlsx?
Is this file xlsx?
Yep
It doesn't work at all on column level:
// Create a new workbook
var workbook = new XSSFWorkbook();
// Create a new sheet
var sheet = workbook.CreateSheet("gridExport_0");
//// Create a style for the rows
var style = workbook.CreateCellStyle();
// Create a solid foreground fill
style.FillPattern = FillPattern.SolidForeground;
style.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.SkyBlue.Index; // Set the foreground color
style.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.Black.Index; // Set the background color
var datetimeStyle = workbook.CreateCellStyle();
var dataformat = workbook.CreateDataFormat();
datetimeStyle.DataFormat = dataformat.GetFormat("yyyy-MM-dd HH:mm:ss");
// Applying the style to the first row (index 0)
sheet.SetDefaultColumnStyle(0, datetimeStyle);
sheet.SetDefaultColumnStyle(1, datetimeStyle);
var row = sheet.CreateRow(0);
row.RowStyle = style;
var cell = row.CreateCell(0);
cell.SetCellType(CellType.String);
cell.SetCellValue("date1");
cell = row.CreateCell(1);
sheet.SetDefaultColumnStyle(1, datetimeStyle);
cell.SetCellType(CellType.String);
cell.SetCellValue("Date2");
row = sheet.CreateRow(1);
cell = row.CreateCell(0);
cell.SetCellType(CellType.Numeric);
cell.SetCellValue(DateTime.UtcNow);
cell = row.CreateCell(1);
sheet.SetDefaultColumnStyle(1, datetimeStyle);
cell.SetCellType(CellType.Numeric);
cell.SetCellValue(DateTime.UtcNow);
//cell.CellStyle = datetimeStyle;
//create file
using var file = new FileStream("/app/test.xlsx", FileMode.Create, FileAccess.Write);
workbook.Write(file);
https://github.com/apache/poi/pull/406 PR should be applied too, because fix in https://github.com/apache/poi/pull/338 cause performance issue
I have met same trouble,Is this bug fixed in 2.7.1?
I have met same trouble,Is this bug fixed in 2.7.1?
HI, unfortunately, no. I've tried to create a PR, but some of the tests are failing. You can contribute if you wish: https://github.com/nissl-lab/npoi/pull/1340
Hi, I'm creating a new sheet with a header row and then the data, I'm trying to apply default style to the whole column, so all the rows after the header will have the same style.
Here's my code:
But this way the cells are not styled, if I instead apply the style manually (by uncommenting the code above) to all the cells then it works.