首先我用的技术是 poi
这是代码,一个工具类得调用
public class WordUtil {
/**
* 基于模板文件导出 word 文档,此方法主要是用来处理文档中需要替换的文本内容,对图片和表格无效
*
* @param templatePath
* 模板文件的路径,要求路径中要包含全名,并且模板文件只能是 07 及以上格式,即 docx 的文件
* @param destFilePath
* 导出文件的存放路径,包含文件名,例如,E:/test/小区公告.docx
* @param data
* 用来替换文档中预定义的字符串,要求预定义的字符串与 data 中的 key 值要相同
*/
public static void exportWordByTemplate(String templatePath,
String destFilePath, Map<String, String> data) {
FileOutputStream out = null;
XWPFDocument doc = null;
try {
doc = new XWPFDocument(POIXMLDocument.openPackage(templatePath));
List<XWPFRun> listRun;
List<XWPFParagraph> listParagraphs = doc.getParagraphs();
for (int i = 0; i < listParagraphs.size(); i++) {
listRun = listParagraphs.get(i).getRuns();
for (int j = 0; j < listRun.size(); j++) {
if (data.get(listRun.get(j).getText(0)) != null) {
String val = data.get(listRun.get(j).getText(0));
listRun.get(j).setText(val, 0);
}
}
}
File destFile = new File(destFilePath);
if (!destFile.getParentFile().exists()) {
destFile.getParentFile().mkdirs();
}
out = new FileOutputStream(destFilePath);
doc.write(out);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (out != null)
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 基于模板文件导出 word 文档,该方法支持03格式,但是此方法只能保留文档内容,不能保留文档中的样式和图片,建议将模板使用 07 的格式保存
*
* @param templatePath
* 模板文件的路径
* @param destFilePath
* 导出文件的存放路径,包含文件名,例如,E:/test/小区公告.doc
* @param data
* 用来替换文档中预定义的字符串,要求预定义的字符串与 data 中的 key 值要相同
*/
public static void export03WordByTemplate(String templatePath,
String destFilePath, Map<String, String> data) {
try {
WordExtractor doc = new WordExtractor(new FileInputStream(
templatePath));
String content = doc.getText();
for (String key : data.keySet()) {
content = content.replaceAll(key, data.get(key));
}
byte b[] = content.getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(b);
POIFSFileSystem fs = new POIFSFileSystem();
DirectoryEntry directory = fs.getRoot();
directory.createDocument("WordDocument", bais);
FileOutputStream ostream = new FileOutputStream(destFilePath);
fs.writeFilesystem(ostream);
bais.close();
ostream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
Map<String, String> maps = new HashMap<String, String>();
maps.put("appellation", "万达公寓业主:");
maps.put(
"main_body",
"输出的内容");
maps.put("date", "2013年1月23日");
exportWordByTemplate("E:/sss 2.docx", "E:/test/test.doc", maps);
}
}
"E:/sss 2.docx 模板存放的地址。
E:/test/test.doc 新生成的地址。
阿帕奇的这个支持导PDF格式的吗
如何导出word的帮助文件
如果是装在C盘的,文件在以下路径C:\Program Files\Microsoft Office\OFFICE11\2052,下面的文件名为"WDMAIN11"的HTML帮助文件
如果在其他盘的,也是在\Microsoft Office\OFFICE11\2052下找
word中怎么导出图片的三种方法
方法一:
1、右键点击Word文档中的图片,点击其中的“另存为图片”。
2、然后在打开的对话框中选择保存路径,点击保存即可将图片保存到电脑中。
方法二:
1、点击Word页面左上角的“文件”,在打开的页面中点击“另存为”选项。
2、然后在打开的保存对话框中选择“网页”,点击保存按钮。
3、在保存路径处找到保存网页的文件夹。
4、打开文件夹即可看到插入在文档中的图片,该图片已经被导出到电脑中了。
方法三:
1、复制Word文档中的图片。
2、打开电脑中的画图工具,将复制的图片粘贴上后点击保存即可。
请教java html导出word如何实现
java将html导出word不用忘记<html></html>这对标签
//换页
<span style='font-size:16px;line-height:150%;font-family:"Times New Roman";
mso-fareast-font-family:宋体;mso-font-kerning:1px;mso-ansi-language:EN-US;
mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA'><br clear=all style='mso-special-character:page-break;page-break-before:always'>
</span>
//换行
<p style='line-height:150%'><span style='font-size:16px;line-height:150%'><o:p> </o:p></span></p>
查看的话 打开word 视图——页面 就能看出看出效果
[java] view plain copy print?
ArrayList records = form.getRecords();//获取数据库数据
if(null!=records&&0!=records.size()){
//html拼接出word内容
String content="<html>";
for (int i = 0; i < records.size(); i++) {
Record record =(Record) records.get(i);
//从数据库中获得数据,将oracle中的clob数据类型转换成string类型
Method method = record.get("CONTENT").getClass().getMethod("getVendorObj",new Class[]{});
CLOB clob = (CLOB)method.invoke(record.get("CONTENT"));
String cx = clob.getSubString((long) 1, (int) clob.length());
String title= (String) record.get("TITLE");
//html拼接出word内容
content+="<div style=\"text-align: center\"><span style=\"font-size: 24px\"><span style=\"font-family: 黑体\">"+title+"<br /> <br /> </span></span></div>";
content+="<div style=\"text-align: left\"><span >"+cx+"<br /> <br /> </span></span></div>";
//插入分页符
content+="<span lang=EN-US style='font-size:16px;line-height:150%;mso-fareast-font-family:宋体;mso-font-kerning:1px;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA'><br clear=all style='page-break-before:always'></span>";
content+="<p class=MsoNormal style='line-height:150%'><span lang=EN-US style='font-size:16px;line-height:150%'><o:p> </o:p></span></p>";
}
content += "</html>";
byte b[] = content.getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(b);
POIFSFileSystem poifs = new POIFSFileSystem();
DirectoryEntry directory = poifs.getRoot();
DocumentEntry documentEntry = directory.createDocument("WordDocument", bais);
//输出文件
String name="导出知识";
response.reset();
response.setHeader("Content-Disposition",
"attachment;filename=" +
new String( (name + ".doc").getBytes(),
"iso-8859-1"));
response.setContentType("application/msword");
OutputStream ostream = response.getOutputStream();
//输出文件的话,new一个文件流
//FileOutputStream ostream = new FileOutputStream(path+ fileName);
poifs.writeFilesystem(ostream);
ostream.flush();
ostream.close();
bais.close();
texlive怎么导出word
1.百度搜索下载工具:“Tex2Word20”并下载。
2.加压后,安装“Tex2Word20”,使用默认安装路径。
3.安装过程中,选试用安装,如下图所示。
4.安装好后,接下来就是破解该软件了,按照上面的步骤软件被安装到下面3个文件夹:
1)C:\Program Files\tex2word
2)C:\Program Files\Microsoft Office\OFFICE11\STARTUP\
3)C:\Program Files\Common Files\Microsoft Shared\TEXTCONV
5.只需要用破解了的tex2word.cnv代替第3个文件夹中的同名文件。
6.文件安装完成,破解之后,新建一个word文档。
7.打开word文档,“文件”——“打开”,弹出一个对话框,在“文件类型”对话框中选“Tex(*.tex)”,然后找到所需要转化的Tex文件,点“打开”就能转化了。
8.转化后的word文档,如下图所示。
如何把word中的图片导出并保存?
在word中将文档另存为网页文件,那么word中的图片就会出现在网页附带的文件夹中,具体操作请参照以下步骤。
1、在电脑上打开需要保存图片的word文档,点击界面左上角的“Office按钮”图标。
2、然后在其下拉框中,依次点击“另存为/其他格式”选项。
3、在另存为页面中,选择文件保存位置,再在“保存类型”右边的下拉框中选择“网页”,点击“保存”进行确定。
4、找到word文档保存的位置,可以发现多了一个文件夹。
5、打开文件夹,就能看到word文档里面的图片已经成功保存。完成以上设置后,即可把word中的图片导出并保存。
怎样将手机中的word文档导出到电脑上
如果电脑上安装了Word软件,电脑可以打开手机上的word文档。具体方法如下:
1、用USB数据线把手机连到电脑,电脑能够识别出手机,手机端选择连接类型(如USB盘,MTP设备),双击打开手机存储;
2、找到word文档,双击就可以打开,编辑;
3、也可以把word文档复制到电脑上编辑存储。
如何将网页文件导出到word中
工具/原料
Google Chrome
WORD
方法/步骤
打开需要保存的网页,用快捷键Ctrl + S保存网页,选择保存“全部网页”。
保存后的文件
打开WORD,按ctrl+o,找到保存了网页HTML文件的文件夹,选中HTML文件,单击打开。
此时WORD打开了网页文件。下面就将网页文件另存为成docx。
转载请注明出处51数据库 » xwpfparagraph导出word java导出word表格