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

copying global styles

Is there a way to copy the style settings from one global style to another without actually making them point to the same style. Here is the code I am using:
IStyle tableHeader = workbook.Styles.Add("TableHeader");
tableHeader.Color = Color.FromName("Blue");
tableHeader.Font.RGBColor = Color.FromName("White");
tableHeader.Font.Bold = true;
tableHeader.HorizontalAlignment = ExcelHAlign.HAlignCenter;
tableHeader.Borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Thick;
tableHeader.Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thin;

IStyle rowHeader = tableHeader;
rowHeader.Borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.None;

I want the rowHeader to be exactly the same as the tableHeader except without the top border. This code works except the last line removes the top border from both the rowHeader and tableHeader styles, which I don't want. Is there an easy way to do this or am I just going to have to rewrite all the style information for the second style?

Thanks,
Greg

2 Replies

AJ Ajish Syncfusion Team July 25, 2007 06:06 PM UTC

Hi Greg,

It is not necessary to rewrite the style information for the second style. You can create a style based on other style using the following method,

IStyle rowHeader = myWorkbook.Styles.Add("rowHeader", tableHeader);

which creates rowHeader Style based on the tableHeader style. The following code has been modified to fit your requirement,

//Define a style
IStyle tableHeader = myWorkbook.Styles.Add("TableHeader");
tableHeader.Color = Color.FromName("Blue");
tableHeader.Font.RGBColor = Color.FromName("White");
tableHeader.Font.Bold = true;
tableHeader.HorizontalAlignment = ExcelHAlign.HAlignCenter;
tableHeader.Borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Thick;
tableHeader.Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thin;

IStyle rowHeader = myWorkbook.Styles.Add("rowHeader", tableHeader);
rowHeader.Borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.None;

and here is a sample for your reference

Sample: http://websamples.syncfusion.com/samples/XlsIO.Windows/F65223/main.htm

Kindly take a look and let me know if this helps.

Regards,
Ajish.


GR Greg July 26, 2007 05:05 PM UTC

I just tried the code and it works well. This is exactly what I was looking for.

Thanks,
Greg

Loader.
Live Chat Icon For mobile
Up arrow icon