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.
Unfortunately, activation email could not send to your email. Please try again.

copying global styles

Thread ID:

Created:

Updated:

Platform:

Replies:

65223 Jul 25,2007 10:31 AM Jul 26,2007 01:05 PM ASP.NET Web Forms (Classic) 2
loading
Tags: XlsIO
Greg
Asked On July 25, 2007 10:31 AM

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

Ajish [Syncfusion]
Replied On July 25, 2007 02:06 PM

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.

Greg
Replied On July 26, 2007 01:05 PM

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

Thanks,
Greg

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;