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

Free Support Forum - aspose.com

OleFrame Preview generated with Linux not avail with Powerpoint 2010/2013

Hello there,

i am trying to insert a xls with a preview as OLE Object Frame into a pptx. The result file preview is shown with libre office but not with Powerpoint 2010 and 2013 - but if i doubleclick it the xls is opened - and i can edit it.

Seems something wrong with the image resource location inside the pptx?


Environment:
- java.vm.name: Java HotSpot™ 64-Bit Server VM
- java.vm.vendor: Oracle Corporation
- java.vm.version: 24.45-b08
- java.runtime.name: Java™ SE Runtime Environment
- java.runtime.version: 1.7.0_45-b18
- os.name: Linux
- os.arch: amd64
- java.io.tmpdir: /tmp
- file.encoding: UTF-8
- sun.io.unicode.encoding: UnicodeLittle
- sun.cpu.endian: little
- Available processors (cores): 8
- Free memory (bytes): 291 MB
- Maximum memory (MBytes): 5335 MB
- Total memory available to JVM (MBytes): 359 MB
- File system root: /
- Total: 218084 MB; used: 156822 MB; available: 61262 MB
- Aspose lib versions:
- Aspose.Words for Java : 14.11.0.0
- Aspose.Cells for Java : 8.3.1.0
- Aspose.Slides for Java: 14.9.0.0
- Aspose.Pdf for Java : 9.7.0


Code used:
String tempFileName = getClass().getSimpleName() + “.” + (new Object(){}.getClass().getEnclosingMethod().getName());
File tempFile = File.createTempFile(“mls-temp-”+tempFileName, “.ole”);
tempFile.deleteOnExit();
CleanupProcessor.getFileCollection().add(tempFile);

FileOutputStream fos = new FileOutputStream(tempFile);
IOUtils.copy((InputStream) oleObject.getOleObjectBinary().getContent(), fos);
IOUtils.closeQuietly(fos);

//Reading object data in Workbook
Workbook wb = new Workbook(tempFile.getAbsolutePath());
ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
try {
wb.getWorksheets().get(0).getCharts().get(0).toImage(imageStream, new ImageOrPrintOptions());
} catch (Exception e) {
try {
wb.getWorksheets().get(1).getCharts().get(0).toImage(imageStream, new ImageOrPrintOptions());
} catch (Exception e1) {
try {
wb.getWorksheets().get(2).getCharts().get(0).toImage(imageStream, new ImageOrPrintOptions());
} catch (Exception e3) {
// could not get any charts
}
}
}

com.aspose.cells.OoxmlSaveOptions so1 = new com.aspose.cells.OoxmlSaveOptions(com.aspose.cells.SaveFormat.EXCEL_97_TO_2003);
ByteArrayOutputStream baos=new ByteArrayOutputStream();
//Saving modified excel sheet
wb.save(baos, so1);

//Add an Ole Object Frame shape
IOleObjectFrame oof = null;
oof = slide.getShapes().addOleObjectFrame(x, y, totalWidth, totalHeight, “Excel.Sheet.8”, baos.toByteArray());
oof.getSubstitutePictureFormat().getPicture().setImage(slide.getPresentation().getImages().addImage(new ByteArrayInputStream(imageStream.toByteArray())));

IOUtils.closeQuietly(baos);

Resulting file ill attach to the post.

Thanks in advance
Helge Rennicke

Hi Helge Rennicke,

I have observed the generated presentation file from you. I request you to please share the working sample code along with source files used so that we may also try to reproduce the issue on our end. But before sharing further with us, I suggest you to please visit and use this documentation article that does the same thing as you are trying to achieve on your end. I hope this will be helpful to you in your scenario.

Many Thanks,

well not shure what i should provide more than already given - the embedded ole object was created like given in your demo files:

//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.getWorksheets().setOleSize(0, chartRows, 0, chartCols);
//Get the chart image and save to stream
ByteArrayOutputStream imageStream=new ByteArrayOutputStream();
wb.getWorksheets().get(chartSheetIndex).getCharts().get(0).toImage(imageStream, new ImageOrPrintOptions());
//Save the workbook to stream
FileOutputStream fos = new FileOutputStream(tempFile);
wb.save(fos, com.aspose.cells.SaveFormat.EXCEL_97_TO_2003);

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
int dataSheetIndex =wb.getWorksheets().add();
Worksheet dataSheet =wb.getWorksheets().get(dataSheetIndex);
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().get(cellName).setValue(cellValue);
}
//Add a chart sheet
int WorksheetIndex = wb.getWorksheets().add(SheetType.CHART);
Worksheet chartSheet = wb.getWorksheets().get(WorksheetIndex);
chartSheet.setName(“ChartSheet”);
int chartSheetIdx = chartSheet.getIndex();
//Add a chart in ChartSheet with data series from DataSheet
int chIndex = chartSheet.getCharts().add(ChartType.COLUMN, 0, chartRows, 0, chartCols);
Chart chart=chartSheet.getCharts().get(chIndex);

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().setActiveSheetIndex(chartSheetIdx);
return chartSheetIdx;

}

Hi Helge Rennicke,

I have observed your sample code and have created the sample application for your kind reference. Please share, if I may help you further in this regard.

public static void TestEmbeddedChart() throws Exception
{
String path=“D:/Aspose Data/”;
//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.getWorksheets().setOleSize(0, chartRows, 0, chartCols);
//Get the chart image and save to stream
ByteArrayOutputStream imageStream=new ByteArrayOutputStream();
ByteArrayOutputStream dataStream=new ByteArrayOutputStream();

com.aspose.cells.OoxmlSaveOptions so1 = new com.aspose.cells.OoxmlSaveOptions(com.aspose.cells.SaveFormat.EXCEL_97_TO_2003);
//Saving modified excel sheet
wb.save(dataStream, so1);

File outputFile = new File(path+“outagain.png”);
FileOutputStream fos = new FileOutputStream(outputFile);


com.aspose.cells.ImageOrPrintOptions opts= new com.aspose.cells.ImageOrPrintOptions();
// opts.setImageFormat(com.aspose.cells.ImageFormat.getJpeg());
opts.setImageFormat(com.aspose.cells.ImageFormat.getPng());
wb.getWorksheets().get(chartSheetIndex).getCharts().get(0).toImage(fos, opts);

fos.close();
wb.getWorksheets().get(chartSheetIndex).getCharts().get(0).toImage(imageStream,opts);

Presentation pres=new Presentation();
ISlide slide=pres.getSlides().get_Item(0);

IOleObjectFrame oof=slide.getShapes().addOleObjectFrame(0,0, 400, 300,“Excel.Sheet.8” ,dataStream.toByteArray());

IPPImage imgx=null;

try{
imgx = pres.getImages().addImage(new FileInputStream(new File( path+“Desert.jpg”)));
}
catch(IOException e){}

oof.getSubstitutePictureFormat().getPicture().setImage(slide.getPresentation().getImages().addImage(new ByteArrayInputStream(imageStream.toByteArray())));

pres.save(path+“TestOle.pptx”,SaveFormat.Pptx);

}

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
int dataSheetIndex =wb.getWorksheets().add();
Worksheet dataSheet =wb.getWorksheets().get(dataSheetIndex);
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().get(cellName).setValue(cellValue);
}
//Add a chart sheet
int WorksheetIndex = wb.getWorksheets().add(com.aspose.cells.SheetType.CHART);
Worksheet chartSheet = wb.getWorksheets().get(WorksheetIndex);
chartSheet.setName(“ChartSheet”);
int chartSheetIdx = chartSheet.getIndex();
//Add a chart in ChartSheet with data series from DataSheet
int chIndex = chartSheet.getCharts().add(com.aspose.cells.ChartType.COLUMN, 0, chartRows, 0, chartCols);
com.aspose.cells.Chart chart=chartSheet.getCharts().get(chIndex);

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().setActiveSheetIndex(chartSheetIdx);
return chartSheetIdx;

}

Many Thanks,