Formatting not retained while creating .ppt from excel template in Java

Hi Priya,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

After further investigating your issue, we think that it is because you are creating a PPT 2003 format file which cannot accept excel 2007 files. If you want to embed excel2007 files into you presentation, we think you should use PPTX file format.

If you want to use PPT format, then save the excel file in 2003 file format. Also, we tried embedding your template XLSX file into a PPT file by Aspose.Slides (without using Aspose.Cells) and the generated file gives the same error.

Also, please note that from Aspose.Cells V2.2.0, Workbook.save() method has been modified. In old versions, using Workbook.save() method without specifying the file format will save the resultant file as excel97-2007 file format automatically. But from 2.2.0, Workbook.save() method will save the Workbook as its original file format, if user does not specify the file format. So as per your sample code, the Workbook is opened as XLSX file, then Workbook.save() method will generate an XLSX file too.

Thank You & Best Regards,

Hi,

Thank you the reply.

I tried several different things(changing the PPT to PPTX, changing the EXCEL Format to match), but I could not successfully transform the xls to ppt or xlsx to pptx.

Please help.

Thanks

Priya

Hi,

You said that you could not even transform xls to ppt. Well, we don’t find the issue at all when converting xls file to ppt. Here is the sample code and attached is the generated ppt file, you may open into Powerpoint and click on the object, it works fine without any issue at all.

Sample code:

public class AsposePpt {
private Workbook templateWB;
public static void main(String args[]) throws Exception {
AsposePpt aspose = new AsposePpt();
aspose.loadTemplate(new FileInputStream(“d:\files\template.xlsx”));

aspose.exportToPpt(“d:\files\myrepport.ppt”, “SLIDE”);
}
public void loadTemplate(InputStream template) throws Exception {
templateWB = new Workbook();
templateWB.open(template, FileFormatType.EXCEL2007);

}

public void exportToPpt(String filename, String namePrefix) throws IOException {
Worksheets sheets = templateWB.getWorksheets();
NamedRange[] ranges = sheets.getNamedRanges();
Presentation presentation = new Presentation();
for (NamedRange range : ranges) {
if (!range.getText().startsWith(namePrefix)) {
continue;
}
int pageNum = Integer.parseInt(range.getText().substring(7));
Slide _next = presentation.getSlideByPosition(pageNum - 1);
while (_next == null || _next.getSlidePosition() < pageNum - 1) {
_next = presentation.addEmptySlide();
}
createSlide(range, _next, 50, 50, 5000, 2000);
}
presentation.write(new FileOutputStream(filename));
}

private void createSlide(NamedRange range, final ISlide slide, final int x, final int y,
final int h, final int w) throws IOException {
int startRow = range.getStartRow();
int endRow = range.getEndRow();
int startCol = range.getStartColumn();
int endCol = range.getEndColumn();
templateWB.setOleSize(startRow, Math.max(0, endRow), startCol,
Math.max(0, endCol));
ByteArrayOutputStream bout=new ByteArrayOutputStream();
templateWB.save(bout,FileFormatType.EXCEL97TO2003);
final OleObjectFrame oof = slide.getShapes().addOleObjectFrame(x, y, h, w, “Excel.Sheet.8”, bout.toByteArray());
// oof.setPictureId(slide.getParent().getPictures().get(0).getPictureId());
}

}


Thank you.

Thank you, that worked.

Are all the color pallette available in excel now available in conversion to powerpoint.

Thank you,

Priya

Hi Priya,

Well, yes, all the color information will be saved into the generated xls file, however, for those colors that are not in the MS Excel palette can only be shown as they are when opening the xls file into MS Excel 2007 or higher versions. This behavior is same as MS Excel versions.

Thanks for your understanding!