问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

急求POI 将数据导出到Word的实例

发布网友 发布时间:2022-04-23 05:05

我来回答

1个回答

热心网友 时间:2023-06-22 20:31

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 s = new ByteArrayInputStream(b);

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

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

FileOutputStream ostream = new FileOutputStream(path);

fs.writeFilesystem(ostream);

s.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 s = new ByteArrayInputStream(b);

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

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

FileOutputStream ostream = new FileOutputStream(path);

fs.writeFilesystem(ostream);

s.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;
}

}
*/
利用POI技术从数据库里提取数据,生成一个Excel文档或者Word文档

import org.apache.poi.hssf.usermodel.HSSFSheet;import org.apache.poi.hssf.usermodel.HSSFWorkbook;import org.apache.poi.hwpf.extractor.WordExtractor;import org.apache.poi.poifs.filesystem.DirectoryEntry;import org.apache.poi.poifs.filesystem.DocumentEntry;import org.apache.poi.poifs.filesystem...

...poit里的内容全部快速地、一次性地拷进word的文档里?各位高手有办法...

1.在powerpoit里面按 文件-保存为(有的是换名保存或是另保存)。2.然后会弹出一个界面,在你输入名字的地方下面,有一个叫保存类型的,拉下去。3.然后选择word的方式就可以了。如果你的不是2003的也行。也是刚刚的方法把powerpoit保存成JPEG文件交换格式,然后在word保存就可以了。

如何用POI3.0生成WORD文档

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...

用JSP如何实现将查询出来的数据导入到Word文档中

2-纯JavaScript脚本实现。主要通过客户端调用本机Office组件来实现。3-在JSP页面引入头文件实现。纯JavaScript脚本实现细节方面大体是创建一个word组件ActiveXObject('Word.Application'),用js通过表ID取得表内容然后保存到word,要注意的是js实现有很多不好的地方,例如Internet选项需要把ActiveX空间全部启用,安...

将JSP页面(里面含有表格,表格数据是从数据库导出的)导出成Word

用最新版本的POI是支持到word2007的,如果你尝试后还不行,给我留言,我给你word2007的全套解析,你可以尝试自己写一套解析代码出来。

如何使用POI操作Word文本框中的内容

FileInputStream fis = new FileInputStream("e:/file.docx");XWPFDocument doc = new XWPFDocument(fis);List&lt;XWPFParagraph&gt; paragraphList = doc.getParagraphs();XWPFParagraph paragraph = paragraphList.get(10);文本框在Word中显示如图所示:第二步,获取XWPFParagraph的XmlObject,然后获得XmlObject对象...

java编程:有人做过导出word文件,并且word中附带excel文件的那种模式吗...

假如是.docx文件,用XWPFDocument 这个就可以,poi里面的类 然后是XWPFTable,XWPFTableRow,XWPFTableCell类。分别获得表格,表格的行,表格的格 doc就多了,网上随便找 但是假如又有段落还有表格,我也卡在这了,假如找到方法,麻烦提醒我一下!!

...在数据库读取的多条BLOB 数据一同插入一个word 中,并打印出来_百度...

首先从数据库里读取出来,然后写到word中(通过apache poi jar包),里面有一些列操作office套件的接口

java中如何用jacob将数据库中的二进制图片存到word中的指定位置

主要用到org.apache.poi 来操作word,而读取数据库图片 通过读取数据库Blob 字段的列然后通过 public static BufferedImage imgChangeBuffer(Blob blob)方法钩子一个 BufferedImage 然后把这个 BufferedImage 设置到word中,希望能帮上忙。

poihtml生成横向word

方式如下:1、首先比如有一篇文章的前边设置一个方向,如横向,然后后边都设置为纵向,这样可以先将插入点定位到纵向页面的结尾,2、当然也可以将所有内容全部圈起来,然后在应用于中选中所选文字进行更改,3、如果文章内容中有许多小节,也还可以选中你要更改的节,然后就点击应用于之后的所选节进行更改...

身边大数据应用的实例 数据库的应用实例 数据库在生活中的实例 数据导出到excel oracle导出表数据 数据库实例 大数据的实际运用 数据处理的应用举例 面板数据回归分析实例
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
当前我国经济工作的主线是什么 空调几匹最合适房间 高考时带手表进考场会被监考老师没收吗? 大方县办营业执照在哪里呀 石林县城办营业执照在哪里 家里潮湿有味道怎么办 家里潮湿有味道怎么改善 蛋糕的做法家庭做法蒸蛋糕 黄煌经方沙龙(第一期)        目录       _百... 如何为朋友妈妈庆祝生日呢? 大学班长生日祝福语 给小阿姨的生日祝福语 使用poi 如何在生成word 添加横线?像图里的那样 java poi 生成word表格怎么 让表格填充整个页面和合并单元格 poi 根据模板导出word POI 生成WORD文档?为什么WORD文档打不开 java用poi导出word文档,我要导出一个表格,表格的单元格中还要有一个表格,请问怎么实现 如何用POI3.0生成WORD文档 Java 利用poi 可以直接读取word中的表格保持样式生成新的word么? poi 生成目录位置不对 OPPO Reno5在什么情况下会发烫? OPPO Reno5系列新手机有什么黑科技? OPPO Reno5玩一会儿就发热,怎么办? 高马尾扎发,给人一种蓬松减龄的的少女感,怎么梳最好看? 头发怎么扎好看又简单?求方法。 波波头夏天太热,怎样编扎时尚又凉爽?有简单实用的编发教程吗? 东莞市劳动法年薪假规定 东莞灵活就业人员社保2021年缴费标准 东莞南城街道2020-2021年度&quot;红领奖章&quot;推荐表怎么填 2021年东莞高新技术企业申报什么时候开始? 2011东莞市上年度的社平工资是多少 附东莞市2020-2021年度红领巾奖章个人三星章候选人 java poi模板导出word后用微软的word打不开,但是wps可以,跪求大牛解决一下,不胜感激。 使用poi3.17导出word后,用office软件打开正常,用wps软件打开后,页眉页脚都不显示,知道是什么情况吗? java中怎么使用poi创建,编辑word文档 poi 生成word时如何设置标题 org.apache.poi如何到处word java用poi生成word文档,并且给word文档中的中文设置字体,我测试只能改... 新手第一次美瞳怎么戴? 美瞳正确的戴法是怎样的? 美瞳正确的戴法? 美瞳的配戴法和取法 美瞳使用方法介绍,正确的配戴法和取法是什么? 怎么戴美瞳?美瞳正确的戴法是什么样的,麻烦知道的告诉我一下 word中线条粗细为3磅怎么设置? 美瞳的戴法 如何改变EXCEL表格线条的粗细? 笔记本电脑没有硬盘能用吗? 怎么带美瞳 奇异果的营养价值是什么? 美瞳的正确戴法 美瞳的正确带法