我想保存Excel(xls / HSSF)中没有扩展名的所有附件。 我现在已经尝试了很长时间,我真的不知道这是否可能。我也尝试了Apache Tika,但我不想使用Tika,因为无论如何我还需要POI来执行其他任务。
我尝试了Busy Developers Guide中的示例代码,但这不会提取旧办公室格式的文件(doc,ppt,xls)。并且在尝试创建new SlideShow(new HSLFSlideShow(dn, fs))
错误时会引发错误:(Remove argument to match HSLFSlideShow(dn))
我的实际代码是:
public static void saveEmbeddedXLS(InputStream fis_param, String embDIR) throws IOException, InvalidFormatException{
//HSSF - XLS
int i = 0;
System.out.println("Starting Embedded Search in xls...");
POIFSFileSystem fs = new POIFSFileSystem(fis_param);//create FileSystem using fileInputStream
HSSFWorkbook workbook = new HSSFWorkbook(fs);
for (HSSFObjectData obj : workbook.getAllEmbeddedObjects()) {
System.out.println("Objects : "+ obj.getOLE2ClassName());//the OLE2 Class Name of the object
String oleName = obj.getOLE2ClassName();//Document Type
DirectoryNode dn = (DirectoryNode) obj.getDirectory();//get Directory Node
//Trying to create an input Stream with the embedded document, argument of createDocumentInputStream should be: String; Where/How can I get this correct parameter for the function?
InputStream is = dn.createDocumentInputStream(dn);//This line is incorrect! How can I do i correctly?
FileOutputStream fos = new FileOutputStream("embDIR" + i);//Outputfilepath + Number
IOUtils.copy(is, fos);//FileInputStream > FileOutput Stream (save File without extension)
i++;
}
}
所以我的简单问题是: 是否可以在没有任何扩展名的情况下保存xls文件中的所有附件(尽可能简单)?任何人都可以为我提供解决方案吗?非常感谢!