We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Theme color palette different color sequence

Hello,

I have upgraded my Aspose license to 18.6.0. Getting some issues with Line chart. I have an excel template where I have set the line chart series color as green. Then in Aspose code I use to generate new workbook and copy the template data to new aspose workbook. Code below :-1:

private static byte[] ConcatenateExcel(List<byte[]> resultList)
{
Workbook wb = new Workbook(FileFormatType.Xlsx);
wb.Worksheets.Clear();
Dictionary<string, bool> visibilities = new Dictionary<string, bool>();
foreach (var result in resultList)
{
var processingFile = new Workbook(new MemoryStream(result));
foreach (var ws in processingFile.Worksheets.OrderByDescending(sheet => sheet.Index))//Order by descending in order to insert data sheet first.
{
var newSheetIndex = wb.Worksheets.Add();
var newWS = wb.Worksheets[newSheetIndex];
if (newWS != null)
{
newWS.Name = ws.Name;
newWS.Copy(ws, new CopyOptions() { CopyNames = true, ColumnCharacterWidth = true, CopyInvalidFormulasAsValues = true });

                    visibilities.Add(newWS.Name, ws.IsVisible);
                    //wb.Worksheets[newSheetIndex].IsVisible = ws.IsVisible;
                }
            }
        }
        foreach (var item in visibilities)
        {
            wb.Worksheets[item.Key].IsVisible = item.Value;
        }

        return GetBytes(wb);
    }

When I generate the output I get gray color of series instead of green. I compared aspose excel output with noremal microsoft excel line chart color pallete. I have found the color sequence difference . Picture attached.
ChartSeriesIssue.PNG (195.6 KB)

Please guide me through this issue.

Thanks,
Sarthak

@spathak,

Thanks for your query.

Please share your one or more template Excel file(s) which can be used for testing.

Hello,
Thanks for the response. I have attached the template excel file.
If you open template then you can see a chart series in green color. but one you run that through a code below and generate aspose workbook with that template you will see change in series color from green to gray.

Code to generate issue.

public static byte[] PopulateDatatoExcel()
{
Workbook wb = new Workbook(new MemoryStream(Properties.Resources.chartTest_Series));
var testbyte = GetByte(wb);
var res = new List<byte[]>();
res.Add(testbyte);
ConcatenateExcel(res);
wb.Save(@“C:\TEMP\ReviewChart.xlsx”);
return GetBytes(wb);
}

private static byte[] ConcatenateExcel(List<byte[]> resultList)
{
Workbook wb = new Workbook(FileFormatType.Xlsx);
wb.Worksheets.Clear();
Dictionary<string, bool> visibilities = new Dictionary<string, bool>();
foreach (var result in resultList)
{
var processingFile = new Workbook(new MemoryStream(result));
foreach (var ws in processingFile.Worksheets.OrderByDescending(sheet => sheet.Index))//Order by descending in order to insert data sheet first.
{
var newSheetIndex = wb.Worksheets.Add();
var newWS = wb.Worksheets[newSheetIndex];
if (newWS != null)
{
newWS.Name = ws.Name;
newWS.Copy(ws, new CopyOptions() { CopyNames = true, ColumnCharacterWidth = true, CopyInvalidFormulasAsValues = true });

                    visibilities.Add(newWS.Name, ws.IsVisible);
                    //wb.Worksheets[newSheetIndex].IsVisible = ws.IsVisible;
                }
            }
        }
        foreach (var item in visibilities)
        {
            wb.Worksheets[item.Key].IsVisible = item.Value;
        }

        wb.Save(@"C:\TEMP\ReviewChart2.xlsx"); // Check this excel file output which will give you different chart series color.

        return GetBytes(wb);
    }
    private static byte[] GetBytes(Workbook wb)
    {
        using (MemoryStream ms = new MemoryStream())
        {
            wb.Save(ms, SaveFormat.Xlsx);
            ms.Seek(0, SeekOrigin.Begin);
            return ms.ToArray();
        }
    }
    private static byte[] GetByte(Workbook wb)
    {
        using (MemoryStream ms = new MemoryStream())
        {
            wb.Save(ms, SaveFormat.Xlsx);
            ms.Seek(0, SeekOrigin.Begin);
            return ms.ToArray();
        }

    }

chartTest_Series.zip (24.3 KB)

@spathak,

We were able to observe the issue but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as
CELLSNET-46271 - Chart series color changed while loading and saving Excel file

@spathak,

An excel file has only a theme color. So, you should add copying the theme color too in ConcatenateExcel() method. See the following sample code segment for your reference:
e.g
Sample code:

...
foreach (var result in resultList)
            {
                var processingFile = new Workbook(new MemoryStream(result));
                wb.CopyTheme(processingFile);
....

@Amjad_Sahi
Thank you for this solution. It worked. But, is there any issue fixed in new version or what happened? Because or code use to work fine before but after upgrade it failed. Is this excel issue or what changed in new version.

@spathak,

Good to know that it figures out your issue now. We have recorded your concerns against your issue into our database. The issue is still open and once we have an update or more information, we will share it with you.

@spathak,

In source file, the line’s color of chart is “accent3” that is dynamical value and depend on the theme of workbook. Please refer the “LineColor.png” in the attachedment. You unzip the “chartTest_Series.xlsx” and find the setting in “xl/charts/chart1.xml”. Open the “xl/theme/theme1.xml”, we can see the “accent3” is “9BBB59”. Please refer to the “ThemeOfSourcefile.png” of attachment. When new Workbook() using Aspose.Cells API, we will create a default theme that is “ThemeOfNewWorkbook.png”. Now the default theme is same as the latest MS Excel.
Images.zip (448.8 KB)

@spathak

This is to inform you that we have fixed your issue. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.