Excel 2007使用SetDefaultColumnStyle设置列样式无法正常生效,需要设置任意样式后,使用GetColumnStyle获取到列样式,然后再修改该样式才能生效,代码描述如下:
```
var columnIndex = i + startColumnIndex;
SetColumnWidth(sheet, columnIndex, headers[i].ColumnWidth);
ICellStyle columnStyle = sheet.Workbook.CreateCellStyle();
sheet.SetDefaultColumnStyle(columnIndex, columnStyle);
columnStyle = sheet.GetColumnStyle(columnIndex);
SetColumnDefaultStyle(sheet.Workbook, columnStyle);
SetCellStyleHorizontalAlignment(columnStyle, headers[i].HorizontalAlignment);
SetCellStyleDataFormat(sheet.Workbook, columnStyle, headers[i].DataFormat);
```
设置列样式之后,创建的新单元格,不设置单元格样式,单元格无法按所在列的列样式进行显示,需要进行再次设置(2003无改问题),代码描述如下:
```
ICell cell = sheetRow.CreateCell(cellIndex);
cell.CellStyle = sheet.GetColumnStyle(cellIndex);
```
```
var columnIndex = i + startColumnIndex;
SetColumnWidth(sheet, columnIndex, headers[i].ColumnWidth);
ICellStyle columnStyle = sheet.Workbook.CreateCellStyle();
sheet.SetDefaultColumnStyle(columnIndex, columnStyle);
columnStyle = sheet.GetColumnStyle(columnIndex);
SetColumnDefaultStyle(sheet.Workbook, columnStyle);
SetCellStyleHorizontalAlignment(columnStyle, headers[i].HorizontalAlignment);
SetCellStyleDataFormat(sheet.Workbook, columnStyle, headers[i].DataFormat);
```
设置列样式之后,创建的新单元格,不设置单元格样式,单元格无法按所在列的列样式进行显示,需要进行再次设置(2003无改问题),代码描述如下:
```
ICell cell = sheetRow.CreateCell(cellIndex);
cell.CellStyle = sheet.GetColumnStyle(cellIndex);
```