We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Creating a workbook using a pre-made template - Styles

Hello, I''m having an issue where we create an IWorkbook from a template (xlt) using the following code: ----- public static IWorkbook CreateNewWorkbook() { RegistryKey key = Registry.CurrentUser.OpenSubKey( @"SOFTWARE\TAG" ); string reportTemplate = key.GetValue( "Report Template" ).ToString(); return CreateNewWorkbook( reportTemplate ); } .... IWorksheet sheet = workBook.Worksheets[ 0 ]; sheet.Range[ 1, 1, 1, 5 ].Text = "Column"; sheet.Range[ 1, 1, 1, 5 ].CellStyleName = "ColumnHeader"; ----- This template has pre-made styles in it. My issue is that if that style is not actively used in a cell when the template is loaded, the following error occurs when trying to assign that pre-made style to a cell. "Style with specified name does not exists. Name: ColumnHeader". If I assign cell A1 the style ColumnHeader inside the template file and then do this, all is well. It seems that when the IWorkbook is created, it only loads those styles that are actively being used. I tried to attach the Excel template but it seems the file attachment form is not working. I will be more than happy to email the template if an address is provided. Any comments would be appreciated. Thanks!

1 Reply

AD Administrator Syncfusion Team February 9, 2005 02:40 PM UTC

Hi Shannon, Please send the file to stephenj @ syncfusion.com Thanks, Stephen. >Hello, I''m having an issue where we create an IWorkbook from a template (xlt) using the following code: >----- > public static IWorkbook CreateNewWorkbook() > { > RegistryKey key = Registry.CurrentUser.OpenSubKey( @"SOFTWARE\TAG" ); > > string reportTemplate = key.GetValue( "Report Template" ).ToString(); > > return CreateNewWorkbook( reportTemplate ); > } >.... > > IWorksheet sheet = workBook.Worksheets[ 0 ]; > sheet.Range[ 1, 1, 1, 5 ].Text = "Column"; > sheet.Range[ 1, 1, 1, 5 ].CellStyleName = "ColumnHeader"; > >----- >This template has pre-made styles in it. My issue is that if that style is not actively used in a cell when the template is loaded, the following error occurs when trying to assign that pre-made style to a cell. "Style with specified name does not exists. Name: ColumnHeader". > >If I assign cell A1 the style ColumnHeader inside the template file and then do this, all is well. It seems that when the IWorkbook is created, it only loads those styles that are actively being used. > >I tried to attach the Excel template but it seems the file attachment form is not working. I will be more than happy to email the template if an address is provided. > >Any comments would be appreciated. >Thanks! >

Loader.
Live Chat Icon For mobile
Up arrow icon