-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ISheet.SetDefaultColumnStyle not applied to new cells #976
Comments
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); |
apache/poi#406 PR should be applied too, because fix in apache/poi#338 cause performance issue |
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: #1340 |
That PR was closed, is there a reason? Has a fix already been applied by another PR 🤞 |
There was an issue with failing unit tests, help is appreciated |
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.
The text was updated successfully, but these errors were encountered: