이 기사에서는 참조를위한 간단한 Java Operation Word의 예를 공유합니다. 특정 내용은 다음과 같습니다
패키지 apache.poi; import java.io.bytearrayinputStream; import java.io.bytearrayoutputstream; import java.io.file; import java.io.fileinputstream; import java.io.fileoutputstream; import java.io.io exception; import java.io.outputstram; java.hutil; java.util.map; import org.apache.poi.hwpf.hwpfdocument; import org.apache.poi.hwpf.usermodel.range; import org.apache.poi.poifs.filesystem.directoryentry; import org.apache.poi.poifs.filesyst fostf; 클래스 ExportDocTest {public static void main (String [] args) {String destFile = "d : //11.doc"; //############################################################################################################### StringBuffer filecon = new StringBuffer (); filecon.append ( "Zhang Dapaoman 317258963215223/n" + "2011 09 09 2013 07 3/N" + "두 번째 Pawn Research 성인/n" + "2013000001 2013 07 08"); filecon.append ( "/n/r/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/ n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n /n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/ n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n /n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/ n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n /n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/ n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n map = string> () "Zues"; "07", "gap", "Zhuanye", "type", "bianhao"); "20220301"); // Biyezheng_moban.doc 문서의 위치에 주목하십시오. bytearrayoutputstream ostream = 새로운 BytearRayoutputStream (); try {document.write (Ostream); // output Word 파일 outputStream outs = new FileOutputStream (destFile); outs.write (Ostream.tobytearRay ()); outs.close (); } catch (ioexception e) {e.printstacktrace (); }} /** * * @param destfile * @param filecon * /public void exportDoc (String destFile, String Filecon) {try {// doc 컨텐츠 bytearrayinputStream bais = new ByTearRayinputStream (filecon.getBytes ()); poifsfilesystem fs = 새로운 poifsfilesystem (); directoryEntry directory = fs.getRoot (); directory.createDocument ( "WordDocument", Bais); fileoutputStream ostream = 새 FileOutputStream (destFile); fs.WriteFilessystem (Ostream); bais.close (); Ostream.close (); } catch (ioexception e) {e.printstacktrace (); }} / ** * 단어 템플릿을 읽고 변수를 교체하고 변수를 교체하십시오 * @param srcpath * @param map * @return * / public hwpfdocument groncecument (문자열 srcpath, map <string, string> map) {// Word 템플릿을 읽습니다. fileInputStream fis = new FileInputStream (새 파일); hwpfdocument doc = 새로운 hwpfdocument (fis); // 단어 텍스트 내용 범위를 읽습니다. bodyRange = doc.getRange (); // (map.Entry <string, String> entry : map.EntrySet ()) {bodyRange.Replacetext ( "$ {" + eptry.getKey () + "}", ender .getValue ())에 대한 텍스트 내용을 대체합니다. } reto doc; } catch (예외 e) {e.printstacktrace (); 널 리턴; }}}위의 내용은이 기사에 관한 모든 것입니다. 모든 사람의 학습에 도움이되기를 바랍니다.