Hello.
I have two questions, but first a short description of what I'm trying to do.
I try to change existing Worksheets with my application. One of my functions deletes columns. To remove a column I remove all cells in this column row by row and shift the Column Styles from my column index+1 to the last column index by 1 to the left.
To shift a Column Style I first tried the following code.
My solution is the following code.
So, my questions are. Is it possible to set remove/delete the style of a column and row? Is it possible to get the index of the last column with a column style? (since this must not be the same as the last column with content)
I hope you can help me with this problem.
Best regards,
Herbie
I have two questions, but first a short description of what I'm trying to do.
I try to change existing Worksheets with my application. One of my functions deletes columns. To remove a column I remove all cells in this column row by row and shift the Column Styles from my column index+1 to the last column index by 1 to the left.
To shift a Column Style I first tried the following code.
ICellStyle columnStyle = sheet.GetColumnStyle(columnIndex + 1);
sheet.SetDefaultColumnStyle(columnIndex, columnStyle);
This only worked if the column at columnIndex+1 had a column style set. Otherwise GetColumnStyle returns null and SetDefaultColumnStyle seems not to accept this value, since I got a NullReferenceException.My solution is the following code.
ICellStyle columnStyle = sheet.GetColumnStyle(columnIndex + 1);
if (columnStyle != null)
sheet.SetDefaultColumnStyle(columnIndex, columnStyle);
else
sheet.SetDefaultColumnStyle(columnIndex, sheet.Workbook.CreateCellStyle());
The result generally looks like I've expected, but when I now callcolumnStyle = sheet.GetColumnStyle(columnIndex);
columnStyle is not null even if the right-hand columns style is null.So, my questions are. Is it possible to set remove/delete the style of a column and row? Is it possible to get the index of the last column with a column style? (since this must not be the same as the last column with content)
I hope you can help me with this problem.
Best regards,
Herbie