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

Free Support Forum - aspose.com

Wanna add more than 56 colors in a Palette for Aspose.cells

Hi,

I am painting charts which has more than 56 columns in it.
So after 56, the colors repeat which is not authentic.
I want to have different colors for all the columns, but I don’t have it In the Palette.
And it doesn’t allow me to add a new Custom color in position 57 and above.
Giving the error “Invalid Palette Index”.

Please suggest some feasible work around.

Regards,
Aslam

Hi,

Thanks for your question.

You will have to replace the existing color of the palette. I mean, overwrite them with your desired colors.

Hi,


Also, For your information, you can set more than 56 colors when saving the file as Excel 2007 file formats(XLSX, XLSB, XSLM etc.) using Aspose.Cells, you don’t need to add/set the colors to the palette as MS Excel 2007/2010 color palette has lots of colors. Please see the following sample code to set a color which is not a part of 56 Color Palette of Excel 2003.

Workbook workbook = new Workbook();
Style style = workbook.Styles[workbook.Styles.Add()];
// Color not in Excel 2003 56 Color standard palette
style.ForegroundColor = Color.FromArgb(20, 228, 241, 155);
style.Pattern = BackgroundType.Solid;
Cells cells = workbook.Worksheets[0].Cells;
cells[“A1”].SetStyle(style);
workbook.Save(“C:\Color_Test.xlsx”, SaveFormat.Excel2007Xlsx);

For you information, it is the limitation of Excel (97-2003) for XLS format that its standard color palette can only has 56 colors at a time. Also, if you want to use any color which is not a part of Excel 2003 Default Color Palette in Excel 2003 file format, you may change the color palette. For details please check the following documentation link:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/colors-and-palette.html


Thank you.

Hi,
I have problem with save format for toImage
well the next code trows exception

ByteArrayOutputStream pictureBytes = new ByteArrayOutputStream();
ImageOrPrintOptions imageOptions = new ImageOrPrintOptions ();
imageOptions.setSaveFormat( imageOptions.getSaveFormat());
aChart.toImage( pictureBytes, imageOptions );


How do I set 2007 excel format for generated images instead of 2003 excel colors?

If I use the next code
ImageOrPrintOptions imageOptions = new ImageOrPrintOptions ();
imageOptions.setImageFormat( ImageFormat.getPng() );
imageOptions.setHorizontalResolution( (int)(AsposeUtility.EXCEL_CHART_WIDTH * AsposeUtility.PIXELS_TO_POINTS) );
imageOptions.setVerticalResolution( (int)(AsposeUtility.EXCEL_CHART_HEIGHT * AsposeUtility.PIXELS_TO_POINTS) );
ByteArrayOutputStream pictureBytes = new ByteArrayOutputStream();
BufferedImage image = null;
aChart.toImage( pictureBytes, imageOptions );
byte[] data = pictureBytes.toByteArray();
Then image have colors as in 2003 excel, but I need colors for 2007.

Hi,


If your chart is in XLS file, the image would be generated in Excel 2003 colors format. If your file XLSX, then the chart image would be in accordance with Excel 2007 colors. Which version of the product you are using (please use our latest version Aspose.Cells for Java v7.0.3)?

If you still find the issue, kindly attach your template Excel file and output image file here, we will check it soon.

Thank you.

Please see the next code, I can’t change save format for image (7.0.2 and 7.0.3 Aspose cells)
if I set the same format then the method aChart.toImage( pictureBytes, imageOptions ); throws exception: java.lang.Exception: Image format(ICON) is not supported.

The attachment contains example then chart is added in excel as chart and as image(from Aspose toImage()).

ImageOrPrintOptions imageOptions = new ImageOrPrintOptions ();
imageOptions.setImageFormat( ImageFormat.getPng() );

imageOptions.setSaveFormat( imageOptions.getSaveFormat() );
imageOptions.setHorizontalResolution( (int)(AsposeUtility.EXCEL_CHART_WIDTH * AsposeUtility.PIXELS_TO_POINTS) );
imageOptions.setVerticalResolution( (int)(AsposeUtility.EXCEL_CHART_HEIGHT * AsposeUtility.PIXELS_TO_POINTS) );

ByteArrayOutputStream pictureBytes = new ByteArrayOutputStream();

// create new picture object
BufferedImage image = null;
try
{
// convert aspose chart object to image
aChart.toImage( pictureBytes, imageOptions );

Hi,


I have tested with our latest fix v7.0.3.2, it works fine. Please try it. The output images are almost same as Excel, see the attached two image files.

Here is simplest sample code that I used.

Sample code:
Workbook workbook = new Workbook(“colors+in+pie+and+column+with+image.xlsx”);

Chart chart = workbook.getWorksheets().get(0).getCharts().get(0);
chart.toImage(“one.bmp”);