Hello experts,
So, i have a template that i edit with c# to insert some data from a database.
On a specific cell i'm apllying a style that comes with the template using it's styleIndex, and associating it to the cell.
The problem is all the specific style formats of the associated styleIndex are apllied (font color, font size, font, etc..) except for the wrap text.
Only if i click on the style, or hover over other style, on the opened excel sheet the wrap text is applied.
The code to update the cell is the following:
Cell cell = GetCell(worksheetPart.Worksheet,
columnName, rowIndex);
cell.CellValue = new CellValue(text);
cell.DataType =
new EnumValue<CellValues>(CellValues.String);
if (styleIndex > 0)
cell.StyleIndex = styleIndex.Value;
// Save the worksheet.
worksheetPart.Worksheet.Save();
I know that i'm applying the right styleIndex because i see it when i open the excel. The Wrap text for the cell is also enabled, but it's like the cell is not updated, i have to force it by clicking again on the style.
below is the code to create the excel from template
using (SpreadsheetDocument excelDocument =
SpreadsheetDocument.Open(s, true))
{
SheetData sheetData = new SheetData();
Sheet sheet = excelDocument.WorkbookPart.Workbook.Descendants<Sheet>().Last();
var propRef = entityData["Reference"].ToString();
sheet.Name = propRef;
WorksheetPart worksheetPart = GetWorksheetPartByName(excelDocument, propRef);
// args[WorksheetPart, String, Row, Column, StyleIndex]
UpdateCell(worksheetPart, "Some text", 12, "B", 40);
excelDocument.WorkbookPart.WorkbookStylesPart.Stylesheet.Save();
}
Best regards,
johny