永发信息网

如何用POI3.0生成WORD文档

答案:1  悬赏:10  手机版
解决时间 2021-03-17 07:55
如何用POI3.0生成WORD文档
最佳答案
我最近也在学:仅有的一点资料
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);
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
巨人树幼儿园大同分园地址在什么地方,想过去
面试问题,请简单介绍下FPGA和PLC的区别,以
山东省2o16教师事业编考试试卷
引擎盖下面的减震顶胶开裂了,会不会有安全隐
全国妇联授予荣誉称号算不算国家级
结合自身谈谈如何实现人生价值
快批KP软件,是在电脑上用的批发管理软件吗?
约女朋友出来玩 她要么就很慢 要么就说想睡觉
x*(1/40)+1-x*(1/15)=25% 怎么解
网吧4元一个小时。然后活动是冲500送1000。
从青浦卫家角到郊野公园怎么走
北京世纪瑞凯人造毛绒有限公司怎么样?
去看房时怎么知道是大产权和小产权,说的通俗
《艾青诗选》里的好句?
塑料竹排怎么做?怎么固定PVC管才好?
推荐资讯
求一篇耽美文,古风的,开篇时攻找消失的恋人
油淋鱼的做法
如何用一个成语或者幽默的语句形容一下这几年
我经常头晕,头疼,失眠,多梦跟贫血有没有关
房玄龄多谋,杜如晦善断
一名文科生可以学动漫吗
最近很疲劳,想放松一下有什么好的方式吗
3.14x6x6x10x3/1-3.14x3x3x2=几
梦幻西游.100级的装备第四孔什么时候开的机率
日本塔罗牌占卜我从现在起做生意会有钱赚吗?
我想在网上买个赛克电动车48v的充电器应该咋
方圆玻璃行在哪里啊,我有事要去这个地方
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?