Hi msfaiz,
Thanks for your response.
Below is the code am using to embed Excel in PPT , but the whole sheet is not coming under
single slide.If i hard code the set olesize
workbook.setOleSize(0, 50, 0, 70);
am getting the output as in screenshot jpg which you attached, how to dynamically set the OleSize .
public void cleanUpExcelFile(String sFileInput, String sFileOutput,
int headerVal, int footerVal) {
Workbook workbook = new Workbook();
try {
workbook.open(sFileInput);
Worksheets worksheets = workbook.getWorksheets();
Worksheet sheet = worksheets.getSheet(0);
for (int i = worksheets.size() - 1; i > 0; --i) {
worksheets.removeSheet(i);
}
workbook.save(sFileOutput);
} catch (Exception e) {
e.printStackTrace();
}
}
private void generatePPT(String sExcelFile, String sPPtTemplate,
String sPptOutput) {
try {
Presentation pres = new Presentation(new FileInputStream(
sPPtTemplate));
Slide slide1 = pres.getSlideByPosition(1);
File file = new File(sExcelFile);
int length = (int) file.length();
FileInputStream fstro = new FileInputStream(file);
byte[] b = new byte[length];
fstro.read(b, 0, length);
int xPos = 1000 / 2;
int yPos = 0;
int width =(int) pres.getSlideSize().getX() - 1000;
int height =(int) pres.getSlideSize().getY();
slide1.getShapes().addOleObjectFrame(xPos, yPos, width, height, "Excel.Sheet.8", b);
/*
OleObjectFrame oof = slide1.getShapes().addOleObjectFrame(150, 500,
(int) pres.getSlideSize().getX() - 200,
(int) pres.getSlideSize().getY() - 1500, "Excel.Sheet.8", b);
*/
FileOutputStream fos = new FileOutputStream(sPptOutput);
pres.write(fos);
fos.flush();
fos.close();
} catch (PptException e) {
System.out.println("PPT Exception" + e);
e.printStackTrace();
} catch (IOException e) {
System.out.println("IO Exception caught " + e);
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
System.out.println("Start");
String sInFile = "c:/Export2PPT/temp.xls";
String sOutfile = "C:/Export2PPT//temp_output.xls";
String sPPtTemplate = "C:/Export2PPT/demo.ppt";
String sPptOutput = "C:/Export2PPT/result.ppt";
Demo obj = new Demo();
obj.cleanUpExcelFile(sInFile, sOutfile, 2, 1);
obj.generatePPT(sOutfile, sPPtTemplate, sPptOutput);
System.out.println("End");
}
please let me know where am making the mistake.
Regards
Janakiraman