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

Free Support Forum - aspose.com

Maintain values for chart X-Axis while converting Excel to PDF using Aspose.Cells for Java

Hi,

I am using Aspose.Cells v8.6.1
On converting Chart LIB_Column_061930 in attached excel to PDF, the values at X axis do not appear as what they are in excel sheet.

I have attached the Excel file, pdf taken using aspose, and PDF taken using MS-Excel.

For reference the sample code:
private static void chartToPDF() throws Exception {
Workbook workbook = new Workbook(“D:\UMI-LN_Model_Quark testing.xlsx”);
WorksheetCollection ws = workbook.getWorksheets();
Chart chart = workbook.getWorksheets().get(0).getCharts().get(“LIB_Column_061930”);
ChartShape cshape = chart.getChartObject();
int sheetIndex = ws.add();
com.aspose.cells.Worksheet worksheet = ws.get(sheetIndex);
chart.calculate();
double chartWidthInInches = chart.getChartObject().getWidthInch();
double chartHeightInInches = chart.getChartObject().getHeightInch();
boolean defaultApproach = true;
if (chartWidthInInches > 18 || chartHeightInInches > 5) {
// The approach being followed here is to iterate as many columns as colwidth in pixels & set each column width equal = 1 pixel.
// Similarly for chart height, iterate through as many rows as row height & set each row height = 1 pixel.
// This is being done to fit in large charts that have height & width beyond maximum row/col dimensions & white spaces around
// the chart.

double chartWidthInPixels = chart.getChartObject().getWidth();
double chartHeightInPixels = chart.getChartObject().getHeight();
// Deliberately including one more column because Aspose considers the last column adjacent to chart which leads to white space
// on right of chart
for (int i = 0; i <= chartWidthInPixels; i++) {
worksheet.getCells().setColumnWidthPixel(i, 1);
}

// Deliberately including one more row because Aspose considers the last row adjacent to chart which leads to white space
// below the chart.
for (int i = 0; i <= chartHeightInPixels; i++) {
worksheet.getCells().setRowHeightPixel(i, 1);
}
defaultApproach = false;
} else {
worksheet.getCells().setColumnWidthInch(0, chartWidthInInches);
worksheet.getCells().setRowHeightInch(0, chartHeightInInches);
}

//Setting the name of the newly added worksheet
String transientSheetName = “TransientWorksheet”;
worksheet.setName(transientSheetName);
//Copy the Chart to Second Worksheet
worksheet.getShapes().addCopy(cshape, 0, 0, 0, 0);
//Get the new chart and set its height and width accordingly
com.aspose.cells.Chart chart1 = worksheet.getCharts().get(0);
chart1.getChartObject().setHeightInch(chartHeightInInches);
chart1.getChartObject().setWidthInch(chartWidthInInches);
//Make remaining worksheets invisible so that they are not part of the output pdf
for (int i = 0; i < ws.getCount(); i++) {
String sheetName = ws.get(i).getName();
if(!transientSheetName.equalsIgnoreCase(sheetName)){
ws.get(i).setVisible(false);
}
}
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.setOnePagePerSheet(true);
worksheet.getPageSetup().setTopMargin(0);
worksheet.getPageSetup().setBottomMargin(0);
worksheet.getPageSetup().setRightMargin(0);
worksheet.getPageSetup().setLeftMargin(0);
//Setting Print area to first cell only as the chart is contained in the first cell (A1:A1)
if (defaultApproach) {
worksheet.getPageSetup().setPrintArea(“A1:A1”);
}
// Save the workbook
workbook.save(“d:\temp\Aspose_PDF.pdf”, pdfSaveOptions);
}


Can you please analyse this issue.

Thanks,
Neha Gautam

Hi Neha,


Thank you for contacting Aspose support.

Please check the attached PDF that we have generated against the latest version of Aspose.Cells for Java 8.6.1.2. Please notice the data labels for the X-axis where the difference between the two labels is 20 as opposed to the original chart where the difference is 10. Please confirm, are you taking about the aforementioned issue in this thread?

Hello,


Yes that’s the issue I am talking about. I used Aspose.Cells for Java 8.6.1. In the pdf generated, the difference between data labels for X-axis is 50.

Hi Neha,


Thank you for the confirmation. We have now logged this incident in our bug tracking system under the ticket CELLSJAVA-41557 for further analysis. Our product team will further look into the details of this problem and we will keep you updated on the status of correction.

Hi,


Please try our latest version/ fix: Aspose.Cells for Java (Latest Version)

We have fixed your issue “CELLSJAVA-41557” now.

Let us know your feedback.

Thank you.

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


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

Hello,


I have attached an Excel document.

I used aspose.cells v8.6.2 to generate pdf of chart-LIB_Column_061930_dup in worksheet Exhibits. But the issue I have reported is still not resolved.

I used chart.toPdf(…) method to generated the pdf

The difference in the Y-axis values is different in pdf taken using aspose and pdf taken using MS-Excel. The difference should have been 5 whereas it is 10.

Can you please look into this issue.

Hi,


Thanks for providing template files and some details.

You are right, the issue is still there using your newly attached file “UMI+LN_Model_Quark+testing+(1).xlsm” and the following sample code. I render the chart “LIB_Column_061930_dup” in the template file to PDF which does not show y-axis tick marks (labels) same as per original chart in the template file:
e.g
Sample code:

Workbook workbook = new Workbook(“UMI+LN_Model_Quark+testing+(1).xlsm”);
WorksheetCollection ws = workbook.getWorksheets();
Chart chart = workbook.getWorksheets().get(“Exhibits”).getCharts().get(“LIB_Column_061930_dup”);
ChartShape cshape = chart.getChartObject();
int sheetIndex = ws.add();
com.aspose.cells.Worksheet worksheet = ws.get(sheetIndex);
chart.calculate();
double chartWidthInInches = chart.getChartObject().getWidthInch();
double chartHeightInInches = chart.getChartObject().getHeightInch();
boolean defaultApproach = true;
if (chartWidthInInches > 18 || chartHeightInInches > 5) {
// The approach being followed here is to iterate as many columns as colwidth in pixels & set each column width equal = 1 pixel.
// Similarly for chart height, iterate through as many rows as row height & set each row height = 1 pixel.
// This is being done to fit in large charts that have height & width beyond maximum row/col dimensions & white spaces around
// the chart.

double chartWidthInPixels = chart.getChartObject().getWidth();
double chartHeightInPixels = chart.getChartObject().getHeight();
// Deliberately including one more column because Aspose considers the last column adjacent to chart which leads to white space
// on right of chart
for (int i = 0; i <= chartWidthInPixels; i++) {
worksheet.getCells().setColumnWidthPixel(i, 1);
}

// Deliberately including one more row because Aspose considers the last row adjacent to chart which leads to white space
// below the chart.
for (int i = 0; i <= chartHeightInPixels; i++) {
worksheet.getCells().setRowHeightPixel(i, 1);
}
defaultApproach = false;
} else {
worksheet.getCells().setColumnWidthInch(0, chartWidthInInches);
worksheet.getCells().setRowHeightInch(0, chartHeightInInches);
}

//Setting the name of the newly added worksheet
String transientSheetName = “TransientWorksheet”;
worksheet.setName(transientSheetName);
//Copy the Chart to Second Worksheet
worksheet.getShapes().addCopy(cshape, 0, 0, 0, 0);
//Get the new chart and set its height and width accordingly
com.aspose.cells.Chart chart1 = worksheet.getCharts().get(0);
chart1.getChartObject().setHeightInch(chartHeightInInches);
chart1.getChartObject().setWidthInch(chartWidthInInches);
//Make remaining worksheets invisible so that they are not part of the output pdf
for (int i = 0; i < ws.getCount(); i++) {
String sheetName = ws.get(i).getName();
if(!transientSheetName.equalsIgnoreCase(sheetName)){
ws.get(i).setVisible(false);
}
}
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.setOnePagePerSheet(true);
worksheet.getPageSetup().setTopMargin(0);
worksheet.getPageSetup().setBottomMargin(0);
worksheet.getPageSetup().setRightMargin(0);
worksheet.getPageSetup().setLeftMargin(0);
//Setting Print area to first cell only as the chart is contained in the first cell (A1:A1)
if (defaultApproach) {
worksheet.getPageSetup().setPrintArea(“A1:A1”);
}
// Save the workbook
workbook.save(“out1.pdf”, pdfSaveOptions);

I have reopened your issue “CELLSJAVA-41557” again. Our product team will look into it soon.

Once we have any update on it, we will let you know here.

Thank you.


Hi,

Thanks for your posting and using Aspose.Cells.

The scales of vertical value axis can’t be fixed now. The height of axis is too small. We need to add the scale from 5 to 10 and reduce the count of the axis labels for making the labels not overlapping.

In excel, the legend is 2 rows, but Aspose is 3 rows. We will look into it and find the size of legend related to the size of chart. If you drag the corner of chart to make the size of chart change, the axis and legend will change too. For this chart, the size is critical value. We can’t do same as excel.