Hi,
Well, actually MS Excel's standard color palette has 56 default colors on it. So, if you are setting some some custom colors for a range of cells in the worksheet, now when the copy operation is performed, the custom colors might be lost in the copied sheet. I think (as a workaround) you should export colors (in the palette) of your input workbook to your second workbook's palette, so that the custom colors should not be missed.
You may see the following sample code for the above scenario.
Workbook workbook = new Workbook();
.
.//Your code goes here.
.
.
//Note: Since Excel color palette has 56 colors on it.
//The colors are indexed 0-55.
//If a color is not present on the palette, we have to add it
//to the palette, so that we may use use.
//Add all the colors (including custom colors) of Workbook1 to change the palette of Workbook2.
Color[] colors = workbook.Colors;
Workbook book2 = new Workbook();
for (int i = 0; i < colors.Length; i++)
book2.ChangePalette(colors[i], i);
book2.Worksheets[0].Copy(workbook.Worksheets[0]);
book2.Save("f:\\test\\bookAfterCopy.xls");
Note: This is one of the possible scenario for your issue. But it might be some other scenario for your issue too. So, if you issue is not related to the above scenario. We appreciate if you could you elaborate: are you using an xlsx file and now want to copy its formatted worksheet to other xls file? I think you may post your complete sample code or create a test application, zip it and post here to show the issue, we will check it soon.
Thank you.
Amjad Sahi
Support Developer,
Aspose Sialkot Team
Contact Us