public class DocumentWrapper extends Object implements Closeable
构造器和说明 |
---|
DocumentWrapper(org.apache.poi.hwpf.HWPFDocument doc2003)
包装了2003格式的文档处理器
|
DocumentWrapper(org.apache.poi.xwpf.usermodel.XWPFDocument doc2007)
包装了2007格式的文档处理器
|
DocumentWrapper(com.deepoove.poi.XWPFTemplate doc2007plus)
包装了2007格式的文档处理器
|
限定符和类型 | 方法和说明 |
---|---|
void |
addTableRow(int tableIndex,
int rowIndex)
在指定行后面增加行
|
void |
close() |
void |
drawTable(Map<String,String> headers,
Collection<Map<String,Object>> list,
Map<Integer,String> rowColorStyleMap,
Map<Integer,Integer> rowHeightStyleMap,
Map<Integer,Integer> colWidthStyleMap,
Set<String> imageColSet,
String pattern)
绘制数据表格
|
String |
getContentFromCell(int tableIndex,
int cellRowIndex,
int cellColIndex)
获取表格指定单元格的文本内容
|
Map<Integer,ArrayList<String[]>> |
getTableData()
将word表格的内容按照最简单的行列模式,构造二维集合返回,集合中一个元素代表一行数据
注意,该方法不会读取WORD文档中表格里面的图片数据,也不会读取表格之外的数据。
|
ArrayList<String> |
getTextData()
将word文本内容逐段读取,该方法适合小页数范围的word内容获取,
大页数范围的word内容获取使用该方法有可能导致内存占用过大
注意:表格中的每个单元格会被认为是单独一个段落
|
void |
inputTableCellContent(int tableIndex,
int cellRowIndex,
int cellColIndex,
String cellValue)
往表格指定单元格设置文本内容
|
void |
mergeCell(int tableIndex,
int cellRowFromIndex,
int cellColFromIndex,
int cellRowToIndex,
int cellColToIndex)
合并表格指定区域的单元格
|
void |
render(LinkedHashMap<String,Object> data)
替换文档中的指定标签,该方法处理后,会将文档中的所有标签都去掉,所以在制作文档前应该只调用一次最佳
|
void |
replaceText(LinkedHashMap<String,String> texts)
替换文档中的指定文本
|
void |
write(OutputStream outputStream)
文档写入到指定的输出流
|
public DocumentWrapper(org.apache.poi.hwpf.HWPFDocument doc2003)
doc2003
- 2003格式的文档处理器public DocumentWrapper(org.apache.poi.xwpf.usermodel.XWPFDocument doc2007)
doc2007
- 2007格式的文档处理器public DocumentWrapper(com.deepoove.poi.XWPFTemplate doc2007plus)
doc2007plus
- 2007格式的文档处理器增强版public void replaceText(LinkedHashMap<String,String> texts)
texts
- 替换文本的映射关系public void write(OutputStream outputStream) throws IOException
outputStream
- 文档数据输出流IOException
- 输出文档数据过程中,可能抛出该异常public void render(LinkedHashMap<String,Object> data)
data
- 替换数据的映射关系public void close()
close
在接口中 Closeable
close
在接口中 AutoCloseable
public Map<Integer,ArrayList<String[]>> getTableData()
public ArrayList<String> getTextData()
注意:表格中的每个单元格会被认为是单独一个段落
public void drawTable(Map<String,String> headers, Collection<Map<String,Object>> list, Map<Integer,String> rowColorStyleMap, Map<Integer,Integer> rowHeightStyleMap, Map<Integer,Integer> colWidthStyleMap, Set<String> imageColSet, String pattern)
headers
- 表格属性列名数组list
- 需要显示的数据集合,集合中一定要放置符合javabean风格的类的对象。此方法支持的
javabean属性的数据类型有基本数据类型及String,Date,String[],Double[]rowColorStyleMap
- 行的背景颜色风格rowHeightStyleMap
- 行的高度风格colWidthStyleMap
- 列的宽度风格,指定列需要占几个字符宽度imageColSet
- 图片列,以标题为标识pattern
- 如果有时间数据,设定输出格式。默认为"yyyy-MM-dd"public void addTableRow(int tableIndex, int rowIndex)
tableIndex
- 表格索引,从0开始rowIndex
- 行索引,从0开始public void mergeCell(int tableIndex, int cellRowFromIndex, int cellColFromIndex, int cellRowToIndex, int cellColToIndex)
tableIndex
- 表格索引,从0开始cellRowFromIndex
- 起始单元格行索引,从0开始cellColFromIndex
- 起始单元格列索引,从0开始cellRowToIndex
- 目标单元格行索引,从0开始cellColToIndex
- 目标单元格列索引,从0开始public String getContentFromCell(int tableIndex, int cellRowIndex, int cellColIndex)
tableIndex
- 表格索引,从0开始cellRowIndex
- 行索引,从0开始cellColIndex
- 列索引,从0开始public void inputTableCellContent(int tableIndex, int cellRowIndex, int cellColIndex, String cellValue)
tableIndex
- 表格索引,从0开始cellRowIndex
- 行索引,从0开始cellColIndex
- 列索引,从0开始cellValue
- 文本内容