Unplanned
Last Updated: 17 Apr 2019 14:21 by ADMIN
ADMIN
Marin Bratanov
Created on: 26 Dec 2017 14:31
Category: Spreadsheet
Type: Bug Report
1
Default font size is not saved and loaded to/from Excel

The default font size on the client is not saved explicitly on the Excel file, so the Excel defaults take over (11px Calibri), so upon subsequent import all cells will have that font. Steps to repro: go to https://demos.telerik.com/aspnet-ajax/spreadsheet/examples/import-export/defaultcs.aspx export the file import the file Expected: nothing changes Actual: all cells are 11px Calibri

Workaround: Set a default font when the cell font is null

 

public override void SaveWorkbook(Workbook workbook)
{
    string path = "C:\\path-to-output.xlsx";
     
    for (int i = 0; i < workbook.Sheets.Count; i++)
    {
        for (int j = 0; j < workbook.Sheets[i].Rows.Count; j++)
        {
            for (int l = 0; l < workbook.Sheets[i].Rows[i].Cells.Count; l++)
            {
                string fontFamily = workbook.Sheets[i].Rows[i].Cells[l].FontFamily;
                workbook.Sheets[i].Rows[i].Cells[l].FontFamily = !string.IsNullOrEmpty(fontFamily) ? fontFamily : "Courier New";
 
                double? fontSize = workbook.Sheets[i].Rows[i].Cells[l].FontSize;
                workbook.Sheets[i].Rows[i].Cells[l].FontSize = fontSize.HasValue ? fontSize : 12;
            }
        }
    }
    workbook.Save(path);
}

 

0 comments