@@ -6,6 +6,8 @@ import java.util.List; | |||||
import java.util.Map; | import java.util.Map; | ||||
import org.apache.poi.xwpf.usermodel.XWPFDocument; | import org.apache.poi.xwpf.usermodel.XWPFDocument; | ||||
import org.apache.poi.xwpf.usermodel.XWPFFooter; | |||||
import org.apache.poi.xwpf.usermodel.XWPFHeader; | |||||
import org.apache.poi.xwpf.usermodel.XWPFParagraph; | import org.apache.poi.xwpf.usermodel.XWPFParagraph; | ||||
import org.apache.poi.xwpf.usermodel.XWPFRun; | import org.apache.poi.xwpf.usermodel.XWPFRun; | ||||
import org.apache.poi.xwpf.usermodel.XWPFTable; | import org.apache.poi.xwpf.usermodel.XWPFTable; | ||||
@@ -42,6 +44,7 @@ public class ParseWord07 { | |||||
* @param currentRun | * @param currentRun | ||||
* @throws Exception | * @throws Exception | ||||
*/ | */ | ||||
@SuppressWarnings("deprecation") | |||||
private void addAnImage(WordImageEntity obj, XWPFRun currentRun) throws Exception { | private void addAnImage(WordImageEntity obj, XWPFRun currentRun) throws Exception { | ||||
Object[] isAndType = POIPublicUtil.getIsAndType(obj); | Object[] isAndType = POIPublicUtil.getIsAndType(obj); | ||||
String picId; | String picId; | ||||
@@ -239,7 +242,9 @@ public class ParseWord07 { | |||||
private void parseWordSetValue(MyXWPFDocument doc, Map<String, Object> map) throws Exception { | private void parseWordSetValue(MyXWPFDocument doc, Map<String, Object> map) throws Exception { | ||||
// 第一步解析文档 | // 第一步解析文档 | ||||
parseAllParagraphic(doc.getParagraphs(), map); | parseAllParagraphic(doc.getParagraphs(), map); | ||||
// 第二步解析所有表格 | |||||
// 第二步解析页眉,页脚 | |||||
parseHeaderAndFoot(doc, map); | |||||
// 第三步解析所有表格 | |||||
XWPFTable table; | XWPFTable table; | ||||
Iterator<XWPFTable> itTable = doc.getTablesIterator(); | Iterator<XWPFTable> itTable = doc.getTablesIterator(); | ||||
while (itTable.hasNext()) { | while (itTable.hasNext()) { | ||||
@@ -251,4 +256,25 @@ public class ParseWord07 { | |||||
} | } | ||||
/** | |||||
* 解析页眉和页脚 | |||||
* @param doc | |||||
* @param map | |||||
* @throws Exception | |||||
*/ | |||||
private void parseHeaderAndFoot(MyXWPFDocument doc, Map<String, Object> map) throws Exception { | |||||
List<XWPFHeader> headerList = doc.getHeaderList(); | |||||
for (XWPFHeader xwpfHeader : headerList) { | |||||
for (int i = 0; i < xwpfHeader.getListParagraph().size(); i++) { | |||||
parseThisParagraph(xwpfHeader.getListParagraph().get(i), map); | |||||
} | |||||
} | |||||
List<XWPFFooter> footerList = doc.getFooterList(); | |||||
for (XWPFFooter xwpfFooter : footerList) { | |||||
for (int i = 0; i < xwpfFooter.getListParagraph().size(); i++) { | |||||
parseThisParagraph(xwpfFooter.getListParagraph().get(i), map); | |||||
} | |||||
} | |||||
} | |||||
} | } |
@@ -1,22 +1,17 @@ | |||||
<?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||||
<classpath> | <classpath> | ||||
<classpathentry kind="src" output="target/classes" path="src/main/java"> | |||||
<classpathentry kind="src" output="target/test-classes" path="src/main/java"> | |||||
<attributes> | <attributes> | ||||
<attribute name="optional" value="true"/> | <attribute name="optional" value="true"/> | ||||
<attribute name="maven.pomderived" value="true"/> | <attribute name="maven.pomderived" value="true"/> | ||||
</attributes> | </attributes> | ||||
</classpathentry> | </classpathentry> | ||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> | |||||
<classpathentry kind="src" path="src/test"/> | |||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/main/resources"> | |||||
<attributes> | <attributes> | ||||
<attribute name="maven.pomderived" value="true"/> | <attribute name="maven.pomderived" value="true"/> | ||||
</attributes> | </attributes> | ||||
</classpathentry> | </classpathentry> | ||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> | |||||
<attributes> | |||||
<attribute name="optional" value="true"/> | |||||
<attribute name="maven.pomderived" value="true"/> | |||||
</attributes> | |||||
</classpathentry> | |||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"> | <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"> | ||||
<attributes> | <attributes> | ||||
<attribute name="maven.pomderived" value="true"/> | <attribute name="maven.pomderived" value="true"/> | ||||
@@ -17,7 +17,7 @@ public class WordExportUtilTest { | |||||
/** | /** | ||||
* 简单导出包含图片 | * 简单导出包含图片 | ||||
*/ | */ | ||||
@Test | |||||
//@Test | |||||
public void imageWordExport() { | public void imageWordExport() { | ||||
Map<String, Object> map = new HashMap<String, Object>(); | Map<String, Object> map = new HashMap<String, Object>(); | ||||
map.put("department", "Jeecg"); | map.put("department", "Jeecg"); | ||||
@@ -49,6 +49,8 @@ public class WordExportUtilTest { | |||||
map.put("department", "Jeecg"); | map.put("department", "Jeecg"); | ||||
map.put("person", "JueYue"); | map.put("person", "JueYue"); | ||||
map.put("time", format.format(new Date())); | map.put("time", format.format(new Date())); | ||||
map.put("me","JueYue"); | |||||
map.put("date", "2015-01-03"); | |||||
try { | try { | ||||
XWPFDocument doc = WordExportUtil.exportWord07( | XWPFDocument doc = WordExportUtil.exportWord07( | ||||
"org/jeecgframework/poi/word/doc/Simple.docx", map); | "org/jeecgframework/poi/word/doc/Simple.docx", map); | ||||