资源简介

JAVA用poi解析doc、docx、slx、xlsx,代码我整合在一个类中,生成的是一个html,自己仔细阅读,大部分功能都能实现了,附带了POI3.8给大家

资源截图

代码片段和文件信息

import java.awt.Image;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;

import org.apache.poi.POIxmlDocument;
import org.apache.poi.POIxmlTextExtractor;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellstyle;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.hssf.usermodel.HSSFPalette;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.CharacterRun;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.Picture;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.hwpf.usermodel.Table;
import org.apache.poi.hwpf.usermodel.TableCell;
import org.apache.poi.hwpf.usermodel.TableIterator;
import org.apache.poi.hwpf.usermodel.TableRow;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.xml.*;






public class Read {
private  String nameStr;
public Range range = null;
public HWPFDocument hwpf = null;
public String htmlPath;
public String picturePath;

public List pictures;
public TableIterator tableIterator;
public int presentPicture = 0;
public int screenWidth;
public FileOutputStream output;
public File myFile;
StringBuffer lsb = new StringBuffer();

OutputStreamWriter out1;
BufferedWriter bw;
String content;
public static void main(String[] args) {
Read r=new Read();


}
public Read(){
nameStr = “I:\\Test.doc“;
read();
}
public  void read(){
if(nameStr.endsWith(“.doc“)){
getRange();
makeFile();
this.readDOC();
System.out.println(“htmlPath“ + this.htmlPath);
}
if(this.nameStr.endsWith(“.docx“)){

try {
this.makeFile();
this.readDOCX();
writeHTML();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printSta

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-01-28 10:32  READ\
     目录           0  2013-01-28 10:29  READ\Fileread\
     文件        1138  2013-01-28 09:34  READ\Fileread\.classpath
     文件         384  2013-01-24 14:44  READ\Fileread\.project
     目录           0  2013-01-28 10:29  READ\Fileread\.settings\
     文件         598  2013-01-24 14:44  READ\Fileread\.settings\org.eclipse.jdt.core.prefs
     目录           0  2013-01-28 10:29  READ\Fileread\bin\
     文件        5544  2013-01-28 09:34  READ\Fileread\bin\Excel.class
     文件       21983  2013-01-28 09:34  READ\Fileread\bin\Read.class
     文件        6593  2013-01-28 09:34  READ\Fileread\bin\word.class
     目录           0  2013-01-28 10:30  READ\Fileread\src\
     文件       23418  2013-01-26 16:54  READ\Fileread\src\Read.java
     目录           0  2013-01-28 10:32  READ\poi-3.8\
     文件       27138  2012-03-17 16:14  READ\poi-3.8\LICENSE
     文件         890  2012-03-17 16:14  READ\poi-3.8\NOTICE
     目录           0  2013-01-28 10:32  READ\poi-3.8\docs\
     目录           0  2013-01-28 10:32  READ\poi-3.8\docs\apidocs\
     文件      253044  2012-03-17 18:06  READ\poi-3.8\docs\apidocs\allclasses-frame.html
     文件      220024  2012-03-17 18:06  READ\poi-3.8\docs\apidocs\allclasses-noframe.html
     文件     1393316  2012-03-17 18:05  READ\poi-3.8\docs\apidocs\constant-values.html
     文件      120002  2012-03-17 18:06  READ\poi-3.8\docs\apidocs\deprecated-list.html
     文件       10098  2012-03-17 18:06  READ\poi-3.8\docs\apidocs\help-doc.html
     文件     7757667  2012-03-17 18:06  READ\poi-3.8\docs\apidocs\index-all.html
     文件        1441  2012-03-17 18:06  READ\poi-3.8\docs\apidocs\index.html
     目录           0  2013-01-28 10:31  READ\poi-3.8\docs\apidocs\org\
     目录           0  2013-01-28 10:31  READ\poi-3.8\docs\apidocs\org\apache\
     目录           0  2013-01-28 10:32  READ\poi-3.8\docs\apidocs\org\apache\poi\
     文件       10706  2012-03-17 18:04  READ\poi-3.8\docs\apidocs\org\apache\poi\EncryptedDocumentException.html
     文件       11249  2012-03-17 18:04  READ\poi-3.8\docs\apidocs\org\apache\poi\OldFileFormatException.html
     文件       31664  2012-03-17 18:04  READ\poi-3.8\docs\apidocs\org\apache\poi\POIDocument.html
     文件       19042  2012-03-17 18:04  READ\poi-3.8\docs\apidocs\org\apache\poi\POIOLE2TextExtractor.html
............此处省略4242个文件信息

评论

共有 条评论