Hello.
I'm new to NPOI and if I misunderstand something please correct me. I want to write a test application which opens an existing Excel Workbook (created by Excel 2007 or 2010 in 97-2003 xls Format) and removes the column style of column index 4. The first sheet in the Workbook includes several columns formatted in different value formats like Date and Text and different cell colors.
The only function I've found to set a column style was SetDefaultColumnStyle of ISheet.
Here is the code:
```
IWorkbook wb;
ISheet ws;
using (FileStream file = new FileStream(@"..\..\..\Test\Test_Table.xls", FileMode.Open, FileAccess.Read))
{
wb = new HSSFWorkbook(file);
}
ws = wb.GetSheetAt(0);
ws.SetDefaultColumnStyle(4, wb.CreateCellStyle());
using (FileStream file = new FileStream(@"..\..\..\Test\Test_Table_result.xls", FileMode.Create, FileAccess.Write))
{
wb.Write(file);
}
```
For the column E the call of SetDefaultColumnStyle works as expected. But the Colors of the cells in the other columns change. When I compare the original file with the file created by NPOI some of the cell colors are changed.
The description of SetDefaultColumnStyle says "Sets the default column style for a given column. POI will only apply this style to new cells Added to the sheet.". So this function should have no influence on any cell which already has its own cell style, didn't it? From my Point of view is a bug.
To proof that the color change is not a General Problem I also opened the workbook and saved it without changes. The resulting file is smaller than the original Excel file but the content and the formatting keeps the same. So, the Color change of the cells must have something to do with the call to SetDefaultColumnStyle.
It would be great if someone could tell me if there is another possibility to remove the default column style from a column, which does not affect the existing cell styles of the sheet. Furthermore, I hope that this behavior can be fixed in the next stable release of NPOI.
My testing workbook is attatched.
Best regards
Herbie
I'm new to NPOI and if I misunderstand something please correct me. I want to write a test application which opens an existing Excel Workbook (created by Excel 2007 or 2010 in 97-2003 xls Format) and removes the column style of column index 4. The first sheet in the Workbook includes several columns formatted in different value formats like Date and Text and different cell colors.
The only function I've found to set a column style was SetDefaultColumnStyle of ISheet.
Here is the code:
```
IWorkbook wb;
ISheet ws;
using (FileStream file = new FileStream(@"..\..\..\Test\Test_Table.xls", FileMode.Open, FileAccess.Read))
{
wb = new HSSFWorkbook(file);
}
ws = wb.GetSheetAt(0);
ws.SetDefaultColumnStyle(4, wb.CreateCellStyle());
using (FileStream file = new FileStream(@"..\..\..\Test\Test_Table_result.xls", FileMode.Create, FileAccess.Write))
{
wb.Write(file);
}
```
For the column E the call of SetDefaultColumnStyle works as expected. But the Colors of the cells in the other columns change. When I compare the original file with the file created by NPOI some of the cell colors are changed.
The description of SetDefaultColumnStyle says "Sets the default column style for a given column. POI will only apply this style to new cells Added to the sheet.". So this function should have no influence on any cell which already has its own cell style, didn't it? From my Point of view is a bug.
To proof that the color change is not a General Problem I also opened the workbook and saved it without changes. The resulting file is smaller than the original Excel file but the content and the formatting keeps the same. So, the Color change of the cells must have something to do with the call to SetDefaultColumnStyle.
It would be great if someone could tell me if there is another possibility to remove the default column style from a column, which does not affect the existing cell styles of the sheet. Furthermore, I hope that this behavior can be fixed in the next stable release of NPOI.
My testing workbook is attatched.
Best regards
Herbie