andrid 读取Word文件 (无格式)
来源:互联网 发布:铃声助手mac版 编辑:程序博客网 时间:2024/06/06 03:38
需要额JAR包
package other.a;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.model.FieldsDocumentPart;
import org.apache.poi.hwpf.usermodel.Field;
import org.apache.poi.hwpf.usermodel.Fields;
import org.apache.poi.hwpf.usermodel.Range;
public class Test2 {
public static void main(String[] args) {
try {
// 读取word模板
String fileDir = new File("../../../../../YQ/").getCanonicalPath();
FileInputStream in = new FileInputStream(new File(fileDir
+ "/模板.doc"));
HWPFDocument hdt = new HWPFDocument(in);
Fields fields = hdt.getFields();
Iterator<Field> it = fields.getFields(FieldsDocumentPart.MAIN)
.iterator();
while (it.hasNext()) {
System.out.println(it.next().getType());
}
// 读取word文本内容
Range range = hdt.getRange();
System.out.println(range.text());
// 替换文本内容
// for (Map.Entry<String,String> entry:map.entrySet()) {
// range.replaceText(entry.getKey(),entry.getValue());
// }
ByteArrayOutputStream ostream = new ByteArrayOutputStream();
String fileName = "" + System.currentTimeMillis();
fileName += ".doc";
FileOutputStream out = new FileOutputStream(fileDir + "/"
+ fileName, true);
hdt.write(ostream);
out.write(ostream.toByteArray());
out.close();
ostream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
- andrid 读取Word文件 (无格式)
- poi读取word简历(伪word格式的doc文件 )提取文本内容报错
- Andrid 资源文件 (images)
- word 无格式粘贴
- Java实现poi方式读取word文件内容(不带格式)
- JAVA读取word文件
- java读取word文件
- 读取word excel 文件
- Java读取Word文件
- 读取word excel 文件
- Android读取word文件
- c++读取word文件
- Android读取word文件
- C#读取Word文件
- Java读取word文件
- Andrid资源文件使用
- andrid 读取log代码实现
- C格式读取文件
- adb Install安装错误常见列表
- 特殊IP地址(保留IP地址)介绍
- 如何成为一名优秀的web前端工程师
- 软件项目管理体系
- 监控linux 网络流量
- andrid 读取Word文件 (无格式)
- 自己设计的一道ACM风格的程序设计训练题:大货车极限送货
- java 打jar包 (使用Eclipse)
- xcode代码提示功能失效的解决方法
- ListView创建列和设置数据并保存成xml
- jquery after append appendTo三个函数的区别
- asmlinkage如何理解
- POJ 3020 Antenna Placement
- vs2008编译出现错误 error C2220: 警告被视为错误 - 没有生成“object”文件