Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
205
Apply style to all Cells in excel
posted

Hi,

I need to apply font size and wrap text as true to all cells in a given worksheet, as we have worksheet.cells.Fontsize and worksheet.cells.wraptext in interop to do this

How can we do this using infragistics, if not possible please mention any alternative so that this can be achived.

Thanks

  • 44743
    posted

    This is currently not possible to set at the worksheet level. You can submit a feature request for this. Currently, the fastest and most memory efficient way I can think of to do this would be to loop over all column and set these properties at the column level:

    Workbook workbook = new Workbook();
    Worksheet worksheet = workbook.Worksheets.Add("Sheet1");
     
    IWorksheetCellFormat columnFormat = workbook.CreateNewWorksheetCellFormat();
    columnFormat.Font.Height = 400;
    columnFormat.WrapText = ExcelDefaultableBoolean.True;
     
    int maxColumnCount = Workbook.GetMaxColumnCount(workbook.CurrentFormat);
    for (int i = 0; i < maxColumnCount - 1; i++)
    	worksheet.Columns[i].CellFormat.SetFormatting(columnFormat);
     
    workbook.Save("Book1.xls");