Hi
I am Facing one Problem -
I have Ten Columns,in each column if any specific value comes then i want to change the style of that cell.
here is the code which i am using for 5 column, but i am able to change to only 3 columns other two columns style is not changeing
It is Applying only for the FAmily, MemberId, Business Column, not for LastName and FirstName.
Please can any one help meout to solve this problem.
Thanks and regards
Mohammed Irfan
Code :
CellArea CAForW1 = new CellArea();
CAForW1.StartRow = 0;
CAForW1.EndRow = 65535;
CAForW1.StartColumn = 0;
CAForW1.EndColumn = 10;
fcs.AddArea(CAForW1);
int conditionFamily = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, “Family”, “Family”);
int conditionMemberID = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, “Memberid”, “Memberid”);
int conditionBusiness = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, “Business”, “Business”);
int conditionLastName = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, “LastName”, “LastName”);
int conditionFirstName = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, “FirstName”, “FirstName”);
//Sets the background color.
FormatCondition fcFamily = fcs[conditionFamily];
fcFamily.Style.Font.IsBold = true;
fcFamily.Style.BackgroundColor = System.Drawing.Color.Silver;
FormatCondition fcMemberID = fcs[conditionMemberID];
fcMemberID.Style.Font.IsBold = true;
fcMemberID.Style.BackgroundColor = System.Drawing.Color.Silver;
FormatCondition fcBusiness = fcs[conditionBusiness];
fcBusiness.Style.Font.IsBold = true;
fcBusiness.Style.BackgroundColor = System.Drawing.Color.Silver;
FormatCondition fcLastName = fcs[conditionLastName];
fcLastName.Style.Font.IsBold = true;
fcLastName.Style.BackgroundColor = System.Drawing.Color.Silver;
FormatCondition fcFirstName = fcs[conditionFirstName];
fcFirstName.Style.Font.IsBold = true;
fcFirstName.Style.BackgroundColor = System.Drawing.Color.Silver;
Hi Irfan,
Thank you for considering Aspose.
Well, you have to use a separate conditional formatting for all the columns to get your desired result. Please see the sample code as under:
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
//Adds an empty conditional formatting
int index = sheet.ConditionalFormattings.Add();
FormatConditions fcs = sheet.ConditionalFormattings[index];
index = sheet.ConditionalFormattings.Add();
FormatConditions fcs2 = sheet.ConditionalFormattings[index];
index = sheet.ConditionalFormattings.Add();
FormatConditions fcs3 = sheet.ConditionalFormattings[index];
index = sheet.ConditionalFormattings.Add();
FormatConditions fcs4 = sheet.ConditionalFormattings[index];
index = sheet.ConditionalFormattings.Add();
FormatConditions fcs5= sheet.ConditionalFormattings[index];
CellArea CAForW1 = new CellArea();
CAForW1.StartRow = 0;
CAForW1.EndRow = 65535;
CAForW1.StartColumn = 0;
CAForW1.EndColumn = 0;
fcs.AddArea(CAForW1);
CAForW1.StartColumn = 1;
CAForW1.EndColumn = 1;
fcs2.AddArea(CAForW1);
CAForW1.StartColumn = 2;
CAForW1.EndColumn = 2;
fcs3.AddArea(CAForW1);
CAForW1.StartColumn = 3;
CAForW1.EndColumn = 3;
fcs4.AddArea(CAForW1);
CAForW1.StartColumn = 4;
CAForW1.EndColumn = 4;
fcs5.AddArea(CAForW1);
int conditionFamily = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "Family", "Family");
int conditionMemberID = fcs2.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "Memberid", "Memberid");
int conditionBusiness = fcs3.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "Business", "Business");
int conditionLastName = fcs4.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "LastName", "LastName");
int conditionFirstName = fcs5.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "FirstName", "FirstName");
Style style = workbook.Styles[workbook.Styles.Add()];
style.Font.IsBold = true;
style.BackgroundColor = System.Drawing.Color.Silver;
//Sets the background color.
FormatCondition fcFamily = fcs[conditionFamily];
fcFamily.Style = style;
FormatCondition fcMemberID = fcs2[conditionMemberID];
fcMemberID.Style = style;
FormatCondition fcBusiness = fcs3[conditionBusiness];
fcBusiness.Style = style;
FormatCondition fcLastName = fcs4[conditionLastName];
fcLastName.Style = style;
FormatCondition fcFirstName = fcs5[conditionFirstName];
fcFirstName.Style = style;
//Saving the Excel file
workbook.Save("c:\\excels\\Formatting.xls", FileFormatType.Default);
Thank You & Best Regards,
Hi.
Hi,
Aspose.Cells for .NET (Latest Version)
If you still find the issue, kindly give us your sample code and template file(s) to reproduce the issue on our end, we will check it soon.
Hi.
If, you open the report with Office 2010 I worked fine.
wb.Save(HttpContext.Current.Response, fileName + ".xlsx", ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Xlsx));
It should be like following if you are saving to XLSX format:
wb.Save(HttpContext.Current.Response, fileName + ".xlsx", ContentDisposition.Attachment, new OoxmlSaveOptions());
Hi.
Hi,
Hi,