POI 创建word 2007表单示例

时间:2021-07-29 18:41:20

通过本人测试,此代码有一个缺陷,用wps打开word文档格式会错乱,但是在offic中是正常的,故谨慎使用。


Java代码  POI 创建word 2007表单示例
  1. import java.io.FileOutputStream;  
  2. import java.math.BigInteger;  
  3. import java.util.List;  
  4.   
  5. import org.apache.commons.lang3.StringUtils;  
  6. import org.apache.poi.xwpf.usermodel.ParagraphAlignment;  
  7. import org.apache.poi.xwpf.usermodel.TextAlignment;  
  8. import org.apache.poi.xwpf.usermodel.XWPFDocument;  
  9. import org.apache.poi.xwpf.usermodel.XWPFParagraph;  
  10. import org.apache.poi.xwpf.usermodel.XWPFRun;  
  11. import org.apache.poi.xwpf.usermodel.XWPFTable;  
  12. import org.apache.poi.xwpf.usermodel.XWPFTableCell;  
  13. import org.apache.poi.xwpf.usermodel.XWPFTableRow;  
  14. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;  
  15. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;  
  16. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHeight;  
  17. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHpsMeasure;  
  18. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc;  
  19. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr;  
  20. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;  
  21. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;  
  22. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTShd;  
  23. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSignedTwipsMeasure;  
  24. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSpacing;  
  25. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSym;  
  26. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;  
  27. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblBorders;  
  28. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblGrid;  
  29. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblGridCol;  
  30. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblPr;  
  31. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;  
  32. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;  
  33. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr;  
  34. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTextScale;  
  35. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTrPr;  
  36. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVerticalJc;  
  37. import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;  
  38. import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHeightRule;  
  39. import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHint;  
  40. import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;  
  41. import org.openxmlformats.schemas.wordprocessingml.x2006.main.STLineSpacingRule;  
  42. import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge;  
  43. import org.openxmlformats.schemas.wordprocessingml.x2006.main.STShd;  
  44. import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;  
  45. import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalJc;  
  46.   
  47. public class POI_07_创建表格示例_S4_Test {  
  48.     public static void main(String[] args) throws Exception {  
  49.         POI_07_创建表格示例_S4_Test t2 = new POI_07_创建表格示例_S4_Test();  
  50.         t2.createTable();  
  51.     }  
  52.   
  53.     /** 
  54.      * @Description: 添加方块♢ 
  55.      */  
  56.     public void setCellContentCommonFunction(XWPFTableCell cell, String content)  
  57.             throws Exception {  
  58.         XWPFParagraph p = cell.addParagraph();  
  59.         setParagraphSpacingInfo(p, true"0""0""0""0"true"300",  
  60.                 STLineSpacingRule.AUTO);  
  61.         setParagraphAlignInfo(p, ParagraphAlignment.BOTH, TextAlignment.CENTER);  
  62.         XWPFRun pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  63.         setParagraphRunSymInfo(p, pRun, "宋体""Times New Roman""21"true,  
  64.                 falsefalse060);  
  65.         pRun = getOrAddParagraphFirstRun(p, truefalse);  
  66.         setParagraphRunFontInfo(p, pRun, content, "宋体""Times New Roman",  
  67.                 "21"truefalsefalsefalsenullnull060);  
  68.     }  
  69.   
  70.     /** 
  71.      * @Description: 保存文档 
  72.      */  
  73.     public void saveDocument(XWPFDocument document, String savePath)  
  74.             throws Exception {  
  75.         FileOutputStream fos = new FileOutputStream(savePath);  
  76.         document.write(fos);  
  77.         fos.close();  
  78.     }  
  79.   
  80.     /** 
  81.      * @Description: 得到单元格第一个Paragraph 
  82.      */  
  83.     public XWPFParagraph getCellFirstParagraph(XWPFTableCell cell) {  
  84.         XWPFParagraph p;  
  85.         if (cell.getParagraphs() != null && cell.getParagraphs().size() > 0) {  
  86.             p = cell.getParagraphs().get(0);  
  87.         } else {  
  88.             p = cell.addParagraph();  
  89.         }  
  90.         return p;  
  91.     }  
  92.   
  93.     /** 
  94.      * @Description: 得到段落CTPPr 
  95.      */  
  96.     public CTPPr getParagraphCTPPr(XWPFParagraph p) {  
  97.         CTPPr pPPr = null;  
  98.         if (p.getCTP() != null) {  
  99.             if (p.getCTP().getPPr() != null) {  
  100.                 pPPr = p.getCTP().getPPr();  
  101.             } else {  
  102.                 pPPr = p.getCTP().addNewPPr();  
  103.             }  
  104.         }  
  105.         return pPPr;  
  106.     }  
  107.   
  108.     /** 
  109.      * @Description: 设置段落间距信息,一行=100 一磅=20 
  110.      */  
  111.     public void setParagraphSpacingInfo(XWPFParagraph p, boolean isSpace,  
  112.             String before, String after, String beforeLines, String afterLines,  
  113.             boolean isLine, String line, STLineSpacingRule.Enum lineValue) {  
  114.         CTPPr pPPr = getParagraphCTPPr(p);  
  115.         CTSpacing pSpacing = pPPr.getSpacing() != null ? pPPr.getSpacing()  
  116.                 : pPPr.addNewSpacing();  
  117.         if (isSpace) {  
  118.             // 段前磅数  
  119.             if (before != null) {  
  120.                 pSpacing.setBefore(new BigInteger(before));  
  121.             }  
  122.             // 段后磅数  
  123.             if (after != null) {  
  124.                 pSpacing.setAfter(new BigInteger(after));  
  125.             }  
  126.             // 段前行数  
  127.             if (beforeLines != null) {  
  128.                 pSpacing.setBeforeLines(new BigInteger(beforeLines));  
  129.             }  
  130.             // 段后行数  
  131.             if (afterLines != null) {  
  132.                 pSpacing.setAfterLines(new BigInteger(afterLines));  
  133.             }  
  134.         }  
  135.         // 间距  
  136.         if (isLine) {  
  137.             if (line != null) {  
  138.                 pSpacing.setLine(new BigInteger(line));  
  139.             }  
  140.             if (lineValue != null) {  
  141.                 pSpacing.setLineRule(lineValue);  
  142.             }  
  143.         }  
  144.     }  
  145.   
  146.     /** 
  147.      * @Description: 设置段落文本样式(高亮与底纹显示效果不同)设置字符间距信息(CTSignedTwipsMeasure) 
  148.      * @param verticalAlign 
  149.      *            : SUPERSCRIPT上标 SUBSCRIPT下标 
  150.      * @param position 
  151.      *            :字符间距位置:>0提升 <0降低=磅值*2 如3磅=6 
  152.      * @param spacingValue 
  153.      *            :字符间距间距 >0加宽 <0紧缩 =磅值*20 如2磅=40 
  154.      * @param indent 
  155.      *            :字符间距缩进 <100 缩 
  156.      */  
  157.   
  158.     public void setParagraphRunFontInfo(XWPFParagraph p, XWPFRun pRun,  
  159.             String content, String cnFontFamily, String enFontFamily,  
  160.             String fontSize, boolean isBlod, boolean isItalic,  
  161.             boolean isStrike, boolean isShd, String shdColor,  
  162.             STShd.Enum shdStyle, int position, int spacingValue, int indent) {  
  163.         CTRPr pRpr = getRunCTRPr(p, pRun);  
  164.         if (StringUtils.isNotBlank(content)) {  
  165.             // pRun.setText(content);  
  166.             if (content.contains("\n")) {// System.properties("line.separator")  
  167.                 String[] lines = content.split("\n");  
  168.                 pRun.setText(lines[0], 0); // set first line into XWPFRun  
  169.                 for (int i = 1; i < lines.length; i++) {  
  170.                     // add break and insert new text  
  171.                     pRun.addBreak();  
  172.                     pRun.setText(lines[i]);  
  173.                 }  
  174.             } else {  
  175.                 pRun.setText(content, 0);  
  176.             }  
  177.         }  
  178.         // 设置字体  
  179.         CTFonts fonts = pRpr.isSetRFonts() ? pRpr.getRFonts() : pRpr  
  180.                 .addNewRFonts();  
  181.         if (StringUtils.isNotBlank(enFontFamily)) {  
  182.             fonts.setAscii(enFontFamily);  
  183.             fonts.setHAnsi(enFontFamily);  
  184.         }  
  185.         if (StringUtils.isNotBlank(cnFontFamily)) {  
  186.             fonts.setEastAsia(cnFontFamily);  
  187.             fonts.setHint(STHint.EAST_ASIA);  
  188.         }  
  189.         // 设置字体大小  
  190.         CTHpsMeasure sz = pRpr.isSetSz() ? pRpr.getSz() : pRpr.addNewSz();  
  191.         sz.setVal(new BigInteger(fontSize));  
  192.   
  193.         CTHpsMeasure szCs = pRpr.isSetSzCs() ? pRpr.getSzCs() : pRpr  
  194.                 .addNewSzCs();  
  195.         szCs.setVal(new BigInteger(fontSize));  
  196.   
  197.         // 设置字体样式  
  198.         // 加粗  
  199.         if (isBlod) {  
  200.             pRun.setBold(isBlod);  
  201.         }  
  202.         // 倾斜  
  203.         if (isItalic) {  
  204.             pRun.setItalic(isItalic);  
  205.         }  
  206.         // 删除线  
  207.         if (isStrike) {  
  208.             pRun.setStrike(isStrike);  
  209.         }  
  210.         if (isShd) {  
  211.             // 设置底纹  
  212.             CTShd shd = pRpr.isSetShd() ? pRpr.getShd() : pRpr.addNewShd();  
  213.             if (shdStyle != null) {  
  214.                 shd.setVal(shdStyle);  
  215.             }  
  216.             if (shdColor != null) {  
  217.                 shd.setColor(shdColor);  
  218.                 shd.setFill(shdColor);  
  219.             }  
  220.         }  
  221.   
  222.         // 设置文本位置  
  223.         if (position != 0) {  
  224.             pRun.setTextPosition(position);  
  225.         }  
  226.         if (spacingValue > 0) {  
  227.             // 设置字符间距信息  
  228.             CTSignedTwipsMeasure ctSTwipsMeasure = pRpr.isSetSpacing() ? pRpr  
  229.                     .getSpacing() : pRpr.addNewSpacing();  
  230.             ctSTwipsMeasure  
  231.                     .setVal(new BigInteger(String.valueOf(spacingValue)));  
  232.         }  
  233.         if (indent > 0) {  
  234.             CTTextScale paramCTTextScale = pRpr.isSetW() ? pRpr.getW() : pRpr  
  235.                     .addNewW();  
  236.             paramCTTextScale.setVal(indent);  
  237.         }  
  238.     }  
  239.   
  240.     /** 
  241.      * @Description: 得到XWPFRun的CTRPr 
  242.      */  
  243.     public CTRPr getRunCTRPr(XWPFParagraph p, XWPFRun pRun) {  
  244.         CTRPr pRpr = null;  
  245.         if (pRun.getCTR() != null) {  
  246.             pRpr = pRun.getCTR().getRPr();  
  247.             if (pRpr == null) {  
  248.                 pRpr = pRun.getCTR().addNewRPr();  
  249.             }  
  250.         } else {  
  251.             pRpr = p.getCTP().addNewR().addNewRPr();  
  252.         }  
  253.         return pRpr;  
  254.     }  
  255.   
  256.     /** 
  257.      * @Description: 设置段落对齐 
  258.      */  
  259.     public void setParagraphAlignInfo(XWPFParagraph p,  
  260.             ParagraphAlignment pAlign, TextAlignment valign) {  
  261.         if (pAlign != null) {  
  262.             p.setAlignment(pAlign);  
  263.         }  
  264.         if (valign != null) {  
  265.             p.setVerticalAlignment(valign);  
  266.         }  
  267.     }  
  268.   
  269.     public XWPFRun getOrAddParagraphFirstRun(XWPFParagraph p, boolean isInsert,  
  270.             boolean isNewLine) {  
  271.         XWPFRun pRun = null;  
  272.         if (isInsert) {  
  273.             pRun = p.createRun();  
  274.         } else {  
  275.             if (p.getRuns() != null && p.getRuns().size() > 0) {  
  276.                 pRun = p.getRuns().get(0);  
  277.             } else {  
  278.                 pRun = p.createRun();  
  279.             }  
  280.         }  
  281.         if (isNewLine) {  
  282.             pRun.addBreak();  
  283.         }  
  284.         return pRun;  
  285.     }  
  286.   
  287.     /** 
  288.      * @Description: 设置Table的边框 
  289.      */  
  290.     public void setTableBorders(XWPFTable table, STBorder.Enum borderType,  
  291.             String size, String color, String space) {  
  292.         CTTblPr tblPr = getTableCTTblPr(table);  
  293.         CTTblBorders borders = tblPr.isSetTblBorders() ? tblPr.getTblBorders()  
  294.                 : tblPr.addNewTblBorders();  
  295.         CTBorder hBorder = borders.isSetInsideH() ? borders.getInsideH()  
  296.                 : borders.addNewInsideH();  
  297.         hBorder.setVal(borderType);  
  298.         hBorder.setSz(new BigInteger(size));  
  299.         hBorder.setColor(color);  
  300.         hBorder.setSpace(new BigInteger(space));  
  301.   
  302.         CTBorder vBorder = borders.isSetInsideV() ? borders.getInsideV()  
  303.                 : borders.addNewInsideV();  
  304.         vBorder.setVal(borderType);  
  305.         vBorder.setSz(new BigInteger(size));  
  306.         vBorder.setColor(color);  
  307.         vBorder.setSpace(new BigInteger(space));  
  308.   
  309.         CTBorder lBorder = borders.isSetLeft() ? borders.getLeft() : borders  
  310.                 .addNewLeft();  
  311.         lBorder.setVal(borderType);  
  312.         lBorder.setSz(new BigInteger(size));  
  313.         lBorder.setColor(color);  
  314.         lBorder.setSpace(new BigInteger(space));  
  315.   
  316.         CTBorder rBorder = borders.isSetRight() ? borders.getRight() : borders  
  317.                 .addNewRight();  
  318.         rBorder.setVal(borderType);  
  319.         rBorder.setSz(new BigInteger(size));  
  320.         rBorder.setColor(color);  
  321.         rBorder.setSpace(new BigInteger(space));  
  322.   
  323.         CTBorder tBorder = borders.isSetTop() ? borders.getTop() : borders  
  324.                 .addNewTop();  
  325.         tBorder.setVal(borderType);  
  326.         tBorder.setSz(new BigInteger(size));  
  327.         tBorder.setColor(color);  
  328.         tBorder.setSpace(new BigInteger(space));  
  329.   
  330.         CTBorder bBorder = borders.isSetBottom() ? borders.getBottom()  
  331.                 : borders.addNewBottom();  
  332.         bBorder.setVal(borderType);  
  333.         bBorder.setSz(new BigInteger(size));  
  334.         bBorder.setColor(color);  
  335.         bBorder.setSpace(new BigInteger(space));  
  336.     }  
  337.   
  338.     /** 
  339.      * @Description: 得到Table的CTTblPr,不存在则新建 
  340.      */  
  341.     public CTTblPr getTableCTTblPr(XWPFTable table) {  
  342.         CTTbl ttbl = table.getCTTbl();  
  343.         CTTblPr tblPr = ttbl.getTblPr() == null ? ttbl.addNewTblPr() : ttbl  
  344.                 .getTblPr();  
  345.         return tblPr;  
  346.     }  
  347.   
  348.     /** 
  349.      * @Description: 设置列宽和垂直对齐方式 
  350.      */  
  351.     public void setCellWidthAndVAlign(XWPFTableCell cell, String width,  
  352.             STTblWidth.Enum typeEnum, STVerticalJc.Enum vAlign) {  
  353.         CTTcPr tcPr = getCellCTTcPr(cell);  
  354.         CTTblWidth tcw = tcPr.isSetTcW() ? tcPr.getTcW() : tcPr.addNewTcW();  
  355.         if (width != null) {  
  356.             tcw.setW(new BigInteger(width));  
  357.         }  
  358.         if (typeEnum != null) {  
  359.             tcw.setType(typeEnum);  
  360.         }  
  361.         if (vAlign != null) {  
  362.             CTVerticalJc vJc = tcPr.isSetVAlign() ? tcPr.getVAlign() : tcPr  
  363.                     .addNewVAlign();  
  364.             vJc.setVal(vAlign);  
  365.         }  
  366.     }  
  367.   
  368.     /** 
  369.      * @Description: 跨列合并 
  370.      */  
  371.     public void mergeCellsHorizontal(XWPFTable table, int row, int fromCell,  
  372.             int toCell) {  
  373.         for (int cellIndex = fromCell; cellIndex <= toCell; cellIndex++) {  
  374.             XWPFTableCell cell = table.getRow(row).getCell(cellIndex);  
  375.             if (cellIndex == fromCell) {  
  376.                 // The first merged cell is set with RESTART merge value  
  377.                 getCellCTTcPr(cell).addNewHMerge().setVal(STMerge.RESTART);  
  378.             } else {  
  379.                 // Cells which join (merge) the first one,are set with CONTINUE  
  380.                 getCellCTTcPr(cell).addNewHMerge().setVal(STMerge.CONTINUE);  
  381.             }  
  382.         }  
  383.     }  
  384.   
  385.     /** 
  386.      *  
  387.      * @Description: 得到Cell的CTTcPr,不存在则新建 
  388.      */  
  389.     public CTTcPr getCellCTTcPr(XWPFTableCell cell) {  
  390.         CTTc cttc = cell.getCTTc();  
  391.         CTTcPr tcPr = cttc.isSetTcPr() ? cttc.getTcPr() : cttc.addNewTcPr();  
  392.         return tcPr;  
  393.     }  
  394.   
  395.     /** 
  396.      * @Description: 设置表格列宽 
  397.      */  
  398.     public void setTableGridCol(XWPFTable table, int[] colWidths) {  
  399.         CTTbl ttbl = table.getCTTbl();  
  400.         CTTblGrid tblGrid = ttbl.getTblGrid() != null ? ttbl.getTblGrid()  
  401.                 : ttbl.addNewTblGrid();  
  402.         for (int j = 0, len = colWidths.length; j < len; j++) {  
  403.             CTTblGridCol gridCol = tblGrid.addNewGridCol();  
  404.             gridCol.setW(new BigInteger(String.valueOf(colWidths[j])));  
  405.         }  
  406.     }  
  407.   
  408.     public void setParagraphRunSymInfo(XWPFParagraph p, XWPFRun pRun,  
  409.             String cnFontFamily, String enFontFamily, String fontSize,  
  410.             boolean isBlod, boolean isItalic, boolean isStrike, int position,  
  411.             int spacingValue, int indent) throws Exception {  
  412.         CTRPr pRpr = getRunCTRPr(p, pRun);  
  413.         // 设置字体  
  414.         CTFonts fonts = pRpr.isSetRFonts() ? pRpr.getRFonts() : pRpr  
  415.                 .addNewRFonts();  
  416.         if (StringUtils.isNotBlank(enFontFamily)) {  
  417.             fonts.setAscii(enFontFamily);  
  418.             fonts.setHAnsi(enFontFamily);  
  419.         }  
  420.         if (StringUtils.isNotBlank(cnFontFamily)) {  
  421.             fonts.setEastAsia(cnFontFamily);  
  422.             fonts.setHint(STHint.EAST_ASIA);  
  423.         }  
  424.         // 设置字体大小  
  425.         CTHpsMeasure sz = pRpr.isSetSz() ? pRpr.getSz() : pRpr.addNewSz();  
  426.         sz.setVal(new BigInteger(fontSize));  
  427.   
  428.         CTHpsMeasure szCs = pRpr.isSetSzCs() ? pRpr.getSzCs() : pRpr  
  429.                 .addNewSzCs();  
  430.         szCs.setVal(new BigInteger(fontSize));  
  431.   
  432.         // 设置字体样式  
  433.         // 加粗  
  434.         if (isBlod) {  
  435.             pRun.setBold(isBlod);  
  436.         }  
  437.         // 倾斜  
  438.         if (isItalic) {  
  439.             pRun.setItalic(isItalic);  
  440.         }  
  441.         // 删除线  
  442.         if (isStrike) {  
  443.             pRun.setStrike(isStrike);  
  444.         }  
  445.         // 设置文本位置  
  446.         if (position != 0) {  
  447.             pRun.setTextPosition(position);  
  448.         }  
  449.         if (spacingValue > 0) {  
  450.             // 设置字符间距信息  
  451.             CTSignedTwipsMeasure ctSTwipsMeasure = pRpr.isSetSpacing() ? pRpr  
  452.                     .getSpacing() : pRpr.addNewSpacing();  
  453.             ctSTwipsMeasure  
  454.                     .setVal(new BigInteger(String.valueOf(spacingValue)));  
  455.         }  
  456.         if (indent > 0) {  
  457.             CTTextScale paramCTTextScale = pRpr.isSetW() ? pRpr.getW() : pRpr  
  458.                     .addNewW();  
  459.             paramCTTextScale.setVal(indent);  
  460.         }  
  461.         List<CTSym> symList = pRun.getCTR().getSymList();  
  462.         CTSym sym = CTSym.Factory  
  463.                 .parse("<xml-fragment w:font=\"Wingdings 2\" w:char=\"00A3\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\"> </xml-fragment>");  
  464.         symList.add(sym);  
  465.     }  
  466.   
  467.     /** 
  468.      * @Description: 设置表格总宽度与水平对齐方式 
  469.      */  
  470.     public void setTableWidthAndHAlign(XWPFTable table, String width,  
  471.             STJc.Enum enumValue) {  
  472.         CTTblPr tblPr = getTableCTTblPr(table);  
  473.         CTTblWidth tblWidth = tblPr.isSetTblW() ? tblPr.getTblW() : tblPr  
  474.                 .addNewTblW();  
  475.         if (enumValue != null) {  
  476.             CTJc cTJc = tblPr.addNewJc();  
  477.             cTJc.setVal(enumValue);  
  478.         }  
  479.         tblWidth.setW(new BigInteger(width));  
  480.         tblWidth.setType(STTblWidth.DXA);  
  481.     }  
  482.   
  483.     /** 
  484.      * @Description: 设置单元格Margin 
  485.      */  
  486.     public void setTableCellMargin(XWPFTable table, int top, int left,  
  487.             int bottom, int right) {  
  488.         table.setCellMargins(top, left, bottom, right);  
  489.     }  
  490.   
  491.     /** 
  492.      * @Description: 得到CTTrPr,不存在则新建 
  493.      */  
  494.     public CTTrPr getRowCTTrPr(XWPFTableRow row) {  
  495.         CTRow ctRow = row.getCtRow();  
  496.         CTTrPr trPr = ctRow.isSetTrPr() ? ctRow.getTrPr() : ctRow.addNewTrPr();  
  497.         return trPr;  
  498.     }  
  499.   
  500.     /** 
  501.      * @Description: 设置行高 
  502.      */  
  503.     public void setRowHeight(XWPFTableRow row, String hight,  
  504.             STHeightRule.Enum heigthEnum) {  
  505.         CTTrPr trPr = getRowCTTrPr(row);  
  506.         CTHeight trHeight;  
  507.         if (trPr.getTrHeightList() != null && trPr.getTrHeightList().size() > 0) {  
  508.             trHeight = trPr.getTrHeightList().get(0);  
  509.         } else {  
  510.             trHeight = trPr.addNewTrHeight();  
  511.         }  
  512.         trHeight.setVal(new BigInteger(hight));  
  513.         if (heigthEnum != null) {  
  514.             trHeight.setHRule(heigthEnum);  
  515.         }  
  516.     }  
  517.   
  518.     /** 
  519.      * @Description: 设置底纹 
  520.      */  
  521.     public void setCellShdStyle(XWPFTableCell cell, boolean isShd,  
  522.             String shdColor, STShd.Enum shdStyle) {  
  523.         CTTcPr tcPr = getCellCTTcPr(cell);  
  524.         if (isShd) {  
  525.             // 设置底纹  
  526.             CTShd shd = tcPr.isSetShd() ? tcPr.getShd() : tcPr.addNewShd();  
  527.             if (shdStyle != null) {  
  528.                 shd.setVal(shdStyle);  
  529.             }  
  530.             if (shdColor != null) {  
  531.                 shd.setColor(shdColor);  
  532.                 shd.setFill(shdColor);  
  533.             }  
  534.         }  
  535.     }  
  536.   
  537.     public void createTable() throws Exception {  
  538.         XWPFDocument xdoc = new XWPFDocument();  
  539.   
  540.         XWPFParagraph p = xdoc.createParagraph();  
  541.         // 固定值25磅  
  542.         setParagraphSpacingInfo(p, true"0""80"nullnulltrue"500",  
  543.                 STLineSpacingRule.EXACT);  
  544.         // 居中  
  545.         setParagraphAlignInfo(p, ParagraphAlignment.CENTER,  
  546.                 TextAlignment.CENTER);  
  547.         XWPFRun pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  548.         setParagraphRunFontInfo(p, pRun, "××××(××)事件报告表""宋体",  
  549.                 "Times New Roman""36"truefalsefalsefalsenullnull,  
  550.                 0090);  
  551.   
  552.         p = xdoc.createParagraph();  
  553.         // 固定值25磅  
  554.         setParagraphSpacingInfo(p, true"0""80"nullnulltrue"500",  
  555.                 STLineSpacingRule.EXACT);  
  556.         // 居中  
  557.         setParagraphAlignInfo(p, ParagraphAlignment.CENTER,  
  558.                 TextAlignment.CENTER);  
  559.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  560.         setParagraphRunFontInfo(p, pRun, "(××××××)""宋体""Times New Roman",  
  561.                 "36"truefalsefalsefalsenullnull0090);  
  562.   
  563.         p = xdoc.createParagraph();  
  564.         // 单倍行距  
  565.         setParagraphSpacingInfo(p, true"0""0""0""0"true"240",  
  566.                 STLineSpacingRule.AUTO);  
  567.         setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);  
  568.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  569.         setParagraphRunFontInfo(p, pRun, "﹡报告日期:年月日﹡ 事件发生日期:年月日""宋体",  
  570.                 "Times New Roman""24"truefalsefalsefalsenullnull,  
  571.                 060);  
  572.   
  573.         // 创建表格21行3列  
  574.         XWPFTable table = xdoc.createTable(214);  
  575.         setTableBorders(table, STBorder.SINGLE, "4""auto""0");  
  576.         setTableWidthAndHAlign(table, "9024", STJc.CENTER);  
  577.         setTableCellMargin(table, 01080108);  
  578.         int[] colWidths = new int[] { 216926385253692 };  
  579.         setTableGridCol(table, colWidths);  
  580.   
  581.         XWPFTableRow row = table.getRow(0);  
  582.         setRowHeight(row, "460", STHeightRule.AT_LEAST);  
  583.         XWPFTableCell cell = row.getCell(0);  
  584.         setCellShdStyle(cell, true"FFFFFF"null);  
  585.         p = getCellFirstParagraph(cell);  
  586.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  587.         setParagraphRunFontInfo(p, pRun, "A.负责人或部门资料 ﹡""宋体",  
  588.                 "Times New Roman""24"truefalsefalsefalsenullnull,  
  589.                 060);  
  590.         mergeCellsHorizontal(table, 003);  
  591.   
  592.         row = table.getRow(1);  
  593.         setRowHeight(row, "567", STHeightRule.AT_LEAST);  
  594.         cell = row.getCell(0);  
  595.         setCellWidthAndVAlign(cell, "2169", STTblWidth.DXA, STVerticalJc.TOP);  
  596.         p = getCellFirstParagraph(cell);  
  597.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  598.         setParagraphRunFontInfo(p, pRun, "1.负责人:""宋体""Times New Roman",  
  599.                 "21"falsefalsefalsefalsenullnull060);  
  600.   
  601.         cell = row.getCell(1);  
  602.         setCellWidthAndVAlign(cell, "3163", STTblWidth.DXA, STVerticalJc.TOP);  
  603.         p = getCellFirstParagraph(cell);  
  604.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  605.         setParagraphRunFontInfo(p, pRun, "2.负责部门:""宋体""Times New Roman",  
  606.                 "21"falsefalsefalsefalsenullnull060);  
  607.   
  608.         cell = row.getCell(2);  
  609.         setCellWidthAndVAlign(cell, "3692", STTblWidth.DXA, STVerticalJc.TOP);  
  610.         p = getCellFirstParagraph(cell);  
  611.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  612.         setParagraphRunFontInfo(p, pRun, "3.事件发生地点:""宋体""Times New Roman",  
  613.                 "21"falsefalsefalsefalsenullnull060);  
  614.         cell = row.getCell(3);  
  615.         setCellWidthAndVAlign(cell, "0", STTblWidth.AUTO, STVerticalJc.TOP);  
  616.         mergeCellsHorizontal(table, 123);  
  617.   
  618.         row = table.getRow(2);  
  619.         setRowHeight(row, "657", STHeightRule.AT_LEAST);  
  620.         cell = row.getCell(0);  
  621.         p = getCellFirstParagraph(cell);  
  622.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  623.         setParagraphRunFontInfo(p, pRun, "4.在场相关人员:""宋体""Times New Roman",  
  624.                 "21"falsefalsefalsefalsenullnull060);  
  625.         mergeCellsHorizontal(table, 203);  
  626.   
  627.         row = table.getRow(3);  
  628.         setRowHeight(row, "387", STHeightRule.AT_LEAST);  
  629.         cell = row.getCell(0);  
  630.         setCellShdStyle(cell, true"FFFFFF"null);  
  631.         p = getCellFirstParagraph(cell);  
  632.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  633.         setParagraphRunFontInfo(p, pRun, "B.不良事件情况 ﹡""宋体""Times New Roman",  
  634.                 "24"truefalsefalsefalsenullnull060);  
  635.         mergeCellsHorizontal(table, 303);  
  636.   
  637.         row = table.getRow(4);  
  638.         setRowHeight(row, "1613", STHeightRule.AT_LEAST);  
  639.         cell = row.getCell(0);  
  640.         p = getCellFirstParagraph(cell);  
  641.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  642.         setParagraphRunFontInfo(p, pRun, "5.事件主要表现:""宋体""Times New Roman",  
  643.                 "21"falsefalsefalsefalsenullnull060);  
  644.         mergeCellsHorizontal(table, 403);  
  645.   
  646.         row = table.getRow(5);  
  647.         setRowHeight(row, "369", STHeightRule.AT_LEAST);  
  648.         cell = row.getCell(0);  
  649.         setCellShdStyle(cell, true"FFFFFF"null);  
  650.         p = getCellFirstParagraph(cell);  
  651.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  652.         setParagraphRunFontInfo(p, pRun, "C.不良事件类别 ﹡""宋体""Times New Roman",  
  653.                 "24"truefalsefalsefalsenullnull060);  
  654.         mergeCellsHorizontal(table, 503);  
  655.   
  656.         row = table.getRow(6);  
  657.         cell = row.getCell(0);  
  658.         p = getCellFirstParagraph(cell);  
  659.         setParagraphSpacingInfo(p, true"0""0""0""0"true"300",  
  660.                 STLineSpacingRule.AUTO);  
  661.         setParagraphAlignInfo(p, ParagraphAlignment.BOTH, TextAlignment.CENTER);  
  662.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  663.         setParagraphRunSymInfo(p, pRun, "宋体""Times New Roman""21"true,  
  664.                 falsefalse060);  
  665.         setParagraphRunFontInfo(p, pRun, "××××××××××××××××××××××××××××""宋体",  
  666.                 "Times New Roman""21"truefalsefalsefalsenullnull,  
  667.                 060);  
  668.         setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");  
  669.         setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");  
  670.         setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");  
  671.         setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");  
  672.         setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");  
  673.         setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");  
  674.         setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");  
  675.         setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");  
  676.         setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");  
  677.         setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");  
  678.   
  679.         cell = row.getCell(2);  
  680.         p = getCellFirstParagraph(cell);  
  681.         setParagraphSpacingInfo(p, true"0""0""0""0"true"300",  
  682.                 STLineSpacingRule.AUTO);  
  683.         setParagraphAlignInfo(p, ParagraphAlignment.BOTH, TextAlignment.CENTER);  
  684.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  685.         setParagraphRunSymInfo(p, pRun, "宋体""Times New Roman""21"true,  
  686.                 falsefalse060);  
  687.         setParagraphRunFontInfo(p, pRun, "××××××××××××××××××××××××××××""宋体",  
  688.                 "Times New Roman""21"truefalsefalsefalsenullnull,  
  689.                 060);  
  690.         setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");  
  691.         setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");  
  692.         setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");  
  693.         setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");  
  694.         setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");  
  695.         setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");  
  696.         setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");  
  697.         setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");  
  698.   
  699.         mergeCellsHorizontal(table, 601);  
  700.         mergeCellsHorizontal(table, 623);  
  701.   
  702.         row = table.getRow(7);  
  703.         setRowHeight(row, "467", STHeightRule.AT_LEAST);  
  704.         cell = row.getCell(0);  
  705.         setCellShdStyle(cell, true"FFFFFF"null);  
  706.         p = getCellFirstParagraph(cell);  
  707.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  708.         setParagraphRunFontInfo(p, pRun, "D.不良事件的等级 *""宋体",  
  709.                 "Times New Roman""24"truefalsefalsefalsenullnull,  
  710.                 060);  
  711.         mergeCellsHorizontal(table, 703);  
  712.   
  713.         row = table.getRow(8);  
  714.         setRowHeight(row, "467", STHeightRule.AT_LEAST);  
  715.         cell = row.getCell(0);  
  716.         setCellShdStyle(cell, true"FFFFFF"null);  
  717.         p = getCellFirstParagraph(cell);  
  718.         setParagraphAlignInfo(p, ParagraphAlignment.CENTER,  
  719.                 TextAlignment.CENTER);  
  720.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  721.         setParagraphRunSymInfo(p, pRun, "宋体""Times New Roman""28"true,  
  722.                 falsefalse060);  
  723.         setParagraphRunFontInfo(p, pRun, "Ⅰ级事件""宋体""Times New Roman""28",  
  724.                 truefalsefalsefalsenullnull060);  
  725.         pRun = getOrAddParagraphFirstRun(p, truefalse);  
  726.         setParagraphRunSymInfo(p, pRun, "宋体""Times New Roman""28"true,  
  727.                 falsefalse060);  
  728.         setParagraphRunFontInfo(p, pRun, "Ⅱ级事件     ""宋体""Times New Roman",  
  729.                 "28"truefalsefalsefalsenullnull060);  
  730.         pRun = getOrAddParagraphFirstRun(p, truefalse);  
  731.         setParagraphRunSymInfo(p, pRun, "宋体""Times New Roman""28"true,  
  732.                 falsefalse060);  
  733.         setParagraphRunFontInfo(p, pRun, "Ⅲ级事件 ""宋体""Times New Roman",  
  734.                 "28"truefalsefalsefalsenullnull060);  
  735.         pRun = getOrAddParagraphFirstRun(p, truefalse);  
  736.         setParagraphRunSymInfo(p, pRun, "宋体""Times New Roman""28"true,  
  737.                 falsefalse060);  
  738.         setParagraphRunFontInfo(p, pRun, "Ⅳ级事件 ""宋体""Times New Roman",  
  739.                 "28"truefalsefalsefalsenullnull060);  
  740.         mergeCellsHorizontal(table, 803);  
  741.   
  742.         row = table.getRow(9);  
  743.         setRowHeight(row, "467", STHeightRule.AT_LEAST);  
  744.         cell = row.getCell(0);  
  745.         setCellShdStyle(cell, true"FFFFFF"null);  
  746.         p = getCellFirstParagraph(cell);  
  747.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  748.         setParagraphRunFontInfo(p, pRun, "E.事件发生的影响 *""宋体",  
  749.                 "Times New Roman""24"truefalsefalsefalsenullnull,  
  750.                 060);  
  751.         mergeCellsHorizontal(table, 903);  
  752.   
  753.         row = table.getRow(10);  
  754.         setRowHeight(row, "722", STHeightRule.AT_LEAST);  
  755.         mergeCellsHorizontal(table, 1003);  
  756.   
  757.         row = table.getRow(11);  
  758.         setRowHeight(row, "427", STHeightRule.AT_LEAST);  
  759.         cell = row.getCell(0);  
  760.         setCellShdStyle(cell, true"FFFFFF"null);  
  761.         p = getCellFirstParagraph(cell);  
  762.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  763.         setParagraphRunFontInfo(p, pRun, "F.事件发生后及时处理与分析 *""宋体",  
  764.                 "Times New Roman""24"truefalsefalsefalsenullnull,  
  765.                 060);  
  766.         mergeCellsHorizontal(table, 1103);  
  767.   
  768.         row = table.getRow(12);  
  769.         setRowHeight(row, "936", STHeightRule.AT_LEAST);  
  770.         cell = row.getCell(0);  
  771.         p = getCellFirstParagraph(cell);  
  772.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  773.         setParagraphRunFontInfo(p, pRun, "立即通知的人员:""宋体""Times New Roman",  
  774.                 "21"falsefalsefalsefalsenullnull060);  
  775.         mergeCellsHorizontal(table, 1203);  
  776.   
  777.         row = table.getRow(13);  
  778.         setRowHeight(row, "936", STHeightRule.AT_LEAST);  
  779.         cell = row.getCell(0);  
  780.         p = getCellFirstParagraph(cell);  
  781.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  782.         setParagraphRunFontInfo(p, pRun, "可能相关的因素:""宋体""Times New Roman",  
  783.                 "21"falsefalsefalsefalsenullnull060);  
  784.         mergeCellsHorizontal(table, 1303);  
  785.   
  786.         row = table.getRow(14);  
  787.         setRowHeight(row, "936", STHeightRule.AT_LEAST);  
  788.         cell = row.getCell(0);  
  789.         p = getCellFirstParagraph(cell);  
  790.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  791.         setParagraphRunFontInfo(p, pRun, "立即采取的措施:""宋体""Times New Roman",  
  792.                 "21"falsefalsefalsefalsenullnull060);  
  793.         mergeCellsHorizontal(table, 1403);  
  794.   
  795.         row = table.getRow(15);  
  796.         setRowHeight(row, "936", STHeightRule.AT_LEAST);  
  797.         cell = row.getCell(0);  
  798.         p = getCellFirstParagraph(cell);  
  799.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  800.         setParagraphRunFontInfo(p, pRun, "事件处理情况:""宋体""Times New Roman",  
  801.                 "21"falsefalsefalsefalsenullnull060);  
  802.         mergeCellsHorizontal(table, 1503);  
  803.   
  804.         row = table.getRow(16);  
  805.         setRowHeight(row, "460", STHeightRule.AT_LEAST);  
  806.         cell = row.getCell(0);  
  807.         setCellShdStyle(cell, true"FFFFFF"null);  
  808.         p = getCellFirstParagraph(cell);  
  809.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  810.         setParagraphRunFontInfo(p, pRun, "G.不良事件评价(主管部门填写) *""宋体",  
  811.                 "Times New Roman""24"truefalsefalsefalsenullnull,  
  812.                 060);  
  813.         mergeCellsHorizontal(table, 1603);  
  814.   
  815.         row = table.getRow(17);  
  816.         setRowHeight(row, "580", STHeightRule.AT_LEAST);  
  817.         cell = row.getCell(0);  
  818.         p = getCellFirstParagraph(cell);  
  819.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  820.         setParagraphRunFontInfo(p, pRun, "主管部门意见陈述:""宋体""Times New Roman",  
  821.                 "21"falsefalsefalsefalsenullnull060);  
  822.         mergeCellsHorizontal(table, 1703);  
  823.   
  824.         row = table.getRow(18);  
  825.         setRowHeight(row, "1157", STHeightRule.AT_LEAST);  
  826.         cell = row.getCell(0);  
  827.         setCellShdStyle(cell, true"FFFFFF"null);  
  828.         p = getCellFirstParagraph(cell);  
  829.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  830.         setParagraphRunFontInfo(p, pRun, "H.持续改进措施(主管部门填写) *""宋体",  
  831.                 "Times New Roman""24"truefalsefalsefalsenullnull,  
  832.                 060);  
  833.         mergeCellsHorizontal(table, 1803);  
  834.   
  835.         row = table.getRow(19);  
  836.         setRowHeight(row, "457", STHeightRule.AT_LEAST);  
  837.         cell = row.getCell(0);  
  838.         setCellShdStyle(cell, true"FFFFFF"null);  
  839.         p = getCellFirstParagraph(cell);  
  840.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  841.         setParagraphRunFontInfo(p, pRun, "I.选择性填写项目(Ⅰ、Ⅱ级事件必填 *,Ⅲ、Ⅳ级事件建议填写)",  
  842.                 "宋体""Times New Roman""24"truefalsefalsefalsenull,  
  843.                 null060);  
  844.         mergeCellsHorizontal(table, 1903);  
  845.   
  846.         row = table.getRow(20);  
  847.         setRowHeight(row, "567", STHeightRule.AT_LEAST);  
  848.         cell = row.getCell(0);  
  849.         p = getCellFirstParagraph(cell);  
  850.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  851.         setParagraphRunFontInfo(p, pRun, "报 告 人:    行政后勤人员 ""宋体",  
  852.                 "Times New Roman""21"falsefalsefalsefalsenull,  
  853.                 null060);  
  854.         pRun = getOrAddParagraphFirstRun(p, truefalse);  
  855.         setParagraphRunSymInfo(p, pRun, "宋体""Times New Roman""21"true,  
  856.                 falsefalse060);  
  857.         pRun = getOrAddParagraphFirstRun(p, truefalse);  
  858.         setParagraphRunFontInfo(p, pRun, "其他  ""宋体""Times New Roman",  
  859.                 "21"falsefalsefalsefalsenullnull060);  
  860.         pRun = getOrAddParagraphFirstRun(p, truefalse);  
  861.         setParagraphRunSymInfo(p, pRun, "宋体""Times New Roman""21"true,  
  862.                 falsefalse060);  
  863.   
  864.         p = cell.addParagraph();  
  865.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  866.         setParagraphRunFontInfo(p, pRun, "当事人的类别:本院""宋体""Times New Roman",  
  867.                 "21"falsefalsefalsefalsenullnull060);  
  868.         pRun = getOrAddParagraphFirstRun(p, truefalse);  
  869.         setParagraphRunSymInfo(p, pRun, "宋体""Times New Roman""21"true,  
  870.                 falsefalse060);  
  871.         pRun = getOrAddParagraphFirstRun(p, truefalse);  
  872.         setParagraphRunFontInfo(p, pRun, "    其他 ""宋体""Times New Roman",  
  873.                 "21"falsefalsefalsefalsenullnull060);  
  874.         pRun = getOrAddParagraphFirstRun(p, truefalse);  
  875.         setParagraphRunSymInfo(p, pRun, "宋体""Times New Roman""21"true,  
  876.                 falsefalse060);  
  877.   
  878.         p = cell.addParagraph();  
  879.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  880.         setParagraphRunFontInfo(p, pRun, "职    称:    高级 ""宋体",  
  881.                 "Times New Roman""21"falsefalsefalsefalsenull,  
  882.                 null060);  
  883.         pRun = getOrAddParagraphFirstRun(p, truefalse);  
  884.         setParagraphRunSymInfo(p, pRun, "宋体""Times New Roman""21"true,  
  885.                 falsefalse060);  
  886.         pRun = getOrAddParagraphFirstRun(p, truefalse);  
  887.         setParagraphRunFontInfo(p, pRun, "    中级 ""宋体""Times New Roman",  
  888.                 "21"falsefalsefalsefalsenullnull060);  
  889.         pRun = getOrAddParagraphFirstRun(p, truefalse);  
  890.         setParagraphRunSymInfo(p, pRun, "宋体""Times New Roman""21"true,  
  891.                 falsefalse060);  
  892.   
  893.         pRun = getOrAddParagraphFirstRun(p, truefalse);  
  894.         setParagraphRunFontInfo(p, pRun, "    初级 ""宋体""Times New Roman",  
  895.                 "21"falsefalsefalsefalsenullnull060);  
  896.         pRun = getOrAddParagraphFirstRun(p, truefalse);  
  897.         setParagraphRunSymInfo(p, pRun, "宋体""Times New Roman""21"true,  
  898.                 falsefalse060);  
  899.   
  900.         pRun = getOrAddParagraphFirstRun(p, truefalse);  
  901.         setParagraphRunFontInfo(p, pRun, "   其他 ""宋体""Times New Roman",  
  902.                 "21"falsefalsefalsefalsenullnull060);  
  903.         pRun = getOrAddParagraphFirstRun(p, truefalse);  
  904.         setParagraphRunSymInfo(p, pRun, "宋体""Times New Roman""21"true,  
  905.                 falsefalse060);  
  906.   
  907.         p = cell.addParagraph();  
  908.         p = cell.addParagraph();  
  909.         pRun = getOrAddParagraphFirstRun(p, falsefalse);  
  910.         setParagraphRunFontInfo(  
  911.                 p,  
  912.                 pRun,  
  913.                 "报告人签名:         科室:         联系电话:             Email:           ",  
  914.                 "宋体""Times New Roman""21"falsefalsefalsefalse,  
  915.                 nullnull060);  
  916.         mergeCellsHorizontal(table, 2003);  
  917.   
  918.         saveDocument(xdoc, "f:/saveFile/temp/sys_" + System.currentTimeMillis()  
  919.                 + ".docx");  
  920.     }  
  921. }  

    结果为:

    
POI 创建word 2007表单示例

 
此文为转载文章,非常感谢本文作者,本文原始链接: http://53873039oycg.iteye.com/blog/2194549   ,谢谢。



在最后展示一下本人亲测的wps打开样式,offic打开如上图无误。

POI 创建word 2007表单示例

     

全文完。