Skip to content

ISheet.SetDefaultColumnStyle not applied to new cells #976

@Xriuk

Description

@Xriuk

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:

var sheet = workbook.CreateSheet(sheetName);

// Create header
var rowIndex = 0;
var columnIndex = 0;
var properties = entityType.GetPropertiesOrdered();
var row = sheet.CreateRow(rowIndex++);
foreach (var property in properties) {
  var cell = row.CreateCell(columnIndex);
  cell.CellStyle = (...);
  cell.SetCellValue(property.Name);
  
  sheet.SetDefaultColumnStyle(columnIndex, styles.Default); // Here I set the default style
  
  columnIndex++;
}

// Populate rows
foreach (var dataRow in rows) {
  row = sheet.CreateRow(rowIndex++);
  columnIndex = 0;
  foreach (var property in properties) {
    var cell = row.CreateCell(columnIndex++);

    //cell.CellStyle = styles.Default;

    cell.SetCellValue(...);
  }
}

workbook.Write(..., true);

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions