<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
    主站蜘蛛池模板: 亚洲中文字幕久在线| 亚洲区小说区激情区图片区| 丰满亚洲大尺度无码无码专线 | 免费视频中文字幕| 一区二区三区免费在线视频 | 亚洲日韩欧洲无码av夜夜摸| 99久久久国产精品免费蜜臀| 色偷偷噜噜噜亚洲男人| 亚洲αv在线精品糸列| 女人18毛片特级一级免费视频| 久久久久女教师免费一区| 91亚洲国产成人久久精品| 亚洲国产天堂久久综合| 亚欧色视频在线观看免费| 污视频网站免费在线观看| 亚洲日产2021三区在线| 中文字幕亚洲一区二区三区| 久9久9精品免费观看| 无码人妻精品中文字幕免费| 亚洲另类无码专区首页| 亚洲gv猛男gv无码男同短文| 国产一级理论免费版| 91免费国产自产地址入| aaa毛片免费观看| 亚洲Av无码国产一区二区| 亚洲高清无在码在线无弹窗 | 亚洲日韩乱码中文无码蜜桃| 国产成人毛片亚洲精品| 午夜电影免费观看| 2022久久国产精品免费热麻豆| 一个人看的www在线免费视频| 亚洲夂夂婷婷色拍WW47| 亚洲国产人成在线观看69网站| 亚洲国产精品无码久久九九| 成人性生免费视频| 99视频全部免费精品全部四虎| 丁香花在线视频观看免费| 免费大片av手机看片高清| 亚洲heyzo专区无码综合| 亚洲H在线播放在线观看H| 久久亚洲中文字幕精品有坂深雪|