当前位置: 代码迷 >> Java Web开发 >> java中怎么使用poi创建、编辑word文档! (急@@@)
  详细解决方案

java中怎么使用poi创建、编辑word文档! (急@@@)

热度:73   发布时间:2016-04-17 15:42:47.0
求助:java中如何使用poi创建、编辑word文档!!! (急....@@@)
如题:
        java中如何使用poi创建、编辑word文档!!!  

        哪位有例子代码请贴一下,多谢!!!!!!!

------解决方案--------------------
poi项目应该自带例子,里面应该有实例代码
------解决方案--------------------
如何在Java内嵌入PPT
http://blog.csdn.net/bovy/archive/2007/04/06/1554922.aspx
把Word/Excel/Power Point嵌入到Java程序内
http://blog.csdn.net/bovy/archive/2007/04/06/1554447.aspx
------解决方案--------------------
我最近也在学:仅有的一点资料
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);
  相关解决方案