<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 5,  comments - 7,  trackbacks - 0
    import java.io.*
    import java.util.*
    import org.apache.poi.poifs.filesystem.*
    import org.apache.poi.util.LittleEndian; 

    public class WordTest 
    public WordTest() 
    }
     
    public static boolean writeWordFile(String path, String content) 
    boolean w = false
    try 

    // byte b[] = content.getBytes("ISO-8859-1"); 
    byte b[] = content.getBytes(); 

    ByteArrayInputStream bais 
    = new ByteArrayInputStream(b); 

    POIFSFileSystem fs 
    = new POIFSFileSystem(); 
    DirectoryEntry directory 
    = fs.getRoot(); 

    DocumentEntry de 
    = directory.createDocument("WordDocument", bais); 

    FileOutputStream ostream 
    = new FileOutputStream(path); 

    fs.writeFilesystem(ostream); 

    bais.close(); 
    ostream.close(); 

    }
     catch (IOException e) 
    e.printStackTrace(); 
    }
     
    return w; 
    }
     
    public static void main(String[] args)
    boolean b = writeWordFile("E://test.doc","hello"); 
    }
     
    }
     
    /* 
    public String extractText(InputStream in) throws IOException { 
    ArrayList text = new ArrayList(); 
    POIFSFileSystem fsys = new POIFSFileSystem(in); 

    DocumentEntry headerProps = (DocumentEntry) fsys.getRoot().getEntry("WordDocument"); 
    DocumentInputStream din = fsys.createDocumentInputStream("WordDocument"); 
    byte[] header = new byte[headerProps.getSize()]; 

    din.read(header); 
    din.close(); 
    // Prende le informazioni dall'header del documento 
    int info = LittleEndian.getShort(header, 0xa); 

    boolean useTable1 = (info & 0x200) != 0; 

    //boolean useTable1 = true; 

    // Prende informazioni dalla piece table 
    int complexOffset = LittleEndian.getInt(header, 0x1a2); 
    //int complexOffset = LittleEndian.getInt(header); 

    String tableName = null; 
    if (useTable1) { 
    tableName = "1Table"; 
    } else { 
    tableName = "0Table"; 


    DocumentEntry table = (DocumentEntry) fsys.getRoot().getEntry(tableName); 
    byte[] tableStream = new byte[table.getSize()]; 

    din = fsys.createDocumentInputStream(tableName); 

    din.read(tableStream); 
    din.close(); 

    din = null; 
    fsys = null; 
    table = null; 
    headerProps = null; 

    int multiple = findText(tableStream, complexOffset, text); 

    StringBuffer sb = new StringBuffer(); 
    int size = text.size(); 
    tableStream = null; 

    for (int x = 0; x < size; x++) { 

    WordTextPiece nextPiece = (WordTextPiece) text.get(x); 
    int start = nextPiece.getStart(); 
    int length = nextPiece.getLength(); 

    boolean unicode = nextPiece.usesUnicode(); 
    String toStr = null; 
    if (unicode) { 
    toStr = new String(header, start, length * multiple, "UTF-16LE"); 
    } else { 
    toStr = new String(header, start, length, "ISO-8859-1"); 

    sb.append(toStr).append(" "); 


    return sb.toString(); 


    private static int findText(byte[] tableStream, int complexOffset, ArrayList text) 
    throws IOException { 
    //actual text 
    int pos = complexOffset; 
    int multiple = 2; 
    //skips through the prms before we reach the piece table. These contain data 
    //for actual fast saved files 
    while (tableStream[pos] == 1) { 
    pos++; 
    int skip = LittleEndian.getShort(tableStream, pos); 
    pos += 2 + skip; 

    if (tableStream[pos] != 2) { 
    throw new IOException("corrupted Word file"); 
    } else { 
    //parse out the text pieces 
    int pieceTableSize = LittleEndian.getInt(tableStream, ++pos); 
    pos += 4; 
    int pieces = (pieceTableSize - 4) / 12; 
    for (int x = 0; x < pieces; x++) { 
    int filePos = 
    LittleEndian.getInt(tableStream, pos + ((pieces + 1) * 4) + (x *<img src="/images/forum/smiles/icon_cool.gif"/> + 2); 
    boolean unicode = false; 
    if ((filePos & 0x40000000) == 0) { 
    unicode = true; 
    } else { 
    unicode = false; 
    multiple = 1; 
    filePos &= ~(0x40000000); //gives me FC in doc stream 
    filePos /= 2; 

    int totLength = 
    LittleEndian.getInt(tableStream, pos + (x + 1) * 4) 
    - LittleEndian.getInt(tableStream, pos + (x * 4)); 

    WordTextPiece piece = new WordTextPiece(filePos, totLength, unicode); 
    text.add(piece); 




    return multiple; 

    public static void main(String[] args){ 
    WordTest w = new WordTest(); 
    POIFSFileSystem ps = new POIFSFileSystem(); 
    try{ 

    File file = new File("C:\\test.doc"); 

    InputStream in = new FileInputStream(file); 
    String s = w.extractText(in); 
    System.out.println(s); 


    }catch(Exception e){ 
    e.printStackTrace(); 



    public boolean writeWordFile(String path, String content) { 
    boolean w = false; 
    try { 

    // byte b[] = content.getBytes("ISO-8859-1"); 
    byte b[] = content.getBytes(); 

    ByteArrayInputStream bais = new ByteArrayInputStream(b); 

    POIFSFileSystem fs = new POIFSFileSystem(); 
    DirectoryEntry directory = fs.getRoot(); 

    DocumentEntry de = directory.createDocument("WordDocument", bais); 

    FileOutputStream ostream = new FileOutputStream(path); 

    fs.writeFilesystem(ostream); 

    bais.close(); 
    ostream.close(); 

    } catch (IOException e) { 
    e.printStackTrace(); 


    return w; 




    class WordTextPiece { 
    private int _fcStart; 
    private boolean _usesUnicode; 
    private int _length; 

    public WordTextPiece(int start, int length, boolean unicode) { 
    _usesUnicode = unicode; 
    _length = length; 
    _fcStart = start; 

    public boolean usesUnicode() { 
    return _usesUnicode; 


    public int getStart() { 
    return _fcStart; 

    public int getLength() { 
    return _length; 



    */
     
    posted on 2008-11-29 09:55 Vincent-chen 閱讀(4190) 評(píng)論(1)  編輯  收藏 所屬分類(lèi): POI
    主站蜘蛛池模板: 99精品视频在线视频免费观看| 亚洲精品无码成人AAA片| 天天影视色香欲综合免费| 99久久免费中文字幕精品| 91在线视频免费看| 91免费在线播放| 久久99青青精品免费观看| 免费国产成人α片| 久久精品电影免费动漫| 一区二区三区四区免费视频| 99视频在线免费| 亚洲免费黄色网址| 永久免费的网站在线观看| 欧美三级在线电影免费| 在线精品免费视频无码的| 国产免费怕怕免费视频观看| 亚洲精品国产精品乱码不卞| 亚洲人成网亚洲欧洲无码久久| 亚洲综合伊人久久大杳蕉| 亚洲va久久久噜噜噜久久狠狠| 亚洲AV日韩AV永久无码下载| 久久久影院亚洲精品| 久久精品亚洲一区二区三区浴池| 久久久久亚洲精品日久生情 | 国产亚洲欧美在线观看| 国产精品亚洲综合网站| 一级成人a做片免费| 成全动漫视频在线观看免费高清版下载 | 视频一区在线免费观看| 国产亚洲一卡2卡3卡4卡新区| 黄色网址大全免费| 两个人看的www免费视频中文| 久久综合给合久久国产免费| 国产精品成人免费一区二区| 免费人成无码大片在线观看| 亚洲欧洲日产国码无码网站| 亚洲黄色在线播放| 亚洲精华国产精华精华液好用| 成人久久久观看免费毛片| 一区二区三区观看免费中文视频在线播放 | 日本高清免费aaaaa大片视频|