1.POI3.5之后可支持docx、xlsx、pptx等格式格式
HSSF:ms-excel97~2003(.xls)
XSSF:ms-excel2007+(.xlsx)
HWPF:ms-word97~2003(.doc)
XWPF:ms-word2007+(.docx)
HSLF:ppt
XSLF:pptx
2.加入jar包,我做的是对于doc、docx、xls、xlsx文档,总共加入了以下9个jar包:
poi(5个):poi,poi-excelant,poi-ooxml,poi-ooxml-schemas,poi-scratchpad
xmlbeans:为了支持高版本的word与excel
dom4j
commons-fileupload,commons-io:上传与读写
3.对于excel,支持03及07版本
Workbook wb = null; try{wb = new XSSFWorkbook(filePath); }catch (Exception e){ wb = new HSSFWorkbook(new FileInputStream(filePath)); }
4.对于文件下载,先获取后缀名,再设置contentType,设置的值参照tomcat/conf下面的web.xml中的mime类型,如:
response.setContentType("application/msword"); //word2003
5.session获取项目根路径:
String appPath = session.getServletContext().getRealPath(String.valueOf(File.separatorChar));
具体可参照以下文档:
poi与office.pdf