Hi! Aspose Team,
I have the requirement to add the embedded excel in the PPT, I have tried adding it but the size of the embedded excel is quite large & I am facing issue in scrolling the embedded excel.
Is there a way to determine the size of embedded excel according the PPT slide height & width.
I have attached the sample code & excel for the reference.
Example.zip (9.0 KB)
public class OleFrameForGrid {
public static void main(String[] args) throws Exception {
String dataDir = “D://AsposeSlides//”;
boolean IsExists = new File(dataDir).exists();
if (!IsExists)
new File(dataDir).mkdirs();
// Instantiate Prsentation class that represents the PPTX
Presentation pres = new Presentation();
try
{
// Access the first slide
ISlide sld = pres.getSlides().get_Item(0);
sld.getShapes().getParentGroup().getFillFormat().setFillType(FillType.NoFill);
// Load an cel file to stream
FileInputStream fs = new FileInputStream(dataDir + "Example.xlsx");
ByteArrayOutputStream mstream = new ByteArrayOutputStream();
byte[] buf = new byte[4096];
while (true)
{
int bytesRead = fs.read(buf, 0, buf.length);
if (bytesRead <= 0)
break;
mstream.write(buf, 0, bytesRead);
}
// Create data object for embedding
IOleEmbeddedDataInfo dataInfo = new OleEmbeddedDataInfo(mstream.toByteArray(), "xlsx");
float width = (float)pres.getSlideSize().getSize().getWidth();
float height = (float)pres.getSlideSize().getSize().getHeight();
// Add an Ole Object Frame shape
IOleObjectFrame oleObjectFrame = sld.getShapes().addOleObjectFrame(0, 0, (float)pres.getSlideSize().getSize().getWidth(),
(float)pres.getSlideSize().getSize().getHeight(), dataInfo);
//Write the PPTX to disk
pres.save(dataDir + "OleEmbed_out_6.pptx", SaveFormat.Pptx);
System.out.println("Created EmbedObject in PPT");
}
finally
{
if (pres != null) pres.dispose();
}
//ExEnd:AddOLEObjectFrame
}
}
@Rohan_Wankar
Thank you for contacting support.
You can use the two products Aspose.Slides and Aspose.Cells together to improve the result.
Please see the example below for how to do this:
//Create a workbook
Workbook workbook = new Workbook("Example.xlsx");
//set visible rows and columns count
int chartRows = 25;
int chartCols = 11;
Worksheet dataSheet =workbook.getWorksheets().get(0);
//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);
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("Example-out.pptx", com.aspose.slides.SaveFormat.Pptx);
And please check the attached presentation Example-out.zip (34.8 KB)
Hi! @stanislav.miroshnichenko1
This helped me,
But my requirement is to display some content in ppt table & all the content in embedded excel.
I don’t want to show the excel image in ppt.
Is it possible to show the some content in PPT and have the embedded excel below it?
please let me know if you need further details for the same.
thanks!
@Rohan_Wankar
In the code below I removed the excel image and added some text content before embedded excel object. Is this what you want?
code:
//Create a workbook
Workbook workbook = new Workbook("Example.xlsx");
//set visible rows and columns count
int chartRows = 15;
int chartCols = 11;
Worksheet dataSheet =workbook.getWorksheets().get(0);
//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);
//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);
IAutoShape autoShape = sld.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 150, 50);
autoShape.addTextFrame("Hello from Aspose!");
//Add the workbook on slide
IOleEmbeddedDataInfo dataInfo = new OleEmbeddedDataInfo(bout.toByteArray(), "xlsx");
IOleObjectFrame oof = sld.getShapes().addOleObjectFrame(50, 100,
300,
300, dataInfo);
//Write the presentation to disk
pres.save("Example-out3.pptx", com.aspose.slides.SaveFormat.Pptx);
result: Example-out3.zip (44.9 KB)
You can read more about text formatting in the product documentation.