I use this version, aspose-cells-7.5.3.jar to convert simple excel file to pdf file.
It is ok in window 7 but got this error message in
Apache Tomcat/7.0.30 | 1.6.0_35-b10-428-11M3811 | Apple Inc. | Mac OS X | 10.8.2 | x86_64 |
com.aspose.cells.CellsException: File path can't be "". at com.aspose.cells.bdg.a(Unknown Source) at com.aspose.cells.Workbook.a(Unknown Source) at com.aspose.cells.Workbook.save(Unknown Source) at com.all.crm.service.ConvertOthersToPDF.xlsToPdf(ConvertOthersToPDF.java:276) at com.all.crm.service.ConvertOthersToPDF.process(ConvertOthersToPDF.java:98) at
My logic is below.
public void xlsToPdf() {
// TODO Auto-generated method stub
//Instantiate a Presentation object that represents a PPT file
try {
sheetNames = new ArrayList();
//Initialize a new Workbook
//Open an Excel file
Workbook workbook = new Workbook(baseFolder+ fileName);
WorksheetCollection worksheets = workbook.getWorksheets();
ArrayList subEntryList = new ArrayList();
//Create the PdfBookmark entry object.
PdfBookmarkEntry pbeRoot = new PdfBookmarkEntry();
//Set the bookmark collapsed.
pbeRoot.setOpen(false);
//Set its text.
pbeRoot.setText(fileName);
Cell cellInPage = null;
Row row = null;
//Set its destination source page.
pbeRoot.setDestination(cellInPage);
PdfBookmarkEntry subPbe = null;
for ( int i = 0; i < worksheets.getCount(); i++ ) {
Worksheet worksheet = worksheets.get(i);
cellInPage = getFirstNotHiddenCell(worksheet);
//Add another PdfBookmark entry object.
subPbe = new PdfBookmarkEntry();
//Set its text.
String sheetName = worksheet.getName();
if ( sheetName == null || sheetName.equals("") ) {
sheetName = "Sheet " + (i+1);
}
sheetNames.add(sheetName);
subPbe.setText(sheetName);
//Set its destination source page.
subPbe.setDestination(cellInPage);
//Add the entry objects to it.
subEntryList.add(subPbe);
}
pbeRoot.setSubEntry(subEntryList);
//Implement one page per worksheet option
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.setOnePagePerSheet(true);
//Set the pdf bookmarks, you need to specify the root object here.
pdfSaveOptions.setCompliance(1);
//pdfSaveOptions.setBookmark(pbeRoot);
///Save the pdf file
log.info("baseFodler filename="+this.baseFolder + pdfFileName);
workbook.save(this.baseFolder + pdfFileName, pdfSaveOptions);
//Save only one current worksheet
//workbook.save(baseFolder + pdfFileName, FileFormatType.PDF);
} catch ( Exception ex ) {
errorMessages.append(LF+"xlsToPdf error="+ex.getMessage());
log.info("xlsToPdf(),ex=" + MyUtil.exceptionLog(ex));
//ex.printStackTrace();
}
} // end of xlsToPdf