chart.Image with Percentage Cells throws Exception

Hi,

Since I did an upgrade from aspose-cells 2.5.4.15 to 7.0.0 I have a problem with percentage values when saving an chart as an image.

Following code snipped:
...
Cells cells = sheet.getCells();
cells.get("E3").setValue(0.5d);
Style style = workbook.createStyle();
style.setCustom("#,##0%");
cells.get("E3").setStyle(style);
...
chart.toImage("C:/projects/test.jpg");

throws following Exception:

java.lang.NumberFormatException: For input string: "."
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1224)
at java.lang.Double.parseDouble(Double.java:482)
...
at com.aspose.cells.Chart.toImage(Unknown Source)

What I figured out is that following values work:
e3.setValue(10.05d);
e3.setValue(1.05d);
e3.setValue(1.5d);

but following values do not work:
e3.setValue(10.5d);
e3.setValue(0.05d);
Please provide me an fix ASAP

Thank you

Hi,


Please paste your complete sample code/program or final Excel template file (containing the chart and source data). I need to take the image of the chart to check your issue precisely. If I found the issue, I will log it into our issue tracking system so, that we could fix it correctly.

Thank you.

Thank you for your quick response.

I attached my test class

Hi,


I tested the following adjusted code and it works fine with our latest version/fix v7.0.0.3 (attached).

Sample code:
import java.io.File;



import com.aspose.cells.Cell;
import com.aspose.cells.Cells;
import com.aspose.cells.Chart;
import com.aspose.cells.ChartCollection;
import com.aspose.cells.ChartPoint;
import com.aspose.cells.ChartType;
import com.aspose.cells.Color;
import com.aspose.cells.FormattingType;
import com.aspose.cells.Series;
import com.aspose.cells.SeriesCollection;
import com.aspose.cells.Style;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;
import com.aspose.cells.WorksheetCollection;

public class CreateChartTest
{
public static void main(String[] args) throws Exception
{
// Instantiating a Workbook object
Workbook workbook = new Workbook();

Chart chart = createChart(workbook);

SeriesCollection nSeries = chart.getNSeries();

nSeries.add(“B2:E4”, true);
nSeries.setCategoryData(“A2:A4”);
nSeries.get(0).setName("=B1");
nSeries.get(1).setName("=C1");
nSeries.get(2).setName("=D1");
Series series = nSeries.get(3);
series.setName("=E1");

series.getArea().setTransparency(1d);
ChartPoint chartPoint = series.getPoints().get(1);
chartPoint.getDataLabels().setShowValue(true);
chartPoint.getArea().setForegroundColor(Color.getCyan());
chartPoint.getBorder().setVisible(false);
chartPoint.getArea().setTransparency(1d);
chartPoint.getArea().setFormatting(FormattingType.NONE);

chart.getPlotArea().getArea().setForegroundColor(Color.getOrange());
chart.getChartArea().getArea().setForegroundColor(Color.getYellow());
System.out.println(“area transparency: " + series.getArea().getTransparency());
System.out.println(“chartpoint transparency: " + chartPoint.getArea().getTransparency());

chart.toImage(“outmytestingimg.jpg”);
saveFile(workbook);
}

private static void saveFile(final Workbook workbook) throws Exception
{
// Saving the Excel file
//File dir = new File(“target/test/others/”);
// dir.mkdirs();
// String absolutePath = new File(dir, “test.xls”).getAbsolutePath();
workbook.save(“outmytesting.xls”);
//return absolutePath;
}

private static Chart createChart(final Workbook workbook) throws Exception
{
// Obtaining the reference of the first worksheet
WorksheetCollection worksheets = workbook.getWorksheets();
Worksheet sheet = worksheets.get(0);
// Adding some sample value to cells
Cells cells = sheet.getCells();
cells.importArray(new double[][] {
//
{ 1, 2, 3, 4 },// 1
{ 2, 3, 4, 0.5 },// 2
{ 3, 4, 5, 6 }// 3
, }, 1,// row
1// col
);

// set category labels
cells.importArray(new String[][] { { “category 1” }, { “category 2” }, { “category 3” } }, 1, 0);
// set column labels
cells.importArray(new String[][] { { “hans”, “sepp”, “rupert”, “michl” } }, 0, 1);
ChartCollection charts = sheet.getCharts();
// Adding a chart to the worksheet
int chartIndex = charts.add(ChartType.COLUMN, 5, 0, 15, 5);
Chart chart = charts.get(chartIndex);

// TEST PERCENTAGE FORMATTING
addPercentageCell(workbook, cells);

return chart;
}

private static void addPercentageCell(final Workbook workbook, final Cells cells)
{
Cell e3 = cells.get(“E3”);
e3.setValue(0.05d);
Style style = workbook.createStyle();
style.setCustom(”#,##0.00%”);
e3.setStyle(style);
}
}

I have also attached the output Excel file and output image file for the chart.

Thank you.

Hi,

I downloaded the new version and tried the modified code you posted, but it does not work for me.

I also compiled and started the application from command line, but I get the same Exception as before.

Please have a look at the eclipse-project I attached.

Thank you

Hi,


I still could not find the issue.
I am using the version v7.0.0.3 on Windows 7, JDK1.5

Could you give us your environment and JDK details, it may help us to figure out the issue.

thank you.

Hi,

I am using Windows 7 (64 bit), but also tested with Windows XP (32 Bit)

I tried with jdk1.5.0_22 and jdk1.6.0_24

May it be an issue with other locale settings in the jvm?
Locale.getDefault() returns "de_AT"

By the way: how can I set the locale of a workbook?

Thank you

Hi,


Could you try to check with US - English locale settings? Let us know if it works fine.

Thank you.

Hi,

now I got it to work
when I set the default locale to “en_US” it works
Locale.setDefault(new Locale(“en”, “US”));

but when I set the default locale to “de_AT” it does not
Locale.setDefault(new Locale(“de”, “AT”));

Can you please fix that. I do not want to affect the whole JVM

By the way:
In version 2.5.4 it was possible to specify a locale for the workbook
workbookSettings.setLocale(locale)

How can I specify the locale in v7.0.0(.3)?
I need to support different number formattings
e.g. EN: 2,000.00
DE: 2.000,00

Hi,


We will look into the issue of setting locales accordingly. An issue with an id: CELLSJAVA-30459. is already logged for it. We will also support WorkbookSettings.setLocale(locale) method.

Thank you.

The issues you have found earlier (filed as CELLSJAVA-30459,CELLSJAVA-30459) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.