用户登录
用户注册

分享至

poi生产word文档

  • 作者: 自摸白板
  • 来源: 51数据库
  • 2020-04-21

1.java 代码生成word文件

没定格式的话可以再jsp页面添加这段:

<%

response.reset();

response.setContentType("application/vnd.ms-excel;charset=utf-8");

java.util.Date date = new Date();

DateFormat df = new SimpleDateFormat("yyyyMMddhhmmss");

String Starttime = df.format(date).toString();

response.setHeader("Content-disposition", "attachment; filename=GroupingInformation_"+ Starttime + ".doc");

%>

如果要定好格式的话,只有自己去看poi比较复杂。(但是用习惯了就没大问题了。)

poi后台:

导出第三句是格式,这个自己去试试。

2.如何用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);。

3.怎么用java poi生成word表格

rt java.util.Iterator;

import java.util.List;

import java.util.Map;

import java.util.regex.Matcher;

import java.util.regex.Pattern;

public class XwpfTUtil {

/*String filePath = "/sta.docx";

InputStream is;

XWPFDocument doc;

Mapparams = new HashMap();

{

params.put("${name}", "xxx");

params.put("${sex}", "男");

params.put("${political}", "共青团员");

params.put("${place}", "sssss");

params.put("${classes}", "3102");

params.put("${id}", "213123123");

params.put("${qq}", "213123");

params.put("${tel}", "312313213");

params.put("${oldJob}", "sadasd");

params.put("${swap}", "是");

params.put("${first}", "asdasd");

params.put("${second}", "综合事务部");

params.put("${award}", "asda");

params.put("${achievement}", "完成科协网站的开发");

params.put("${advice}", "没有建议");

4.怎样用poi在word中生成表格

关键代码如下:FileInputStream fileInputStream = new FileInputStream( soureFile);POIFSFileSystem pfs = new POIFSFileSystem( fileInputStream );HWPFDocument hwpf = new HWPFDocument(pfs);// make a HWPFDocument objectOutputStream output = new FileOutputStream( targetFile );hwpf.write(output);// write to the target fileoutput.close();(2)再word中插入表格。

HWPF的情况:Table tcDataTable = range.insertTableBefore( (short)column , row);//column and row列数和行数tcDataTable.getRow(i).getCell(j).getParagraph(0).getCharacterRun(0).insertBefore("插入i行j列的内容" );XWPF的情况:String outputFile = "D:\\test.doc";XWPFDocument document = new XWPFDocument();XWPFTable tableOne = document.createTable();XWPFTableRow tableOneRowOne = tableOne.getRow(0);tableOneRowOne.getCell(0).setText("11");XWPFTableCell cell12 = tableOneRowOne.createCell();cell12.setText("12");// tableOneRowOne.addNewTableCell().setText("第1行第2列");// tableOneRowOne.addNewTableCell().setText("第1行第3列");// tableOneRowOne.addNewTableCell().setText("第1行第4列");XWPFTableRow tableOneRowTwo = tableOne.createRow();tableOneRowTwo.getCell(0).setText("21");tableOneRowTwo.getCell(1).setText("22");// tableOneRowTwo.getCell(2).setText("第2行第3列");XWPFTableRow tableOneRow3 = tableOne.createRow();tableOneRow3.addNewTableCell().setText("31");tableOneRow3.addNewTableCell().setText("32");FileOutputStream fOut;try {fOut = new FileOutputStream(outputFile);document.write(fOut); fOut.flush();// 操作结束,关闭文件fOut.close();} catch (Exception e) {e.printStackTrace();}。

5.使用poi 如何在生成word 添加横线

在一篇Word文档中,一般情况下我们将所有页面均设置为横向或纵向。

但有时也需要将其中的某些页面设置为其它页面方向不同,或者根本就是没有规律,横向与纵向的页面掺杂在一起。那么如何才能让一个Word文档中同时存在横向和纵向两种方向的页面呢?能不能随心所欲地调整页面方向呢? 细心的读者可能会发现,当选择菜单命令“文件”|“页面设置”,打开“页面设置”对话框后,在其左下方有一个“应用于”下拉列表。

使用这个下拉列表,我们可以任意设置页面的方向。分不同情况介绍如下。

(1)如果一篇文章的前边设置一个方向,如纵向,而后边都设置为横向,则可以先将插入点定位到纵向页面的结尾,或要设置为横向页面的页首,在“页面设置”对话框中单击“横向”,然后在“应用于”下拉列表中选择“插入点之后”。 (2)如果要将某些选定的页面设置为某一个方向,可以先选中这些页面中所有的内容,然后在“应用于”下拉列表中选择“所选文字”。

(3)如果文档中以标题样式分为许多小节,可以选中要改变页面方向的节,然后在“应用于”下拉列表中选择“所选节”。如果不选某节,而只是将插入点定位到该节中,则还可以选择“本节”。

设置完成后,可以在预览视图中适当缩小显示比例,查看更改的结果,如图中所示。 推而广之,其实不仅可以将页面方向任意地应用到不同的页面,“页面设置”对话框中的其它设置选项,如纸张类型、版式、页边距等,都可以类似地对不同页面采用不同的设置,读者朋友不妨试一下。

6.POI组件怎样使生成的word文档横向排版

在一篇Word文档中,一般情况下我们将所有页面均设置为横向或纵向。

但有时也需要将其中的某些页面设置为其它页面方向不同,或者根本就是没有规律,横向与纵向的页面掺杂在一起。那么如何才能让一个Word文档中同时存在横向和纵向两种方向的页面呢?能不能随心所欲地调整页面方向呢? 细心的读者可能会发现,当选择菜单命令“文件”|“页面设置”,打开“页面设置”对话框后,在其左下方有一个“应用于”下拉列表。

使用这个下拉列表,我们可以任意设置页面的方向。分不同情况介绍如下。

(1)如果一篇文章的前边设置一个方向,如纵向,而后边都设置为横向,则可以先将插入点定位到纵向页面的结尾,或要设置为横向页面的页首,在“页面设置”对话框中单击“横向”,然后在“应用于”下拉列表中选择“插入点之后”。 (2)如果要将某些选定的页面设置为某一个方向,可以先选中这些页面中所有的内容,然后在“应用于”下拉列表中选择“所选文字”。

(3)如果文档中以标题样式分为许多小节,可以选中要改变页面方向的节,然后在“应用于”下拉列表中选择“所选节”。如果不选某节,而只是将插入点定位到该节中,则还可以选择“本节”。

设置完成后,可以在预览视图中适当缩小显示比例,查看更改的结果,如图中所示。 推而广之,其实不仅可以将页面方向任意地应用到不同的页面,“页面设置”对话框中的其它设置选项,如纸张类型、版式、页边距等,都可以类似地对不同页面采用不同的设置,读者朋友不妨试一下。

转载请注明出处51数据库 » poi生产word文档

软件
前端设计
程序设计
Java相关