Poor quality of embedded scaled chart

I have combined solutions for embedding chart and resizing its frame. Unfortunately the final result presents two problems:

1. Poor quality of the initial presentation when fonts are scaled preserving aspect ratio (e.g. resulting in either too wide or too narrow fonts).

2. Activating and then de-activating frame changes the size of the final object together with relatives sizes of the constituents of the chart (e.g. the legend and the plot area).

The source code of the program is attached.

package com.citi.aw.reporting.excel;

import java.io.ByteArrayInputStream;

import java.io.ByteArrayOutputStream;

import java.io.FileOutputStream;

import java.lang.reflect.Array;

import com.aspose.cells.Chart;

import com.aspose.cells.ChartType;

import com.aspose.cells.ImageOptions;

import com.aspose.cells.SheetType;

import com.aspose.cells.Workbook;

import com.aspose.cells.Worksheet;

import com.aspose.slides.OleObjectFrame;

import com.aspose.slides.Presentation;

import com.aspose.slides.Slide;

public class TestExcel

{

public static void Run()

{

try

{

// Create a workbook

Workbook wb = new Workbook();

// Add an excel chart

int chartRows = 55;

int chartCols = 25;

int chartSheetIndex = AddExcelChartInWorkbook(wb, chartRows, chartCols);

// Set chart ole size

wb.setOleSize(0, chartRows, 0, chartCols);

final Chart chart = wb.getWorksheets().getSheet(chartSheetIndex).getCharts().getChart(0);

//----------------------------------------------------------------------------------

final int ShapeW = 3 * 576;

final int ShapeH = 3 * 576;

chart.setSizeWithWindow(true);

//set window width of the workbook in inches (divided by 576 as PowerPoint uses

//576 pixels / inch)

wb.setWindowWidthInch(ShapeW/576f);

//set window height of the workbook in inches

wb.setWindowHeightInch(ShapeW/576f);

//Save Workbook to Stream

ByteArrayOutputStream wbStream=new ByteArrayOutputStream();

wb.save(wbStream);

//----------------------------------------------------------------------------------

// Get the chart image and save to stream

ByteArrayOutputStream imageStream = new ByteArrayOutputStream();

chart.toImage(imageStream, new ImageOptions());

// Save the workbook to stream

ByteArrayOutputStream bout = new ByteArrayOutputStream();

wb.save(bout);

// Create a presentation

Presentation pres = new Presentation();

Slide sld = pres.getSlideByPosition(1);

// Add the workbook on slide

AddExcelChartInPresentation(pres, sld, 0, 0, ShapeW, ShapeH, bout.toByteArray(), imageStream.toByteArray());

// Write the presentation to disk

pres.write(new FileOutputStream("c:\\temp\\aspose\\outputJava.ppt"));

}

catch(Exception e)

{

e.printStackTrace();

}

}

static int AddExcelChartInWorkbook(Workbook wb, int chartRows, int chartCols)

{

// Array of cell names

String[] cellsName = new String[]

{

"A1", "A2", "A3", "A4",

"B1", "B2", "B3", "B4",

"C1", "C2", "C3", "C4",

"D1", "D2", "D3", "D4",

"E1", "E2", "E3", "E4"

};

// Array of cell data

int[] cellsValue = new int[]

{

67, 86, 68, 91,

44, 64, 89, 48,

46, 97, 78, 60,

43, 29, 69, 26,

24, 40, 38, 25

};

// Add a new worksheet to populate cells with data

Worksheet dataSheet = wb.getWorksheets().addSheet();

String sheetName = "DataSheet";

dataSheet.setName(sheetName);

// Populate DataSheet with data

int size = Array.getLength(cellsName);

for(int i = 0; i < size; i++)

{

String cellName = cellsName[i];

int cellValue = cellsValue[i];

dataSheet.getCells().getCell(cellName).setValue(cellValue);

}

// Add a chart sheet

Worksheet chartSheet = wb.getWorksheets().addSheet(SheetType.CHART);

chartSheet.setName("ChartSheet");

int chartSheetIdx = chartSheet.getIndex();

// Add a chart in ChartSheet with data series from DataSheet

Chart chart = chartSheet.getCharts().addChart(ChartType.COLUMN_CLUSTERED, 0, chartRows, 0, chartCols);

chart.getNSeries().add(sheetName + "!A1:E1", false);

chart.getNSeries().add(sheetName + "!A2:E2", false);

chart.getNSeries().add(sheetName + "!A3:E3", false);

chart.getNSeries().add(sheetName + "!A4:E4", false);

// Set ChartSheet as active sheet

wb.getWorksheets().setActiveSheet(chartSheetIdx);

return chartSheetIdx;

}

static void AddExcelChartInPresentation(Presentation pres, Slide sld, int x, int y, int w, int h, byte[] wbArray, byte[] imgChart)

throws Exception

{

com.aspose.slides.Picture pic = new com.aspose.slides.Picture(pres, new ByteArrayInputStream(imgChart));

int picId = pres.getPictures().add(pic);

OleObjectFrame oof = sld.getShapes().addOleObjectFrame(x, y, w, h, "Excel.Sheet.8", wbArray);

oof.setPictureId(picId);

}

public static void main(String[] args)

{

Run();

}

}

Hi Boris,

I have worked with the code snippet shared by you and have observed the Ole Frame getting resized on every time I enable or disable that. An issue with ID 23603 has been created in our issue tracking system to further investigate and resolve the issue. Secondly as far as font scaling issue, I feel if you adjust the width and height of the Ole Frame with respect the ratio of slide width and height, you will not observe this issue any more. I have attached the generated presentation in which I used frame width 5 and height 4. You will observe that the font don't seemed to be skewed or scaled that much.

Thanks and Regards,