91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 18.48MB
    文件類型: .zip
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2023-07-21
  • 語言: 其他
  • 標簽: Java??POI??合并??

資源簡介

相同格式的excel進行合并,或者對多個word文檔進行合并,word文檔包含圖片。

資源截圖

代碼片段和文件信息

package?com.shang;

import?java.io.FileInputStream;
import?java.io.FileOutputStream;
import?java.io.InputStream;
import?java.io.OutputStream;
import?java.util.HashMap;
import?java.util.List;
import?java.util.Map;

import?org.apache.poi.openxml4j.opc.OPCPackage;
import?org.apache.poi.xwpf.usermodel.Document;
import?org.apache.poi.xwpf.usermodel.XWPFDocument;
import?org.apache.poi.xwpf.usermodel.XWPFPictureData;
import?org.apache.xmlbeans.xmlOptions;
import?org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody;

/**
?*?合并word文件
?*?
?*?@author?shang
?*?@date?2019年2月19日
?*/
public?class?MergeDoc?{

public?static?void?main(String[]?args)?throws?Exception?{
InputStream?in1?=?null;
InputStream?in2?=?null;
InputStream?in3?=?null;
OPCPackage?src1Package?=?null;
OPCPackage?src2Package?=?null;
OPCPackage?src3Package?=?null;
OutputStream?dest?=?new?FileOutputStream(“C:/Users/Administrator/Desktop/merge.docx“);
try?{
in1?=?new?FileInputStream(“C:/Users/Administrator/Desktop/第一個測試文件.docx“);
in2?=?new?FileInputStream(“C:/Users/Administrator/Desktop/第二個測試文件.docx“);
in3?=?new?FileInputStream(“C:/Users/Administrator/Desktop/第三個測試文件.docx“);
src1Package?=?OPCPackage.open(in1);
src2Package?=?OPCPackage.open(in2);
src3Package?=?OPCPackage.open(in3);
}?catch?(Exception?e)?{
e.printStackTrace();
}

XWPFDocument?src1Document?=?new?XWPFDocument(src1Package);
XWPFDocument?src2Document?=?new?XWPFDocument(src2Package);
XWPFDocument?src3Document?=?new?XWPFDocument(src3Package);

appendBody(src1Document?src2Document);
appendBody(src1Document?src3Document);

src1Document.write(dest);
in1.close();
in2.close();
in3.close();
dest.close();
System.out.println(“合并完成“);
}

public?static?void?appendBody(XWPFDocument?src?XWPFDocument?append)?throws?Exception?{
CTBody?src1Body?=?src.getDocument().getBody();
CTBody?src2Body?=?append.getDocument().getBody();

List?allPictures?=?append.getAllPictures();
//?記錄圖片合并前及合并后的ID??
Map?map?=?new?HashMap();
for?(XWPFPictureData?picture?:?allPictures)?{
String?before?=?append.getRelationId(picture);
//將原文檔中的圖片加入到目標文檔中??
String?after?=?src.addPictureData(picture.getData()?Document.PICTURE_TYPE_PNG);
map.put(before?after);
}

appendBody(src1Body?src2Body?map);

}

private?static?void?appendBody(CTBody?src?CTBody?append?Map?map)?throws?Exception?{
xmlOptions?optionsOuter?=?new?xmlOptions();
optionsOuter.setSaveOuter();
String?appendString?=?append.xmlText(optionsOuter);

String?srcString?=?src.xmlText();
String?prefix?=?srcString.substring(0?srcString.indexOf(“>“)?+?1);
String?mainPart?=?srcString.substring(srcString.indexOf(“>“)?+?1?srcString.lastIndexOf(“<“));
String?sufix?=?srcString.substring(srcString.lastIndexOf(“<“));
String?addPart?=?appendString.substring(appendString.indexOf(“>“)?+?1

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-02-19?13:38??POI\
?????文件????????1306??2019-02-19?12:16??POI\.classpath
?????文件?????????379??2019-02-19?10:01??POI\.project
?????目錄???????????0??2019-02-19?13:38??POI\.settings\
?????文件?????????598??2019-02-19?10:01??POI\.settings\org.eclipse.jdt.core.prefs
?????目錄???????????0??2019-02-19?13:38??POI\bin\
?????目錄???????????0??2019-02-19?13:38??POI\bin\com\
?????目錄???????????0??2019-02-19?13:38??POI\bin\com\shang\
?????文件????????6069??2019-02-19?13:34??POI\bin\com\shang\MergeDoc.class
?????文件????????6377??2019-02-19?13:36??POI\bin\com\shang\MergeExcel.class
?????目錄???????????0??2019-02-19?13:38??POI\lib\
?????文件???????69409??2019-02-19?12:16??POI\lib\activation-1.1.1.jar
?????文件?????1557320??2019-02-19?12:16??POI\lib\chihleePdfBox.jar
?????文件??????335042??2019-02-19?12:16??POI\lib\commons-codec-1.11.jar
?????文件??????752798??2019-02-19?12:16??POI\lib\commons-collections4-4.2.jar
?????文件??????591748??2019-02-19?12:16??POI\lib\commons-compress-1.18.jar
?????文件???????61829??2019-02-19?12:16??POI\lib\commons-logging-1.2.jar
?????文件?????2213560??2019-02-19?12:16??POI\lib\commons-math3-3.6.1.jar
?????文件??????111927??2019-02-19?12:16??POI\lib\curvesapi-1.05.jar
?????文件??????125632??2019-02-19?12:16??POI\lib\jaxb-api-2.3.0.jar
?????文件??????254858??2019-02-19?12:16??POI\lib\jaxb-core-2.3.0.1.jar
?????文件??????961128??2019-02-19?12:16??POI\lib\jaxb-impl-2.3.0.1.jar
?????文件??????314932??2019-02-19?12:16??POI\lib\junit-4.12.jar
?????文件??????489884??2019-02-19?12:16??POI\lib\log4j-1.2.17.jar
?????文件?????2718209??2019-02-19?12:16??POI\lib\poi-4.0.1.jar
?????文件?????1766188??2019-02-19?12:16??POI\lib\poi-ooxml-4.0.1.jar
?????文件?????7771088??2019-02-19?12:16??POI\lib\poi-ooxml-schemas-4.0.1.jar
?????文件?????2572733??2019-02-19?12:16??POI\lib\xmlbeans-3.0.2.jar
?????目錄???????????0??2019-02-19?13:38??POI\src\
?????目錄???????????0??2019-02-19?13:38??POI\src\com\
?????目錄???????????0??2019-02-19?13:38??POI\src\com\shang\
............此處省略2個文件信息

評論

共有 條評論