Hi! Aspose team,
I have the requirement to display ole object inside PPT.
OLE Object is fine.
But the image which I am creating for the worksheet is not coming proper.
The Text in the image for the cell is getting cut off.
And the cell content in Excel are Vertically Top alligned.
PPT Screenshot image.png (49.3 KB)
Excel Screenshot for which I am creating image
image.png (11.3 KB)
I tried with autofit for dataSheet but still I am not able to get the image properly.
Could you please help me with this issue of image.
Attached sample code and Excel used for the POC.
public static void main(String[] args) throws Exception {
String dataDir = "D://AsposeSlides//";
// Create a workbook
Workbook workbook = new Workbook(dataDir+"Example.xlsx");
// set visible rows and columns count
int chartRows = 25;
int chartCols = 11;
Worksheet dataSheet = workbook.getWorksheets().get(0);
dataSheet.autoFitColumns();
// Set chart print area
dataSheet.getPageSetup().setPrintArea(dataSheet.getCells().get(0, 0).getName() + ":"
+ dataSheet.getCells().get(chartRows + 1, chartCols).getName());
// Set chart ole size
workbook.getWorksheets().setOleSize(0, chartRows, 0, chartCols);
// Get the chart worksheet as an image
ImageOrPrintOptions imageOptions = new ImageOrPrintOptions();
imageOptions.setImageType(ImageType.EMF);
imageOptions.setOnlyArea(true);
imageOptions.setOnePagePerSheet(true);
imageOptions.setAllColumnsInOnePagePerSheet(true);
SheetRender sheetRender = new SheetRender(dataSheet, imageOptions);
ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
sheetRender.toImage(0, imageStream);
byte[] imageByteArray = imageStream.toByteArray();
// Save the workbook to stream
ByteArrayOutputStream bout = new ByteArrayOutputStream();
workbook.save(bout, com.aspose.cells.SaveFormat.XLSX);
// Create a presentation
Presentation pres = new Presentation();
ISlide sld = pres.getSlides().get_Item(0);
// Add the workbook to the slide
IOleEmbeddedDataInfo dataInfo = new OleEmbeddedDataInfo(bout.toByteArray(), "xlsx");
IOleObjectFrame oof = sld.getShapes().addOleObjectFrame(1f, 1f,
(float) pres.getSlideSize().getSize().getWidth() - 2,
(float) pres.getSlideSize().getSize().getHeight() - 2, dataInfo);
oof.getSubstitutePictureFormat().getPicture()
.setImage(pres.getImages().addImage(imageByteArray));
// Write the presentation to disk
pres.save(dataDir+"Example-out-dataSummary.pptx", com.aspose.slides.SaveFormat.Pptx);
System.err.println("File Generated");
}
Used Excel:
Example.zip (11.6 KB)