`
53873039oycg
  • 浏览: 837127 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

[简单]poi创建word 2007表格示例(二)

    博客分类:
  • poi
 
阅读更多

      应博友要求写下这个例子,office word 2007测试通过,见代码:

     

import java.io.FileOutputStream;
import java.math.BigInteger;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
import org.apache.poi.xwpf.usermodel.TextAlignment;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHeight;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHpsMeasure;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTShd;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSignedTwipsMeasure;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSpacing;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSym;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblBorders;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblGrid;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblGridCol;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTextScale;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTrPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVerticalJc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHeightRule;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHint;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STLineSpacingRule;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STShd;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalJc;

public class POI_07_创建表格示例_S4_Test {
	public static void main(String[] args) throws Exception {
		POI_07_创建表格示例_S4_Test t2 = new POI_07_创建表格示例_S4_Test();
		t2.createTable();
	}

	/**
	 * @Description: 添加方块♢
	 */
	public void setCellContentCommonFunction(XWPFTableCell cell, String content)
			throws Exception {
		XWPFParagraph p = cell.addParagraph();
		setParagraphSpacingInfo(p, true, "0", "0", "0", "0", true, "300",
				STLineSpacingRule.AUTO);
		setParagraphAlignInfo(p, ParagraphAlignment.BOTH, TextAlignment.CENTER);
		XWPFRun pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunSymInfo(p, pRun, "宋体", "Times New Roman", "21", true,
				false, false, 0, 6, 0);
		pRun = getOrAddParagraphFirstRun(p, true, false);
		setParagraphRunFontInfo(p, pRun, content, "宋体", "Times New Roman",
				"21", true, false, false, false, null, null, 0, 6, 0);
	}

	/**
	 * @Description: 保存文档
	 */
	public void saveDocument(XWPFDocument document, String savePath)
			throws Exception {
		FileOutputStream fos = new FileOutputStream(savePath);
		document.write(fos);
		fos.close();
	}

	/**
	 * @Description: 得到单元格第一个Paragraph
	 */
	public XWPFParagraph getCellFirstParagraph(XWPFTableCell cell) {
		XWPFParagraph p;
		if (cell.getParagraphs() != null && cell.getParagraphs().size() > 0) {
			p = cell.getParagraphs().get(0);
		} else {
			p = cell.addParagraph();
		}
		return p;
	}

	/**
	 * @Description: 得到段落CTPPr
	 */
	public CTPPr getParagraphCTPPr(XWPFParagraph p) {
		CTPPr pPPr = null;
		if (p.getCTP() != null) {
			if (p.getCTP().getPPr() != null) {
				pPPr = p.getCTP().getPPr();
			} else {
				pPPr = p.getCTP().addNewPPr();
			}
		}
		return pPPr;
	}

	/**
	 * @Description: 设置段落间距信息,一行=100 一磅=20
	 */
	public void setParagraphSpacingInfo(XWPFParagraph p, boolean isSpace,
			String before, String after, String beforeLines, String afterLines,
			boolean isLine, String line, STLineSpacingRule.Enum lineValue) {
		CTPPr pPPr = getParagraphCTPPr(p);
		CTSpacing pSpacing = pPPr.getSpacing() != null ? pPPr.getSpacing()
				: pPPr.addNewSpacing();
		if (isSpace) {
			// 段前磅数
			if (before != null) {
				pSpacing.setBefore(new BigInteger(before));
			}
			// 段后磅数
			if (after != null) {
				pSpacing.setAfter(new BigInteger(after));
			}
			// 段前行数
			if (beforeLines != null) {
				pSpacing.setBeforeLines(new BigInteger(beforeLines));
			}
			// 段后行数
			if (afterLines != null) {
				pSpacing.setAfterLines(new BigInteger(afterLines));
			}
		}
		// 间距
		if (isLine) {
			if (line != null) {
				pSpacing.setLine(new BigInteger(line));
			}
			if (lineValue != null) {
				pSpacing.setLineRule(lineValue);
			}
		}
	}

	/**
	 * @Description: 设置段落文本样式(高亮与底纹显示效果不同)设置字符间距信息(CTSignedTwipsMeasure)
	 * @param verticalAlign
	 *            : SUPERSCRIPT上标 SUBSCRIPT下标
	 * @param position
	 *            :字符间距位置:>0提升 <0降低=磅值*2 如3磅=6
	 * @param spacingValue
	 *            :字符间距间距 >0加宽 <0紧缩 =磅值*20 如2磅=40
	 * @param indent
	 *            :字符间距缩进 <100 缩
	 */

	public void setParagraphRunFontInfo(XWPFParagraph p, XWPFRun pRun,
			String content, String cnFontFamily, String enFontFamily,
			String fontSize, boolean isBlod, boolean isItalic,
			boolean isStrike, boolean isShd, String shdColor,
			STShd.Enum shdStyle, int position, int spacingValue, int indent) {
		CTRPr pRpr = getRunCTRPr(p, pRun);
		if (StringUtils.isNotBlank(content)) {
			// pRun.setText(content);
			if (content.contains("\n")) {// System.properties("line.separator")
				String[] lines = content.split("\n");
				pRun.setText(lines[0], 0); // set first line into XWPFRun
				for (int i = 1; i < lines.length; i++) {
					// add break and insert new text
					pRun.addBreak();
					pRun.setText(lines[i]);
				}
			} else {
				pRun.setText(content, 0);
			}
		}
		// 设置字体
		CTFonts fonts = pRpr.isSetRFonts() ? pRpr.getRFonts() : pRpr
				.addNewRFonts();
		if (StringUtils.isNotBlank(enFontFamily)) {
			fonts.setAscii(enFontFamily);
			fonts.setHAnsi(enFontFamily);
		}
		if (StringUtils.isNotBlank(cnFontFamily)) {
			fonts.setEastAsia(cnFontFamily);
			fonts.setHint(STHint.EAST_ASIA);
		}
		// 设置字体大小
		CTHpsMeasure sz = pRpr.isSetSz() ? pRpr.getSz() : pRpr.addNewSz();
		sz.setVal(new BigInteger(fontSize));

		CTHpsMeasure szCs = pRpr.isSetSzCs() ? pRpr.getSzCs() : pRpr
				.addNewSzCs();
		szCs.setVal(new BigInteger(fontSize));

		// 设置字体样式
		// 加粗
		if (isBlod) {
			pRun.setBold(isBlod);
		}
		// 倾斜
		if (isItalic) {
			pRun.setItalic(isItalic);
		}
		// 删除线
		if (isStrike) {
			pRun.setStrike(isStrike);
		}
		if (isShd) {
			// 设置底纹
			CTShd shd = pRpr.isSetShd() ? pRpr.getShd() : pRpr.addNewShd();
			if (shdStyle != null) {
				shd.setVal(shdStyle);
			}
			if (shdColor != null) {
				shd.setColor(shdColor);
				shd.setFill(shdColor);
			}
		}

		// 设置文本位置
		if (position != 0) {
			pRun.setTextPosition(position);
		}
		if (spacingValue > 0) {
			// 设置字符间距信息
			CTSignedTwipsMeasure ctSTwipsMeasure = pRpr.isSetSpacing() ? pRpr
					.getSpacing() : pRpr.addNewSpacing();
			ctSTwipsMeasure
					.setVal(new BigInteger(String.valueOf(spacingValue)));
		}
		if (indent > 0) {
			CTTextScale paramCTTextScale = pRpr.isSetW() ? pRpr.getW() : pRpr
					.addNewW();
			paramCTTextScale.setVal(indent);
		}
	}

	/**
	 * @Description: 得到XWPFRun的CTRPr
	 */
	public CTRPr getRunCTRPr(XWPFParagraph p, XWPFRun pRun) {
		CTRPr pRpr = null;
		if (pRun.getCTR() != null) {
			pRpr = pRun.getCTR().getRPr();
			if (pRpr == null) {
				pRpr = pRun.getCTR().addNewRPr();
			}
		} else {
			pRpr = p.getCTP().addNewR().addNewRPr();
		}
		return pRpr;
	}

	/**
	 * @Description: 设置段落对齐
	 */
	public void setParagraphAlignInfo(XWPFParagraph p,
			ParagraphAlignment pAlign, TextAlignment valign) {
		if (pAlign != null) {
			p.setAlignment(pAlign);
		}
		if (valign != null) {
			p.setVerticalAlignment(valign);
		}
	}

	public XWPFRun getOrAddParagraphFirstRun(XWPFParagraph p, boolean isInsert,
			boolean isNewLine) {
		XWPFRun pRun = null;
		if (isInsert) {
			pRun = p.createRun();
		} else {
			if (p.getRuns() != null && p.getRuns().size() > 0) {
				pRun = p.getRuns().get(0);
			} else {
				pRun = p.createRun();
			}
		}
		if (isNewLine) {
			pRun.addBreak();
		}
		return pRun;
	}

	/**
	 * @Description: 设置Table的边框
	 */
	public void setTableBorders(XWPFTable table, STBorder.Enum borderType,
			String size, String color, String space) {
		CTTblPr tblPr = getTableCTTblPr(table);
		CTTblBorders borders = tblPr.isSetTblBorders() ? tblPr.getTblBorders()
				: tblPr.addNewTblBorders();
		CTBorder hBorder = borders.isSetInsideH() ? borders.getInsideH()
				: borders.addNewInsideH();
		hBorder.setVal(borderType);
		hBorder.setSz(new BigInteger(size));
		hBorder.setColor(color);
		hBorder.setSpace(new BigInteger(space));

		CTBorder vBorder = borders.isSetInsideV() ? borders.getInsideV()
				: borders.addNewInsideV();
		vBorder.setVal(borderType);
		vBorder.setSz(new BigInteger(size));
		vBorder.setColor(color);
		vBorder.setSpace(new BigInteger(space));

		CTBorder lBorder = borders.isSetLeft() ? borders.getLeft() : borders
				.addNewLeft();
		lBorder.setVal(borderType);
		lBorder.setSz(new BigInteger(size));
		lBorder.setColor(color);
		lBorder.setSpace(new BigInteger(space));

		CTBorder rBorder = borders.isSetRight() ? borders.getRight() : borders
				.addNewRight();
		rBorder.setVal(borderType);
		rBorder.setSz(new BigInteger(size));
		rBorder.setColor(color);
		rBorder.setSpace(new BigInteger(space));

		CTBorder tBorder = borders.isSetTop() ? borders.getTop() : borders
				.addNewTop();
		tBorder.setVal(borderType);
		tBorder.setSz(new BigInteger(size));
		tBorder.setColor(color);
		tBorder.setSpace(new BigInteger(space));

		CTBorder bBorder = borders.isSetBottom() ? borders.getBottom()
				: borders.addNewBottom();
		bBorder.setVal(borderType);
		bBorder.setSz(new BigInteger(size));
		bBorder.setColor(color);
		bBorder.setSpace(new BigInteger(space));
	}

	/**
	 * @Description: 得到Table的CTTblPr,不存在则新建
	 */
	public CTTblPr getTableCTTblPr(XWPFTable table) {
		CTTbl ttbl = table.getCTTbl();
		CTTblPr tblPr = ttbl.getTblPr() == null ? ttbl.addNewTblPr() : ttbl
				.getTblPr();
		return tblPr;
	}

	/**
	 * @Description: 设置列宽和垂直对齐方式
	 */
	public void setCellWidthAndVAlign(XWPFTableCell cell, String width,
			STTblWidth.Enum typeEnum, STVerticalJc.Enum vAlign) {
		CTTcPr tcPr = getCellCTTcPr(cell);
		CTTblWidth tcw = tcPr.isSetTcW() ? tcPr.getTcW() : tcPr.addNewTcW();
		if (width != null) {
			tcw.setW(new BigInteger(width));
		}
		if (typeEnum != null) {
			tcw.setType(typeEnum);
		}
		if (vAlign != null) {
			CTVerticalJc vJc = tcPr.isSetVAlign() ? tcPr.getVAlign() : tcPr
					.addNewVAlign();
			vJc.setVal(vAlign);
		}
	}

	/**
	 * @Description: 跨列合并
	 */
	public void mergeCellsHorizontal(XWPFTable table, int row, int fromCell,
			int toCell) {
		for (int cellIndex = fromCell; cellIndex <= toCell; cellIndex++) {
			XWPFTableCell cell = table.getRow(row).getCell(cellIndex);
			if (cellIndex == fromCell) {
				// The first merged cell is set with RESTART merge value
				getCellCTTcPr(cell).addNewHMerge().setVal(STMerge.RESTART);
			} else {
				// Cells which join (merge) the first one,are set with CONTINUE
				getCellCTTcPr(cell).addNewHMerge().setVal(STMerge.CONTINUE);
			}
		}
	}

	/**
	 * 
	 * @Description: 得到Cell的CTTcPr,不存在则新建
	 */
	public CTTcPr getCellCTTcPr(XWPFTableCell cell) {
		CTTc cttc = cell.getCTTc();
		CTTcPr tcPr = cttc.isSetTcPr() ? cttc.getTcPr() : cttc.addNewTcPr();
		return tcPr;
	}

	/**
	 * @Description: 设置表格列宽
	 */
	public void setTableGridCol(XWPFTable table, int[] colWidths) {
		CTTbl ttbl = table.getCTTbl();
		CTTblGrid tblGrid = ttbl.getTblGrid() != null ? ttbl.getTblGrid()
				: ttbl.addNewTblGrid();
		for (int j = 0, len = colWidths.length; j < len; j++) {
			CTTblGridCol gridCol = tblGrid.addNewGridCol();
			gridCol.setW(new BigInteger(String.valueOf(colWidths[j])));
		}
	}

	public void setParagraphRunSymInfo(XWPFParagraph p, XWPFRun pRun,
			String cnFontFamily, String enFontFamily, String fontSize,
			boolean isBlod, boolean isItalic, boolean isStrike, int position,
			int spacingValue, int indent) throws Exception {
		CTRPr pRpr = getRunCTRPr(p, pRun);
		// 设置字体
		CTFonts fonts = pRpr.isSetRFonts() ? pRpr.getRFonts() : pRpr
				.addNewRFonts();
		if (StringUtils.isNotBlank(enFontFamily)) {
			fonts.setAscii(enFontFamily);
			fonts.setHAnsi(enFontFamily);
		}
		if (StringUtils.isNotBlank(cnFontFamily)) {
			fonts.setEastAsia(cnFontFamily);
			fonts.setHint(STHint.EAST_ASIA);
		}
		// 设置字体大小
		CTHpsMeasure sz = pRpr.isSetSz() ? pRpr.getSz() : pRpr.addNewSz();
		sz.setVal(new BigInteger(fontSize));

		CTHpsMeasure szCs = pRpr.isSetSzCs() ? pRpr.getSzCs() : pRpr
				.addNewSzCs();
		szCs.setVal(new BigInteger(fontSize));

		// 设置字体样式
		// 加粗
		if (isBlod) {
			pRun.setBold(isBlod);
		}
		// 倾斜
		if (isItalic) {
			pRun.setItalic(isItalic);
		}
		// 删除线
		if (isStrike) {
			pRun.setStrike(isStrike);
		}
		// 设置文本位置
		if (position != 0) {
			pRun.setTextPosition(position);
		}
		if (spacingValue > 0) {
			// 设置字符间距信息
			CTSignedTwipsMeasure ctSTwipsMeasure = pRpr.isSetSpacing() ? pRpr
					.getSpacing() : pRpr.addNewSpacing();
			ctSTwipsMeasure
					.setVal(new BigInteger(String.valueOf(spacingValue)));
		}
		if (indent > 0) {
			CTTextScale paramCTTextScale = pRpr.isSetW() ? pRpr.getW() : pRpr
					.addNewW();
			paramCTTextScale.setVal(indent);
		}
		List<CTSym> symList = pRun.getCTR().getSymList();
		CTSym sym = CTSym.Factory
				.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>");
		symList.add(sym);
	}

	/**
	 * @Description: 设置表格总宽度与水平对齐方式
	 */
	public void setTableWidthAndHAlign(XWPFTable table, String width,
			STJc.Enum enumValue) {
		CTTblPr tblPr = getTableCTTblPr(table);
		CTTblWidth tblWidth = tblPr.isSetTblW() ? tblPr.getTblW() : tblPr
				.addNewTblW();
		if (enumValue != null) {
			CTJc cTJc = tblPr.addNewJc();
			cTJc.setVal(enumValue);
		}
		tblWidth.setW(new BigInteger(width));
		tblWidth.setType(STTblWidth.DXA);
	}

	/**
	 * @Description: 设置单元格Margin
	 */
	public void setTableCellMargin(XWPFTable table, int top, int left,
			int bottom, int right) {
		table.setCellMargins(top, left, bottom, right);
	}

	/**
	 * @Description: 得到CTTrPr,不存在则新建
	 */
	public CTTrPr getRowCTTrPr(XWPFTableRow row) {
		CTRow ctRow = row.getCtRow();
		CTTrPr trPr = ctRow.isSetTrPr() ? ctRow.getTrPr() : ctRow.addNewTrPr();
		return trPr;
	}

	/**
	 * @Description: 设置行高
	 */
	public void setRowHeight(XWPFTableRow row, String hight,
			STHeightRule.Enum heigthEnum) {
		CTTrPr trPr = getRowCTTrPr(row);
		CTHeight trHeight;
		if (trPr.getTrHeightList() != null && trPr.getTrHeightList().size() > 0) {
			trHeight = trPr.getTrHeightList().get(0);
		} else {
			trHeight = trPr.addNewTrHeight();
		}
		trHeight.setVal(new BigInteger(hight));
		if (heigthEnum != null) {
			trHeight.setHRule(heigthEnum);
		}
	}

	/**
	 * @Description: 设置底纹
	 */
	public void setCellShdStyle(XWPFTableCell cell, boolean isShd,
			String shdColor, STShd.Enum shdStyle) {
		CTTcPr tcPr = getCellCTTcPr(cell);
		if (isShd) {
			// 设置底纹
			CTShd shd = tcPr.isSetShd() ? tcPr.getShd() : tcPr.addNewShd();
			if (shdStyle != null) {
				shd.setVal(shdStyle);
			}
			if (shdColor != null) {
				shd.setColor(shdColor);
				shd.setFill(shdColor);
			}
		}
	}

	public void createTable() throws Exception {
		XWPFDocument xdoc = new XWPFDocument();

		XWPFParagraph p = xdoc.createParagraph();
		// 固定值25磅
		setParagraphSpacingInfo(p, true, "0", "80", null, null, true, "500",
				STLineSpacingRule.EXACT);
		// 居中
		setParagraphAlignInfo(p, ParagraphAlignment.CENTER,
				TextAlignment.CENTER);
		XWPFRun pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "××××(××)事件报告表", "宋体",
				"Times New Roman", "36", true, false, false, false, null, null,
				0, 0, 90);

		p = xdoc.createParagraph();
		// 固定值25磅
		setParagraphSpacingInfo(p, true, "0", "80", null, null, true, "500",
				STLineSpacingRule.EXACT);
		// 居中
		setParagraphAlignInfo(p, ParagraphAlignment.CENTER,
				TextAlignment.CENTER);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "(××××××)", "宋体", "Times New Roman",
				"36", true, false, false, false, null, null, 0, 0, 90);

		p = xdoc.createParagraph();
		// 单倍行距
		setParagraphSpacingInfo(p, true, "0", "0", "0", "0", true, "240",
				STLineSpacingRule.AUTO);
		setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "﹡报告日期:年月日﹡ 事件发生日期:年月日", "宋体",
				"Times New Roman", "24", true, false, false, false, null, null,
				0, 6, 0);

		// 创建表格21行3列
		XWPFTable table = xdoc.createTable(21, 4);
		setTableBorders(table, STBorder.SINGLE, "4", "auto", "0");
		setTableWidthAndHAlign(table, "9024", STJc.CENTER);
		setTableCellMargin(table, 0, 108, 0, 108);
		int[] colWidths = new int[] { 2169, 2638, 525, 3692 };
		setTableGridCol(table, colWidths);

		XWPFTableRow row = table.getRow(0);
		setRowHeight(row, "460", STHeightRule.AT_LEAST);
		XWPFTableCell cell = row.getCell(0);
		setCellShdStyle(cell, true, "FFFFFF", null);
		p = getCellFirstParagraph(cell);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "A.负责人或部门资料 ﹡", "宋体",
				"Times New Roman", "24", true, false, false, false, null, null,
				0, 6, 0);
		mergeCellsHorizontal(table, 0, 0, 3);

		row = table.getRow(1);
		setRowHeight(row, "567", STHeightRule.AT_LEAST);
		cell = row.getCell(0);
		setCellWidthAndVAlign(cell, "2169", STTblWidth.DXA, STVerticalJc.TOP);
		p = getCellFirstParagraph(cell);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "1.负责人:", "宋体", "Times New Roman",
				"21", false, false, false, false, null, null, 0, 6, 0);

		cell = row.getCell(1);
		setCellWidthAndVAlign(cell, "3163", STTblWidth.DXA, STVerticalJc.TOP);
		p = getCellFirstParagraph(cell);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "2.负责部门:", "宋体", "Times New Roman",
				"21", false, false, false, false, null, null, 0, 6, 0);

		cell = row.getCell(2);
		setCellWidthAndVAlign(cell, "3692", STTblWidth.DXA, STVerticalJc.TOP);
		p = getCellFirstParagraph(cell);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "3.事件发生地点:", "宋体", "Times New Roman",
				"21", false, false, false, false, null, null, 0, 6, 0);
		cell = row.getCell(3);
		setCellWidthAndVAlign(cell, "0", STTblWidth.AUTO, STVerticalJc.TOP);
		mergeCellsHorizontal(table, 1, 2, 3);

		row = table.getRow(2);
		setRowHeight(row, "657", STHeightRule.AT_LEAST);
		cell = row.getCell(0);
		p = getCellFirstParagraph(cell);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "4.在场相关人员:", "宋体", "Times New Roman",
				"21", false, false, false, false, null, null, 0, 6, 0);
		mergeCellsHorizontal(table, 2, 0, 3);

		row = table.getRow(3);
		setRowHeight(row, "387", STHeightRule.AT_LEAST);
		cell = row.getCell(0);
		setCellShdStyle(cell, true, "FFFFFF", null);
		p = getCellFirstParagraph(cell);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "B.不良事件情况 ﹡", "宋体", "Times New Roman",
				"24", true, false, false, false, null, null, 0, 6, 0);
		mergeCellsHorizontal(table, 3, 0, 3);

		row = table.getRow(4);
		setRowHeight(row, "1613", STHeightRule.AT_LEAST);
		cell = row.getCell(0);
		p = getCellFirstParagraph(cell);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "5.事件主要表现:", "宋体", "Times New Roman",
				"21", false, false, false, false, null, null, 0, 6, 0);
		mergeCellsHorizontal(table, 4, 0, 3);

		row = table.getRow(5);
		setRowHeight(row, "369", STHeightRule.AT_LEAST);
		cell = row.getCell(0);
		setCellShdStyle(cell, true, "FFFFFF", null);
		p = getCellFirstParagraph(cell);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "C.不良事件类别 ﹡", "宋体", "Times New Roman",
				"24", true, false, false, false, null, null, 0, 6, 0);
		mergeCellsHorizontal(table, 5, 0, 3);

		row = table.getRow(6);
		cell = row.getCell(0);
		p = getCellFirstParagraph(cell);
		setParagraphSpacingInfo(p, true, "0", "0", "0", "0", true, "300",
				STLineSpacingRule.AUTO);
		setParagraphAlignInfo(p, ParagraphAlignment.BOTH, TextAlignment.CENTER);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunSymInfo(p, pRun, "宋体", "Times New Roman", "21", true,
				false, false, 0, 6, 0);
		setParagraphRunFontInfo(p, pRun, "××××××××××××××××××××××××××××", "宋体",
				"Times New Roman", "21", true, false, false, false, null, null,
				0, 6, 0);
		setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");
		setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");
		setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");
		setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");
		setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");
		setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");
		setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");
		setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");
		setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");
		setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");

		cell = row.getCell(2);
		p = getCellFirstParagraph(cell);
		setParagraphSpacingInfo(p, true, "0", "0", "0", "0", true, "300",
				STLineSpacingRule.AUTO);
		setParagraphAlignInfo(p, ParagraphAlignment.BOTH, TextAlignment.CENTER);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunSymInfo(p, pRun, "宋体", "Times New Roman", "21", true,
				false, false, 0, 6, 0);
		setParagraphRunFontInfo(p, pRun, "××××××××××××××××××××××××××××", "宋体",
				"Times New Roman", "21", true, false, false, false, null, null,
				0, 6, 0);
		setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");
		setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");
		setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");
		setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");
		setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");
		setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");
		setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");
		setCellContentCommonFunction(cell, "××××××××××××××××××××××××××××");

		mergeCellsHorizontal(table, 6, 0, 1);
		mergeCellsHorizontal(table, 6, 2, 3);

		row = table.getRow(7);
		setRowHeight(row, "467", STHeightRule.AT_LEAST);
		cell = row.getCell(0);
		setCellShdStyle(cell, true, "FFFFFF", null);
		p = getCellFirstParagraph(cell);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "D.不良事件的等级 *", "宋体",
				"Times New Roman", "24", true, false, false, false, null, null,
				0, 6, 0);
		mergeCellsHorizontal(table, 7, 0, 3);

		row = table.getRow(8);
		setRowHeight(row, "467", STHeightRule.AT_LEAST);
		cell = row.getCell(0);
		setCellShdStyle(cell, true, "FFFFFF", null);
		p = getCellFirstParagraph(cell);
		setParagraphAlignInfo(p, ParagraphAlignment.CENTER,
				TextAlignment.CENTER);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunSymInfo(p, pRun, "宋体", "Times New Roman", "28", true,
				false, false, 0, 6, 0);
		setParagraphRunFontInfo(p, pRun, "Ⅰ级事件", "宋体", "Times New Roman", "28",
				true, false, false, false, null, null, 0, 6, 0);
		pRun = getOrAddParagraphFirstRun(p, true, false);
		setParagraphRunSymInfo(p, pRun, "宋体", "Times New Roman", "28", true,
				false, false, 0, 6, 0);
		setParagraphRunFontInfo(p, pRun, "Ⅱ级事件     ", "宋体", "Times New Roman",
				"28", true, false, false, false, null, null, 0, 6, 0);
		pRun = getOrAddParagraphFirstRun(p, true, false);
		setParagraphRunSymInfo(p, pRun, "宋体", "Times New Roman", "28", true,
				false, false, 0, 6, 0);
		setParagraphRunFontInfo(p, pRun, "Ⅲ级事件 ", "宋体", "Times New Roman",
				"28", true, false, false, false, null, null, 0, 6, 0);
		pRun = getOrAddParagraphFirstRun(p, true, false);
		setParagraphRunSymInfo(p, pRun, "宋体", "Times New Roman", "28", true,
				false, false, 0, 6, 0);
		setParagraphRunFontInfo(p, pRun, "Ⅳ级事件 ", "宋体", "Times New Roman",
				"28", true, false, false, false, null, null, 0, 6, 0);
		mergeCellsHorizontal(table, 8, 0, 3);

		row = table.getRow(9);
		setRowHeight(row, "467", STHeightRule.AT_LEAST);
		cell = row.getCell(0);
		setCellShdStyle(cell, true, "FFFFFF", null);
		p = getCellFirstParagraph(cell);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "E.事件发生的影响 *", "宋体",
				"Times New Roman", "24", true, false, false, false, null, null,
				0, 6, 0);
		mergeCellsHorizontal(table, 9, 0, 3);

		row = table.getRow(10);
		setRowHeight(row, "722", STHeightRule.AT_LEAST);
		mergeCellsHorizontal(table, 10, 0, 3);

		row = table.getRow(11);
		setRowHeight(row, "427", STHeightRule.AT_LEAST);
		cell = row.getCell(0);
		setCellShdStyle(cell, true, "FFFFFF", null);
		p = getCellFirstParagraph(cell);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "F.事件发生后及时处理与分析 *", "宋体",
				"Times New Roman", "24", true, false, false, false, null, null,
				0, 6, 0);
		mergeCellsHorizontal(table, 11, 0, 3);

		row = table.getRow(12);
		setRowHeight(row, "936", STHeightRule.AT_LEAST);
		cell = row.getCell(0);
		p = getCellFirstParagraph(cell);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "立即通知的人员:", "宋体", "Times New Roman",
				"21", false, false, false, false, null, null, 0, 6, 0);
		mergeCellsHorizontal(table, 12, 0, 3);

		row = table.getRow(13);
		setRowHeight(row, "936", STHeightRule.AT_LEAST);
		cell = row.getCell(0);
		p = getCellFirstParagraph(cell);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "可能相关的因素:", "宋体", "Times New Roman",
				"21", false, false, false, false, null, null, 0, 6, 0);
		mergeCellsHorizontal(table, 13, 0, 3);

		row = table.getRow(14);
		setRowHeight(row, "936", STHeightRule.AT_LEAST);
		cell = row.getCell(0);
		p = getCellFirstParagraph(cell);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "立即采取的措施:", "宋体", "Times New Roman",
				"21", false, false, false, false, null, null, 0, 6, 0);
		mergeCellsHorizontal(table, 14, 0, 3);

		row = table.getRow(15);
		setRowHeight(row, "936", STHeightRule.AT_LEAST);
		cell = row.getCell(0);
		p = getCellFirstParagraph(cell);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "事件处理情况:", "宋体", "Times New Roman",
				"21", false, false, false, false, null, null, 0, 6, 0);
		mergeCellsHorizontal(table, 15, 0, 3);

		row = table.getRow(16);
		setRowHeight(row, "460", STHeightRule.AT_LEAST);
		cell = row.getCell(0);
		setCellShdStyle(cell, true, "FFFFFF", null);
		p = getCellFirstParagraph(cell);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "G.不良事件评价(主管部门填写) *", "宋体",
				"Times New Roman", "24", true, false, false, false, null, null,
				0, 6, 0);
		mergeCellsHorizontal(table, 16, 0, 3);

		row = table.getRow(17);
		setRowHeight(row, "580", STHeightRule.AT_LEAST);
		cell = row.getCell(0);
		p = getCellFirstParagraph(cell);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "主管部门意见陈述:", "宋体", "Times New Roman",
				"21", false, false, false, false, null, null, 0, 6, 0);
		mergeCellsHorizontal(table, 17, 0, 3);

		row = table.getRow(18);
		setRowHeight(row, "1157", STHeightRule.AT_LEAST);
		cell = row.getCell(0);
		setCellShdStyle(cell, true, "FFFFFF", null);
		p = getCellFirstParagraph(cell);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "H.持续改进措施(主管部门填写) *", "宋体",
				"Times New Roman", "24", true, false, false, false, null, null,
				0, 6, 0);
		mergeCellsHorizontal(table, 18, 0, 3);

		row = table.getRow(19);
		setRowHeight(row, "457", STHeightRule.AT_LEAST);
		cell = row.getCell(0);
		setCellShdStyle(cell, true, "FFFFFF", null);
		p = getCellFirstParagraph(cell);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "I.选择性填写项目(Ⅰ、Ⅱ级事件必填 *,Ⅲ、Ⅳ级事件建议填写)",
				"宋体", "Times New Roman", "24", true, false, false, false, null,
				null, 0, 6, 0);
		mergeCellsHorizontal(table, 19, 0, 3);

		row = table.getRow(20);
		setRowHeight(row, "567", STHeightRule.AT_LEAST);
		cell = row.getCell(0);
		p = getCellFirstParagraph(cell);
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "报 告 人:    行政后勤人员 ", "宋体",
				"Times New Roman", "21", false, false, false, false, null,
				null, 0, 6, 0);
		pRun = getOrAddParagraphFirstRun(p, true, false);
		setParagraphRunSymInfo(p, pRun, "宋体", "Times New Roman", "21", true,
				false, false, 0, 6, 0);
		pRun = getOrAddParagraphFirstRun(p, true, false);
		setParagraphRunFontInfo(p, pRun, "其他  ", "宋体", "Times New Roman",
				"21", false, false, false, false, null, null, 0, 6, 0);
		pRun = getOrAddParagraphFirstRun(p, true, false);
		setParagraphRunSymInfo(p, pRun, "宋体", "Times New Roman", "21", true,
				false, false, 0, 6, 0);

		p = cell.addParagraph();
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "当事人的类别:本院", "宋体", "Times New Roman",
				"21", false, false, false, false, null, null, 0, 6, 0);
		pRun = getOrAddParagraphFirstRun(p, true, false);
		setParagraphRunSymInfo(p, pRun, "宋体", "Times New Roman", "21", true,
				false, false, 0, 6, 0);
		pRun = getOrAddParagraphFirstRun(p, true, false);
		setParagraphRunFontInfo(p, pRun, "    其他 ", "宋体", "Times New Roman",
				"21", false, false, false, false, null, null, 0, 6, 0);
		pRun = getOrAddParagraphFirstRun(p, true, false);
		setParagraphRunSymInfo(p, pRun, "宋体", "Times New Roman", "21", true,
				false, false, 0, 6, 0);

		p = cell.addParagraph();
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(p, pRun, "职    称:    高级 ", "宋体",
				"Times New Roman", "21", false, false, false, false, null,
				null, 0, 6, 0);
		pRun = getOrAddParagraphFirstRun(p, true, false);
		setParagraphRunSymInfo(p, pRun, "宋体", "Times New Roman", "21", true,
				false, false, 0, 6, 0);
		pRun = getOrAddParagraphFirstRun(p, true, false);
		setParagraphRunFontInfo(p, pRun, "    中级 ", "宋体", "Times New Roman",
				"21", false, false, false, false, null, null, 0, 6, 0);
		pRun = getOrAddParagraphFirstRun(p, true, false);
		setParagraphRunSymInfo(p, pRun, "宋体", "Times New Roman", "21", true,
				false, false, 0, 6, 0);

		pRun = getOrAddParagraphFirstRun(p, true, false);
		setParagraphRunFontInfo(p, pRun, "    初级 ", "宋体", "Times New Roman",
				"21", false, false, false, false, null, null, 0, 6, 0);
		pRun = getOrAddParagraphFirstRun(p, true, false);
		setParagraphRunSymInfo(p, pRun, "宋体", "Times New Roman", "21", true,
				false, false, 0, 6, 0);

		pRun = getOrAddParagraphFirstRun(p, true, false);
		setParagraphRunFontInfo(p, pRun, "   其他 ", "宋体", "Times New Roman",
				"21", false, false, false, false, null, null, 0, 6, 0);
		pRun = getOrAddParagraphFirstRun(p, true, false);
		setParagraphRunSymInfo(p, pRun, "宋体", "Times New Roman", "21", true,
				false, false, 0, 6, 0);

		p = cell.addParagraph();
		p = cell.addParagraph();
		pRun = getOrAddParagraphFirstRun(p, false, false);
		setParagraphRunFontInfo(
				p,
				pRun,
				"报告人签名:         科室:         联系电话:             Email:           ",
				"宋体", "Times New Roman", "21", false, false, false, false,
				null, null, 0, 6, 0);
		mergeCellsHorizontal(table, 20, 0, 3);

		saveDocument(xdoc, "f:/saveFile/temp/sys_" + System.currentTimeMillis()
				+ ".docx");
	}
}

    结果为:

   

 

    本文系原创,转载请注明出处,本文原始链接: http://53873039oycg.iteye.com/blog/2194549   ,谢谢。

     全文完。

  • 大小: 96.5 KB
0
0
分享到:
评论
9 楼 cm0924 2017-11-02  
跨列不支持wps啊 ,有没有解决办法?
8 楼 fuwen1989 2017-07-26  
lengfeng80 写道
问下用的poi版本是3.11的嘛,
我用这个例子提示
java.lang.NoClassDefFoundError: org/openxmlformats/schemas/wordprocessingml/x2006/main/impl/CTTcImpl$1PList,
不知道缺少了哪个包,本身代码没有提示缺少类,运行时候才跑异常。



我重新整理了个程序,可以直接运行,里面包含必备的JAR包
http://blog.csdn.net/fuwen1989/article/details/76130701
7 楼 sbfivwsll 2017-04-25  
必须得ooxml-schemas-1.X.jar,
poi-ooxml-schemas-XX.jar包不得行得。
下载地址:
https://repo1.maven.org/maven2/org/apache/poi/ooxml-schemas/1.3/
6 楼 Action-人生 2016-04-07  
博主请问你的版本是多少啊?能不能把jar都附带一份啊,我这边在官网下的最新的3.14拷贝了你的代码,发现提示少import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHeightRule,
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHint,,请问一下是不是缺少啥jar包,现在急,望博主指明道。。。。。谢谢
5 楼 lengfeng80 2015-03-30  
53873039oycg 写道
lengfeng80 写道
问下用的poi版本是3.11的嘛,
我用这个例子提示
java.lang.NoClassDefFoundError: org/openxmlformats/schemas/wordprocessingml/x2006/main/impl/CTTcImpl$1PList,
不知道缺少了哪个包,本身代码没有提示缺少类,运行时候才跑异常。

ooxml-schemas-1.1.jar有这个包吗?


果然是少了这个包,我还以为poi-ooxml-schemas-3.11-20141221.jar 跟这个是一样的,谢谢哈
4 楼 lengfeng80 2015-03-30  
53873039oycg 写道
lengfeng80 写道
问下用的poi版本是3.11的嘛,
我用这个例子提示
java.lang.NoClassDefFoundError: org/openxmlformats/schemas/wordprocessingml/x2006/main/impl/CTTcImpl$1PList,
不知道缺少了哪个包,本身代码没有提示缺少类,运行时候才跑异常。

ooxml-schemas-1.1.jar有这个包吗?

poi-ooxml-schemas-3.11-20141221.jar 我这边是这个包。
3 楼 53873039oycg 2015-03-27  
lengfeng80 写道
问下用的poi版本是3.11的嘛,
我用这个例子提示
java.lang.NoClassDefFoundError: org/openxmlformats/schemas/wordprocessingml/x2006/main/impl/CTTcImpl$1PList,
不知道缺少了哪个包,本身代码没有提示缺少类,运行时候才跑异常。

ooxml-schemas-1.1.jar有这个包吗?
2 楼 lengfeng80 2015-03-27  
问下用的poi版本是3.11的嘛,
我用这个例子提示
java.lang.NoClassDefFoundError: org/openxmlformats/schemas/wordprocessingml/x2006/main/impl/CTTcImpl$1PList,
不知道缺少了哪个包,本身代码没有提示缺少类,运行时候才跑异常。
1 楼 a754782339 2015-03-22  
老大万岁  

相关推荐

    POI读取 word 2003 和 word 2007 的例子

    word 2007 示例文件 值得注意的是 POI 在读取 word 文件的时候不会读取 word 文件中的图片信息 还有就是对于 2007 版的 word docx 如果 word 文件中有表格 所有表格中的数据都会在读取出来的字符串的最后 "&gt;这是一个...

    [简单]poi读取word 2007简单文本框值

    以下是一个简单的示例代码,演示如何使用Apache POI读取Word 2007文档中的文本框: ```java import org.apache.poi.xwpf.usermodel.*; public class ReadWordTextBox { public static void main(String[] args) ...

    poi操作word表格

    使用Apache POI,我们可以创建、修改、读取和格式化Word文档中的表格。以下是一些关键知识点: 1. **创建表格**: - 使用`XWPFDocument`类来创建一个新的Word文档实例。 - 通过`createTable()`方法创建表格,并...

    poi将word转换成html、样式 表格 图片处理

    Apache POI 是一个开源项目,专门用于处理微软的Office文档格式,如Word(.doc, .docx)、Excel(.xls, .xlsx)等。在本案例中,我们关注的是如何使用Apache POI将Word文档转换为HTML格式,并且保持原有的样式、表格...

    Java Poi流根据Word模板插入相应的文本、表格和图片,并生成新的Word报告。

    在这个场景中,我们关注的是如何利用Java POI库通过Word模板生成包含特定文本、表格和图片的报告。 首先,我们需要了解Java POI中的XWPFDocument类,它是用来处理.docx文件的。XWPFDocument可以读取、修改和创建...

    Apache poi 根据word模板生成word报表 替换 循环列表 图片

    下面是一个简单的代码示例,展示如何执行这些操作: ```java // 初始化Word模板 XWPFDocument doc = new XWPFDocument(new FileInputStream("template.docx")); // 替换文本 List&lt;XWPFParagraph&gt; paragraphs = doc...

    poi 解析 office excel 2003,2007 word 2003,2007 的示例

    本示例将详细介绍如何使用Apache POI解析Office Excel 2003和2007,以及Word 2003和2007的文件。 首先,我们来看Excel的解析。Excel 2003使用的是.BOOK文件格式(HSSFWorkbook),而2007及以上版本使用的是.XLSX...

    POI生成word文档

    在你的案例中,"POI2word"可能是包含示例代码和所需资源的文件夹。你可以通过阅读这些代码来了解如何将数据库中的题目数据转换为Word文档,并结合模板进行排版和图片插入。记得,处理复杂格式和模板时,可能需要对...

    java Apache poi word模板 表格模板 word报表.zip

    `XWPFTable`和`XWPFTableRow`是Apache POI用于创建和操作Word表格的主要类。你可以预先在模板中设计好表格结构,然后在运行时填充数据。表格的行和列可以通过这些类的方法进行添加、删除和修改。 4. **Word报表...

    利用poi+word模版书签,向word中插入数据

    本教程将深入讲解如何利用Apache POI的XWPF模块结合Word模板中的书签,实现数据的动态插入,从而创建个性化的Word文档。 首先,我们需要理解Apache POI的XWPF模块。XWPF(XML Word Processing)是POI项目的一部分,...

    poi解析excel、word2007,2010等版本

    本项目中的"poiTest"是一个Web应用示例,它演示了如何使用Apache POI来解析不同版本的Excel(如2007、2010)以及Word2007和2010文档。 1. **Apache POI 简介** Apache POI 是由Apache软件基金会开发的一个项目,...

    poi完美word转html

    2. 只支持DOC不支持DOCX:代码示例仅适用于旧版的Word文档格式(.doc),对于新版的Word文档格式(.docx),需要使用不同的方法或更高版本的POI库。 六、扩展阅读与资源: 为了更深入地理解和应用Apache POI进行...

    poi 将echar报表生成到word table表格中

    这个图片文件将是插入到Word表格中的元素。 以下是实现这一功能的基本步骤: 1. **创建Word文档**:初始化`XWPFDocument`对象,并创建一个新的`XWPFParagraph`。 2. **创建表格**:使用`XWPFDocument.createTable...

    java POI完整示例,POI将word转HTML,数据库倒出数据到Excel等

    Java POI是一个强大的库,主要用于处理Microsoft Office格式的文件,如Word、Excel和PowerPoint。在本示例中,我们将探讨如何使用POI进行一系列操作,包括将Word文档转换为HTML,以及从数据库导出数据到Excel。 1. ...

    poiWord2003和Word2007包括图片完整转换成html 包括完整Jar包

    1. **Apache POI基础**:Apache POI提供了HSSF和XSSF两个API,分别用于读写老版本的BIFF8格式(如Word2003的.doc文件)和新的OOXML格式(如Word2007的.docx文件)。HSSF对应于Excel,而XSSF则对应于Word和PowerPoint...

    POI word目录处理备忘

    标题“POI word目录处理备忘”涉及到的是Apache POI库在处理Microsoft Word文档时,尤其是涉及Word文档目录(TOC,Table of Contents)的操作。Apache POI是一个流行的开源Java库,它允许开发者读取、写入和修改...

    基于poi导出word以及图片

    通过以上步骤,你就可以使用Apache POI 3.13来创建、编辑并导出包含文本和图片的Word文档了。注意,这只是一个基础示例,实际应用中可能需要处理更复杂的情况,比如样式设置、页眉页脚、页码等。在处理大量数据时,...

    java运用poi填充word数据并将多个word合并为一个

    Apache POI是一个开源项目,提供了一组API来处理Microsoft Office格式的文件,如DOCX(Word 2007及以上版本)和DOC(Word 97-2003)。在Java应用中,我们通常使用XWPF(XML Word Processing)API来操作DOCX文件,而...

    POI实现word和excel在线预览

    在IT行业中,Apache POI是一个广泛使用的库,主要用于读取、写入Microsoft Office格式的文件,包括Word(.doc/.docx)和Excel(.xls/.xlsx)文档。本项目提供的"POI实现word和excel在线预览"是基于Apache POI的一个...

Global site tag (gtag.js) - Google Analytics