|
@@ -1,10 +1,5 @@
|
|
|
package com.yaoxiang.diagnosis.word;
|
|
|
|
|
|
-import com.deepoove.poi.XWPFTemplate;
|
|
|
-import com.deepoove.poi.template.ElementTemplate;
|
|
|
-import fr.opensagres.poi.xwpf.converter.core.ImageManager;
|
|
|
-import fr.opensagres.poi.xwpf.converter.xhtml.XHTMLConverter;
|
|
|
-import fr.opensagres.poi.xwpf.converter.xhtml.XHTMLOptions;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
|
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
|
@@ -39,12 +34,12 @@ public class WordUtil {
|
|
|
|
|
|
public static final String DIR_CONTRACT_TPL = DIRECTORY_SEPARATOR + "contract" + DIRECTORY_SEPARATOR + "tpl" + DIRECTORY_SEPARATOR;
|
|
|
|
|
|
- public static List<String> getVars(String docUrl) {
|
|
|
- XWPFTemplate template = XWPFTemplate.compile(docUrl);
|
|
|
- return template.getElementTemplates().stream()
|
|
|
- .map(ElementTemplate::getTagName)
|
|
|
- .collect(Collectors.toList());
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
public static void readDoc(InputStream inputStream, Consumer<String> operation) {
|
|
|
XWPFDocument doc;
|
|
@@ -73,26 +68,19 @@ public class WordUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static void build(String templateUrl, Map<String, Object> params, OutputStream outputStream) throws IOException {
|
|
|
- XWPFTemplate template = XWPFTemplate.compile(templateUrl).render(params);
|
|
|
-
|
|
|
- template.write(outputStream);
|
|
|
- template.close();
|
|
|
- }
|
|
|
-
|
|
|
- public static String wordToHtml(InputStream in) {
|
|
|
- try {
|
|
|
- XWPFDocument document = new XWPFDocument(in);
|
|
|
- XHTMLOptions options = XHTMLOptions.create();
|
|
|
- options.setImageManager(new ImageManager(new File("image"), "image"));
|
|
|
- OutputStream out = new ByteArrayOutputStream();
|
|
|
- XHTMLConverter.getInstance().convert(document, out, options);
|
|
|
- return out.toString();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- return null;
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
* 打开一个word2007文档
|
|
@@ -233,26 +221,25 @@ public class WordUtil {
|
|
|
|
|
|
* 将word2007转换成html
|
|
|
*
|
|
|
- * @param pathname 路径
|
|
|
*/
|
|
|
- public static String word7ToHtml(String pathname) {
|
|
|
- XWPFDocument document = open(pathname);
|
|
|
- XHTMLOptions options = XHTMLOptions.create();
|
|
|
-
|
|
|
- options.setImageManager(new ImageManager(new File("image"), ""));
|
|
|
- OutputStream out = new ByteArrayOutputStream();
|
|
|
- try {
|
|
|
- XHTMLConverter.getInstance().convert(document, out, options);
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- String html = out.toString();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- return html;
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
|
|
@@ -263,8 +250,8 @@ public class WordUtil {
|
|
|
list.add(String.valueOf(i + 1));
|
|
|
}
|
|
|
|
|
|
- String html = word7ToHtml(pathname);
|
|
|
- System.out.println(html);
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|