I am not able to change the text color of the row using style.Font.color property .
Style boldStyle = planWorkBook.CreateStyle();
//Code to change the background color
boldStyle.ForegroundColor = System.Drawing.Color.Blue;
boldStyle.Pattern = BackgroundType.Solid;
//code to change the text color
boldStyle.Font.Color = System.Drawing.Color.White;
boldStyle.Font.IsBold = false;
boldStyle.HorizontalAlignment = TextAlignmentType.Left;
Background change code is working however the text change code is not working.
please help.
How do you apply style to the cell/row/range, i think you are missing this thing. See the updated code segment (I have added a few lines to your code segment) for your reference:
e.g Sample code:
Workbook planWorkBook = new Workbook();
Style boldStyle = planWorkBook.CreateStyle();
//Code to change the background color
boldStyle.ForegroundColor = System.Drawing.Color.Blue;
boldStyle.Pattern = BackgroundType.Solid;
//code to change the text color
boldStyle.Font.Color = System.Drawing.Color.White;
boldStyle.Font.IsBold = false;
boldStyle.HorizontalAlignment = TextAlignmentType.Left;
StyleFlag flag1 = new StyleFlag();
flag1.CellShading = true;
flag1.Font = true;
flag1.HorizontalAlignment = true;
//Apply the style to the first row of the first sheet.
Worksheet worksheet = planWorkBook.Worksheets[0];
worksheet.Cells.ApplyRowStyle(0, boldStyle, flag1);
//Apply the style to the A9 cell.
worksheet.Cells["A9"].SetStyle(boldStyle, flag1);
Also, see the document for your further reference:
I used the following sample code with our latest version/fix: Aspose.Cells for .NET v18.5.x, it works fine:
e.g Sample code:
Workbook planWorkBook = new Workbook();
Style boldStyle = planWorkBook.CreateStyle();
//Code to change the background color
boldStyle.ForegroundColor = System.Drawing.Color.Blue;
boldStyle.Pattern = BackgroundType.Solid;
//code to change the text color
boldStyle.Font.Color = System.Drawing.Color.White;
boldStyle.Font.IsBold = false;
boldStyle.HorizontalAlignment = TextAlignmentType.Left;
StyleFlag flag1 = new StyleFlag();
flag1.CellShading = true;
flag1.Font = true;
flag1.HorizontalAlignment = true;
Worksheet worksheet = planWorkBook.Worksheets[0];
worksheet.Cells["A1"].PutValue("testin...");
worksheet.Cells["A9"].PutValue("hello");
//Apply the style to the first row of the first sheet.
worksheet.Cells.ApplyRowStyle(0, boldStyle, flag1);
//Apply the style to the A9 cell.
worksheet.Cells["A9"].SetStyle(boldStyle, flag1);
planWorkBook.Save("e:\\test2\\out1.xlsx");
I have also attached the output file for your reference.
Since you are using some older version of the product, so we are not sure if it was working or not. But it works absolutely fine using latest version/fix. Moreover, we neither can evaluate your issue in older version nor we can fix any issue (if found). The fixes are based on latest APIs set. files1.zip (6.3 KB)