To further inform you, the chart color issue in generated xls (Excel 2003) file is because chart in your template xlsx file contain colors which are not in excel 2003 palette, so these colors will get lost if you save the file to xls format.
Also, currently reading gradient fill data from xlsx chart is not supported, so gradient fill data of the chart will get lost in the generated xls file.
Well, I tested your scenario and found no problem when saving an XLSX file to XLS file. The standard palette colors in the charts are saved fine. Please post your template file here which causes this problem and we will look into it soon.
Also, if you use the gradient fill with standard palette colors in your XLSX file and save it as XLS file, the colors will get lost. If you use solid fill, the colors will remain same in the generated XLS file.
Well, since the series color info is contained in the gradient fill data from xlsx file’s chart, so, the color would get lost saving to xls format. This is not supported yet. But, if a series uses solid fill and colors in the excel 2003 color palette, the colors won’t get lost saving to xls format.
We have found the issue regarding chart series colors in the generated XLS file. We are working on this issue and we will provide you a fix as soon as the issue gets resolved.
After checking the file 21010.xlsx again, we find the color of the area is not in the standard Palette. Please use Workbook.IsColorInPalette to check it. If you save the xlsx file to xls file, you will find the color of the area is changed.
Please check it with the following codes:
Workbook workbook = new Workbook();
workbook.Open(@"f:\filetemp\21010.xlsx");
Chart chart = workbook.Worksheets[0].Charts[0];
for (int i = 0; i < chart.NSeries.Count; i++)
{
Console.WriteLine(chart.NSeries[i].Type);
Console.WriteLine(workbook.IsColorInPalette(chart.NSeries[i].Area.ForegroundColor));
Console.WriteLine(chart.NSeries[i].Area.ForegroundColor);
}
We will try to look for a similar color in the palette to replace the color of the area, but this feature cannot be supported soon.
As a workaround, please set the color to the palette manually by using the following code,
Workbook workbook = new Workbook();
workbook.Open(@"f:\filetemp\21010.xlsx");
Chart chart = workbook.Worksheets[0].Charts[0];
for (int i = 0; i < chart.NSeries.Count; i++)
{
System.Drawing.Color color = chart.NSeries[i].Area.ForegroundColor;
if (!workbook.IsColorInPalette(color))
{
workbook.ChangePalette(color, 55 - i);
}
}
workbook.Save(@"f:\filetemp\dest.xls");
Well, MS Excel 2007 Xlsx color palette has more colors and is more enhanced. MS Excel 2003 xls standard color palette has limited colors. So, it is quite possible that when you convert/save as MS Excel 2007 xlsx file to MS Excel 2003 xls format, the colors might be lost/changed. There are some style formattings/colors for xlsx files which might not work/look the same in xls file format. Could you check the conversion xlsx->xls in MS Excel 2007 manually if it works fine.
If you confirm it works, kindly post your template xlsx and output xls file(generated by Aspose.Cells) with sample code, we will check your issue soon.
Well, it seems that colors in your XLSX files are not in the default Excel 2003 color template. So you have to use Workbook.IsColorInPalette option to check the color in the default palette and then you can add the color in the default palette. Please see the following code for your reference,
Sample Code:
//Instantiate a new Workbook.
Workbook excelbook = new Workbook();
excelbook.Open("c:\\output.xlsx",FileFormatType.Excel2007Xlsx);
Worksheet sheet = excelbook.Worksheets[0];
int colorIndex = 55;
for (int row = 0; row <= sheet.Cells.MaxRow;row++ )
{
for (int column = 0; column <= sheet.Cells.MaxColumn; column++)
{
Cell cell = sheet.Cells[row,column];
if (!excelbook.IsColorInPalette(cell.Style.ForegroundColor))
{
//add the color to the palette or use some other default color for those cells not
// in the default palette
if(colorIndex>0)
excelbook.ChangePalette(cell.Style.ForegroundColor, colorIndex--);
}
}
}
//Save the excel file.
excelbook.Save("C:\\Color_test.xls");
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.