问题描述:

I am trying to extract "excel template" from the existing notes document to the file system and reading using Apache POI. I am trying to extract excel template only if it doesn't already exist in the directory, else trying to read from the same location but it's throwing null exception when it runs second time.

here is my code,

 //If it has an attachment

if (doc.hasEmbedded()) {

RichTextItem body = (RichTextItem)docTmpl.getFirstItem("Body");

Vector atts = body.getEmbeddedObjects();

EmbeddedObject att = (EmbeddedObject)atts.elementAt(0);

if ( att.getType() == EmbeddedObject.EMBED_ATTACHMENT ) {

String templatePath = "C:\\externalfiles\\excel\\" + att.getSource();

File f = new File( templatePath );

if(f.exists())

{

System.out.println("Template already exist,use existing one." + templatePath);

} else{

att.extractFile(templatePath);

}

XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(templatePath));

FileOutputStream fileOut = new FileOutputStream(fileName);

XSSFSheet sheet1 = wb.getSheet("General");

相关阅读:
Top