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

[简单] poi word2007简单图文混排

    博客分类:
  • poi
 
阅读更多

       直接上代码:

      

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
import org.apache.poi.xwpf.usermodel.Borders;
import org.apache.poi.xwpf.usermodel.BreakType;
import org.apache.poi.xwpf.usermodel.Document;
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
import org.apache.poi.xwpf.usermodel.TextAlignment;
import org.apache.poi.xwpf.usermodel.UnderlinePatterns;
import org.apache.poi.xwpf.usermodel.VerticalAlign;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRelation;
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.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlToken;
import org.apache.xmlbeans.impl.xb.xmlschema.SpaceAttribute;
import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTColor;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFldChar;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHpsMeasure;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHyperlink;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTInd;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPageMar;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSectPr;
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.CTTbl;
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.CTText;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STFldCharType;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHdrFtr;
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.STOnOff;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STUnderline;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalAlignRun;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalJc;

public class POI_图文混排_S3_Test {
	public static void main(String[] args) throws Exception {
		POI_图文混排_S3_Test t = new POI_图文混排_S3_Test();
		CustomXWPFDocument_S_2 document = new CustomXWPFDocument_S_2();
		//设置页边距
		t.setDocumentMargin(document, "1797", "1440", "1797", "1440");
		//测试添加文字与图片
		t.testAddTextParagraph(document);
		//测试设置段落间距
		t.testParagraphSpacingInfo(document);
		//测试设置段落缩进
		t.testParagraphIndInfo(document);
		//测试表格单元格合并
		t.testMegerTableCell(document);
		//测试添加超链接
		t.testAddHyperlink(document);
		//测试添加页眉页脚
		t.testAddHeaderFooter(document);
		t.saveDocument(document,
				"f:/saveFile/temp/sys_" + System.currentTimeMillis() + ".docx");
	}

	public void testAddTextParagraph(CustomXWPFDocument_S_2 document)
			throws Exception {
		XWPFParagraph p = document.createParagraph();
		setTextFontInfo(p, false, false, "基本实验技能(常见实验仪器及基本操作)", "宋体", "000000",
				"40", true, null, false, false, null, 0,null);
		setParagraphSpacingInfo(p, true, "0", "0", "0", "0", true, "240",
				STLineSpacingRule.Enum.forString("auto"));
		setParagraphAlignInfo(p, ParagraphAlignment.CENTER,
				TextAlignment.CENTER);

		p = document.createParagraph();
		setTextFontInfo(p, false, false, "班级:________    姓名:________", "宋体",
				"000000", "21", false, null, false, false, null, 0,null);
		setParagraphSpacingInfo(p, true, "0", "0", "0", "0", true, "240",
				STLineSpacingRule.Enum.forString("auto"));
		setParagraphAlignInfo(p, ParagraphAlignment.CENTER,
				TextAlignment.CENTER);

		p = document.createParagraph();
		setTextFontInfo(p, false, false, "一、单选题(共10道,每道10分)", "宋体", "000000",
				"21", true, null, false, false, null, 0,null);
		setParagraphSpacingInfo(p, true, "0", "0", "100", null, true, "240",
				STLineSpacingRule.Enum.forString("auto"));
		setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);

		p = document.createParagraph();
		setTextFontInfo(p, false, false, "1.下列有关仪器用途的说法错误的是(    )", "宋体",
				"000000", "21", false, null, false, false, null, 0,null);
		setParagraphSpacingInfo(p, true, "0", "0", "0", "0", true, "240",
				STLineSpacingRule.Enum.forString("auto"));
		setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);

		p = document.createParagraph();
		setTextFontInfo(p, false, false, "A.烧杯用于较多量试剂的反应容器", "宋体", "000000",
				"21", false, null, false, false, null, 0,null);
		setParagraphSpacingInfo(p, true, "0", "0", "100", "0", true, "240",
				STLineSpacingRule.Enum.forString("auto"));
		setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);

		p = document.createParagraph();
		setTextFontInfo(p, false, false, "B.烧杯用于较多量试剂的反应容器", "宋体", "000000",
				"21", false, null, false, false, null, 0,null);
		setParagraphSpacingInfo(p, true, "0", "0", "0", "0", true, "240",
				STLineSpacingRule.Enum.forString("auto"));
		setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);

		p = document.createParagraph();
		setTextFontInfo(p, false, false, "C.烧杯用于较多量试剂的反应容器", "宋体", "000000",
				"21", false, null, false, false, null, 0,null);
		setParagraphSpacingInfo(p, true, "0", "0", "0", "0", true, "240",
				STLineSpacingRule.Enum.forString("auto"));
		setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);

		p = document.createParagraph();
		setTextFontInfo(p, false, false, "D.烧杯用于较多量试剂的反应容器", "宋体", "000000",
				"21", false, null, false, false, null, 0,null);
		setParagraphSpacingInfo(p, true, "0", "0", "0", "0", true, "240",
				STLineSpacingRule.Enum.forString("auto"));
		setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);

		p = document.createParagraph();
		setTextFontInfo(p, false, false, "2.下列实验操作中,正确的是(    ) ", "宋体",
				"000000", "21", false, null, false, false, null, 0,null);
		setParagraphSpacingInfo(p, true, "0", "0", "100", "0", true, "240",
				STLineSpacingRule.Enum.forString("auto"));
		setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);

		p = document.createParagraph();
		setTextFontInfo(p, false, false, "A.", "宋体", "000000", "21", false,
				null, false, false, null, 0,null);
		setParagraphSpacingInfo(p, true, "0", "0", "100", "0", true, "240",
				STLineSpacingRule.Enum.forString("auto"));
		setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);
		String blipId = p.getDocument().addPictureData(
				new FileInputStream(new File("f:/saveFile/temp/image1.png")),
				Document.PICTURE_TYPE_PNG);
		document.createPicture(blipId,
				document.getNextPicNameNumber(Document.PICTURE_TYPE_PNG), 90,
				93, p);

		setTextFontInfo(p, true, false, StringUtils.leftPad("B.", 10), "宋体",
				"000000", "21", false, null, false, false, null, 0,null);
		blipId = p.getDocument().addPictureData(
				new FileInputStream(new File("f:/saveFile/temp/image2.png")),
				Document.PICTURE_TYPE_PNG);
		document.createPicture(blipId,
				document.getNextPicNameNumber(Document.PICTURE_TYPE_PNG), 90,
				93, p);

		setTextFontInfo(p, true, true, "C.", "宋体", "000000", "21", false, null,
				false, false, null, 0,null);
		blipId = p.getDocument().addPictureData(
				new FileInputStream(new File("f:/saveFile/temp/image3.png")),
				Document.PICTURE_TYPE_PNG);
		document.createPicture(blipId,
				document.getNextPicNameNumber(Document.PICTURE_TYPE_PNG), 90,
				93, p);

		setTextFontInfo(p, true, false, StringUtils.leftPad("D.", 10), "宋体",
				"000000", "21", false, null, false, false, null, 0,null);
		blipId = p.getDocument().addPictureData(
				new FileInputStream(new File("f:/saveFile/temp/image4.png")),
				Document.PICTURE_TYPE_PNG);
		document.createPicture(blipId,
				document.getNextPicNameNumber(Document.PICTURE_TYPE_PNG), 90,
				93, p);
	}

	public void testParagraphSpacingInfo(XWPFDocument document) {
		addNewPage(document, BreakType.PAGE);
		XWPFParagraph p = document.createParagraph();
		setTextFontInfo(p, false, false, "测试单倍行距", "宋体", "000000", "21", false,
				null, false, false, null, 0,null);
		setParagraphSpacingInfo(p, true, "0", "0", "0", "0", true, "240",
				STLineSpacingRule.Enum.forString("auto"));
		setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);

		p = document.createParagraph();
		setTextFontInfo(p, true, false, "测试最小值10磅", "宋体", "000000", "21",
				false, null, false, false, null, 0,null);
		setParagraphSpacingInfo(p, true, "0", "0", "0", "0", true, "200",
				STLineSpacingRule.Enum.forString("atLeast"));
		setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);

		p = document.createParagraph();
		setTextFontInfo(p, false, false, "测试固定值12磅", "宋体", "000000", "21",
				false, null, false, false, null, 0,null);
		setParagraphSpacingInfo(p, true, "0", "0", "0", "0", true, "240",
				STLineSpacingRule.Enum.forString("exact"));
		setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);

		p = document.createParagraph();
		setTextFontInfo(p, false, false, "测试1.5倍行距", "宋体", "000000", "21",
				false, null, false, false, null, 0,null);
		setParagraphSpacingInfo(p, true, "0", "0", "0", "0", true, "360",
				STLineSpacingRule.Enum.forString("auto"));
		setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);

		p = document.createParagraph();
		setTextFontInfo(p, false, false, "测试2倍行距", "宋体", "000000", "21", false,
				null, false, false, null, 0,null);
		setParagraphSpacingInfo(p, true, "0", "0", "0", "0", true, "480",
				STLineSpacingRule.Enum.forString("auto"));
		setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);

		p = document.createParagraph();
		setTextFontInfo(p, false, false, "测试多倍行距3", "宋体", "000000", "21",
				false, null, false, false, null, 0,null);
		setParagraphSpacingInfo(p, true, "0", "0", "0", "0", true, "720",
				STLineSpacingRule.Enum.forString("auto"));
		setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);

		p = document.createParagraph();
		setTextFontInfo(p, false, false, "测试段前2行段后2行单倍行距", "宋体", "000000",
				"21", false, null, false, false, null, 0,null);
		setParagraphSpacingInfo(p, true, "0", "0", "200", "200", true, "240",
				STLineSpacingRule.Enum.forString("auto"));
		setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);

		p = document.createParagraph();
		setTextFontInfo(p, false, false, "测试段前2磅段后2磅单倍行距", "宋体", "000000",
				"21", false, null, false, false, null, 0,null);
		setParagraphSpacingInfo(p, true, "40", "40", null, null, true, "240",
				STLineSpacingRule.Enum.forString("auto"));
		setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);

		p = document.createParagraph();
		setTextFontInfo(p, false, false, "测试段前2行段后2磅单倍行距", "宋体", "000000",
				"21", false, null, false, false, null, 0,null);
		setParagraphSpacingInfo(p, true, null, "40", "200", null, true, "240",
				STLineSpacingRule.Enum.forString("auto"));
		setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);

		p = document.createParagraph();
		setTextFontInfo(p, false, false, "测试段前2磅段后2行单倍行距", "宋体", "000000",
				"21", false, null, false, false, null, 0,null);
		setParagraphSpacingInfo(p, true, "40", null, null, "200", true, "240",
				STLineSpacingRule.Enum.forString("auto"));
		setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);
	}

	public void testAddHyperlink(XWPFDocument document) {
		addNewPage(document, BreakType.TEXT_WRAPPING);
		XWPFParagraph p = document.createParagraph();
		setTextFontInfo(p, false, true, "", "宋体", "ff0000", "24", false, null,
				false, false, null, 0,null);
		setTextFontInfo(p, true, false, "测试", "宋体", "ff0000", "24", false,
				null, false, false, null, 0,"20");
		appendExternalHyperlink("mailto:1329186624@qq.com?subject=测试poi超链接",
				"联系我", p, "微软雅黑", "28", true, true, false, null, "4","80");
		setTextFontInfo(p, true, false, "测试", "黑体", "00ff00", "26", false,
				null, false, false, null, 0,"20");
		setTextFontInfo(p, true, true, "", "宋体", "ff0000", "24", false, null,
				false, false, null, 0,null);
		setParagraphAlignInfo(p, ParagraphAlignment.CENTER,
				TextAlignment.CENTER);
		setParagraphSpacingInfo(p, true, "0", "0", "100", "100", true, "240",
				STLineSpacingRule.Enum.forString("auto"));
		setParagraphBorder(p, Borders.DOUBLE, Borders.DOUBLE, Borders.DOUBLE,
				Borders.DOUBLE, null);
	}

	public void testParagraphIndInfo(XWPFDocument document) {
		addNewPage(document, BreakType.PAGE);
		XWPFParagraph p = document.createParagraph();
		setTextFontInfo(p, false, false, "测试首行缩进2字符", "宋体", "000000", "21",
				false, null, false, false, null, 0,null);
		setParagraphIndInfo(p, "440", "200", null, null, null, null, null, null);
		setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);

		p = document.createParagraph();
		setTextFontInfo(p, false, false, "测试悬挂缩进2字符", "宋体", "000000", "21",
				false, null, false, false, null, 0,null);
		setParagraphIndInfo(p, null, null, "440", "200", null, null, null, null);
		setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);

		p = document.createParagraph();
		setTextFontInfo(p, false, false, "测试左侧缩进2字符", "宋体", "000000", "21",
				false, null, false, false, null, 0,null);
		setParagraphIndInfo(p, null, null, null, null, null, null, "440", "200");
		setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);

		p = document.createParagraph();
		setTextFontInfo(p, false, false, "测试右侧缩进2字符", "宋体", "000000", "21",
				false, null, false, false, null, 0,null);
		setParagraphIndInfo(p, null, null, null, null, "440", "200", null, null);
		setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);
	}

	public void testMegerTableCell(XWPFDocument doc) {
		addNewPage(doc, BreakType.PAGE);
		List<String> columnList = new ArrayList<String>();
		columnList.add("序号");
		columnList.add("姓名信息|姓甚|名谁");
		columnList.add("名刺信息|籍贯|营生");
		columnList.add("字");
		XWPFTable table = doc.createTable(4, 6);
		setTableWidth(table, "8000");

		XWPFTableRow firstRow = table.getRow(0);
		XWPFTableRow secondRow = table.getRow(1);
		firstRow.setHeight(400);
		secondRow.setHeight(400);
		XWPFTableCell firstCell = null;
		XWPFTableCell secondCell = null;
		int firstCellIndex = 0;
		for (String str : columnList) {
			if (str.indexOf("|") == -1) {
				firstCell = firstRow.getCell(firstCellIndex);
				setCellText(firstCell, str, "CCCCCC", 1600);
				firstCellIndex++;
			} else {
				String[] strArr = str.split("\\|");
				for (int i = 1; i < strArr.length; i++) {
					firstCell = firstRow.getCell(firstCellIndex);
					setCellText(firstCell, strArr[0], "CCCCCC", 1600);
					secondCell = secondRow.getCell(firstCellIndex);
					setCellText(secondCell, strArr[i], "CCCCCC", 1600);
					firstCellIndex++;
				}
			}
		}

		// 合并行(跨列)
		firstCellIndex = 0;
		for (String str : columnList) {
			if (str.indexOf("|") == -1) {
				firstCellIndex++;
			} else {
				String[] strArr = str.split("\\|");
				mergeCellsHorizontal(table, 0, firstCellIndex, firstCellIndex
						+ strArr.length - 2);
				firstCellIndex += strArr.length - 1;
			}
		}

		// 合并列(跨行)
		firstCellIndex = 0;
		for (String str : columnList) {
			if (str.indexOf("|") == -1) {
				mergeCellsVertically(table, firstCellIndex, 0, 1);
				firstCellIndex++;
			} else {
				String[] strArr = str.split("\\|");
				firstCellIndex += strArr.length - 1;
			}
		}

		// 数据
		for (int i = 2; i < 4; i++) {
			firstRow = table.getRow(i);
			firstRow.setHeight(380);
			for (int j = 0; j < 6; j++) {
				firstCell = firstRow.getCell(j);
				setCellText(firstCell, "测试", "FFFFC9", 1600);
			}
		}
	}

	public void testAddHeaderFooter(XWPFDocument doc) throws Exception {
		simpleDateHeader(doc);
		simpleNumberFooter(doc);
	}

	// 页脚:显示页码信息
	public void simpleNumberFooter(XWPFDocument document) throws Exception {
		CTP ctp = CTP.Factory.newInstance();
		XWPFParagraph codePara = new XWPFParagraph(ctp, document);
		XWPFRun r1 = codePara.createRun();
		r1.setText("第");
		r1.setFontSize(11);
		CTRPr rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR()
				.addNewRPr();
		CTFonts fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr
				.addNewRFonts();
		fonts.setAscii("宋体");
		fonts.setEastAsia("宋体");
		fonts.setHAnsi("宋体");

		r1 = codePara.createRun();
		CTFldChar fldChar = r1.getCTR().addNewFldChar();
		fldChar.setFldCharType(STFldCharType.Enum.forString("begin"));

		r1 = codePara.createRun();
		CTText ctText = r1.getCTR().addNewInstrText();
		ctText.setStringValue("PAGE  \\* MERGEFORMAT");
		ctText.setSpace(SpaceAttribute.Space.Enum.forString("preserve"));
		r1.setFontSize(11);
		rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR()
				.addNewRPr();
		fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts();
		fonts.setAscii("宋体");
		fonts.setEastAsia("宋体");
		fonts.setHAnsi("宋体");

		fldChar = r1.getCTR().addNewFldChar();
		fldChar.setFldCharType(STFldCharType.Enum.forString("end"));

		r1 = codePara.createRun();
		r1.setText("页 总共");
		r1.setFontSize(11);
		rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR()
				.addNewRPr();
		fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts();
		fonts.setAscii("宋体");
		fonts.setEastAsia("宋体");
		fonts.setHAnsi("宋体");

		r1 = codePara.createRun();
		fldChar = r1.getCTR().addNewFldChar();
		fldChar.setFldCharType(STFldCharType.Enum.forString("begin"));

		r1 = codePara.createRun();
		ctText = r1.getCTR().addNewInstrText();
		ctText.setStringValue("NUMPAGES  \\* MERGEFORMAT ");
		ctText.setSpace(SpaceAttribute.Space.Enum.forString("preserve"));
		r1.setFontSize(11);
		rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR()
				.addNewRPr();
		fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts();
		fonts.setAscii("宋体");
		fonts.setEastAsia("宋体");
		fonts.setHAnsi("宋体");

		fldChar = r1.getCTR().addNewFldChar();
		fldChar.setFldCharType(STFldCharType.Enum.forString("end"));

		r1 = codePara.createRun();
		r1.setText("页");
		r1.setFontSize(11);
		rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR()
				.addNewRPr();
		fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts();
		fonts.setAscii("宋体");
		fonts.setEastAsia("宋体");
		fonts.setHAnsi("宋体");

		codePara.setAlignment(ParagraphAlignment.CENTER);
		codePara.setVerticalAlignment(TextAlignment.CENTER);
		codePara.setBorderTop(Borders.THICK);
		XWPFParagraph[] newparagraphs = new XWPFParagraph[1];
		newparagraphs[0] = codePara;
		CTSectPr sectPr = document.getDocument().getBody().addNewSectPr();
		XWPFHeaderFooterPolicy headerFooterPolicy = new XWPFHeaderFooterPolicy(
				document, sectPr);
		headerFooterPolicy.createFooter(STHdrFtr.DEFAULT, newparagraphs);
	}

	public void simpleDateHeader(XWPFDocument document) throws Exception {
		CTP ctp = CTP.Factory.newInstance();
		XWPFParagraph codePara = new XWPFParagraph(ctp, document);

		XWPFRun r1 = codePara.createRun();
		CTFldChar fldChar = r1.getCTR().addNewFldChar();
		fldChar.setFldCharType(STFldCharType.Enum.forString("begin"));

		r1 = codePara.createRun();
		CTText ctText = r1.getCTR().addNewInstrText();
		ctText.setStringValue("TIME \\@ \"EEEE\"");
		ctText.setSpace(SpaceAttribute.Space.Enum.forString("preserve"));
		r1.setFontSize(11);
		CTRPr rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR()
				.addNewRPr();
		CTFonts fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr
				.addNewRFonts();
		fonts.setAscii("微软雅黑");
		fonts.setEastAsia("微软雅黑");
		fonts.setHAnsi("微软雅黑");

		fldChar = r1.getCTR().addNewFldChar();
		fldChar.setFldCharType(STFldCharType.Enum.forString("end"));

		r1 = codePara.createRun();
		r1.setText("年");
		r1.setFontSize(11);
		rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR()
				.addNewRPr();
		fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts();
		fonts.setAscii("微软雅黑");
		fonts.setEastAsia("微软雅黑");
		fonts.setHAnsi("微软雅黑");

		r1 = codePara.createRun();
		fldChar = r1.getCTR().addNewFldChar();
		fldChar.setFldCharType(STFldCharType.Enum.forString("begin"));

		r1 = codePara.createRun();
		ctText = r1.getCTR().addNewInstrText();
		ctText.setStringValue("TIME \\@ \"O\"");
		ctText.setSpace(SpaceAttribute.Space.Enum.forString("preserve"));
		r1.setFontSize(11);
		rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR()
				.addNewRPr();
		fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts();
		fonts.setAscii("微软雅黑");
		fonts.setEastAsia("微软雅黑");
		fonts.setHAnsi("微软雅黑");

		fldChar = r1.getCTR().addNewFldChar();
		fldChar.setFldCharType(STFldCharType.Enum.forString("end"));

		r1 = codePara.createRun();
		r1.setText("月");
		r1.setFontSize(11);
		rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR()
				.addNewRPr();
		fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts();
		fonts.setAscii("微软雅黑");
		fonts.setEastAsia("微软雅黑");
		fonts.setHAnsi("微软雅黑");

		r1 = codePara.createRun();
		fldChar = r1.getCTR().addNewFldChar();
		fldChar.setFldCharType(STFldCharType.Enum.forString("begin"));

		r1 = codePara.createRun();
		ctText = r1.getCTR().addNewInstrText();
		ctText.setStringValue("TIME \\@ \"A\"");
		ctText.setSpace(SpaceAttribute.Space.Enum.forString("preserve"));
		r1.setFontSize(11);
		rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR()
				.addNewRPr();
		fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts();
		fonts.setAscii("微软雅黑");
		fonts.setEastAsia("微软雅黑");
		fonts.setHAnsi("微软雅黑");

		fldChar = r1.getCTR().addNewFldChar();
		fldChar.setFldCharType(STFldCharType.Enum.forString("end"));

		r1 = codePara.createRun();
		r1.setText("日");
		r1.setFontSize(11);
		rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR()
				.addNewRPr();
		fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts();
		fonts.setAscii("微软雅黑");
		fonts.setEastAsia("微软雅黑");
		fonts.setHAnsi("微软雅黑");

		codePara.setAlignment(ParagraphAlignment.CENTER);
		codePara.setVerticalAlignment(TextAlignment.CENTER);
		codePara.setBorderBottom(Borders.THICK);
		XWPFParagraph[] newparagraphs = new XWPFParagraph[1];
		newparagraphs[0] = codePara;
		CTSectPr sectPr = document.getDocument().getBody().addNewSectPr();
		XWPFHeaderFooterPolicy headerFooterPolicy = new XWPFHeaderFooterPolicy(
				document, sectPr);
		headerFooterPolicy.createHeader(STHdrFtr.DEFAULT, newparagraphs);
	}

	public void setCellText(XWPFTableCell cell, String text, String bgcolor,
			int width) {
		CTTc cttc = cell.getCTTc();
		CTTcPr ctPr = cttc.addNewTcPr();
		CTShd ctshd = ctPr.addNewShd();
		ctPr.addNewTcW().setW(BigInteger.valueOf(width));
		ctshd.setFill(bgcolor);
		ctPr.addNewVAlign().setVal(STVerticalJc.CENTER);
		cttc.getPList().get(0).addNewPPr().addNewJc().setVal(STJc.CENTER);
		cell.setText(text);
	}

	/**
	 * @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) {
				cell.getCTTc().addNewTcPr().addNewHMerge()
						.setVal(STMerge.RESTART);
			} else {
				cell.getCTTc().addNewTcPr().addNewHMerge()
						.setVal(STMerge.CONTINUE);
			}
		}
	}

	/**
	 * @Description: 跨行合并
	 */
	public void mergeCellsVertically(XWPFTable table, int col, int fromRow,
			int toRow) {
		for (int rowIndex = fromRow; rowIndex <= toRow; rowIndex++) {
			XWPFTableCell cell = table.getRow(rowIndex).getCell(col);
			if (rowIndex == fromRow) {
				cell.getCTTc().addNewTcPr().addNewVMerge()
						.setVal(STMerge.RESTART);
			} else {
				cell.getCTTc().addNewTcPr().addNewVMerge()
						.setVal(STMerge.CONTINUE);
			}
		}
	}

	public void setTableWidth(XWPFTable table, String width) {
		CTTbl ttbl = table.getCTTbl();
		CTTblPr tblPr = ttbl.getTblPr() == null ? ttbl.addNewTblPr() : ttbl
				.getTblPr();
		CTTblWidth tblWidth = tblPr.isSetTblW() ? tblPr.getTblW() : tblPr
				.addNewTblW();
		CTJc cTJc = tblPr.addNewJc();
		cTJc.setVal(STJc.Enum.forString("center"));
		tblWidth.setW(new BigInteger(width));
		tblWidth.setType(STTblWidth.DXA);
	}

	// 设置段落边框
	public void setParagraphBorder(XWPFParagraph p, Borders lborder,
			Borders tBorders, Borders rBorders, Borders bBorders,
			Borders btborders) {
		if (lborder != null) {
			p.setBorderLeft(lborder);
		}
		if (tBorders != null) {
			p.setBorderTop(tBorders);
		}
		if (rBorders != null) {
			p.setBorderRight(rBorders);
		}
		if (bBorders != null) {
			p.setBorderBottom(bBorders);
		}
		if (btborders != null) {
			p.setBorderBetween(btborders);
		}
	}

	// 设置段落对齐
	public void setParagraphAlignInfo(XWPFParagraph p,
			ParagraphAlignment pAlign, TextAlignment valign) {
		p.setAlignment(pAlign);
		p.setVerticalAlignment(valign);
	}

	// 设置段落缩进信息 1厘米≈567
	public void setParagraphIndInfo(XWPFParagraph p, String firstLine,
			String firstLineChar, String hanging, String hangingChar,
			String right, String rigthChar, String left, String leftChar) {
		CTPPr pPPr = null;
		if (p.getCTP() != null) {
			if (p.getCTP().getPPr() != null) {
				pPPr = p.getCTP().getPPr();
			} else {
				pPPr = p.getCTP().addNewPPr();
			}
		}
		CTInd pInd = pPPr.getInd() != null ? pPPr.getInd() : pPPr.addNewInd();
		if (firstLine != null) {
			pInd.setFirstLine(new BigInteger(firstLine));
		}
		if (firstLineChar != null) {
			pInd.setFirstLineChars(new BigInteger(firstLineChar));
		}
		if (hanging != null) {
			pInd.setHanging(new BigInteger(hanging));
		}
		if (hangingChar != null) {
			pInd.setHangingChars(new BigInteger(hangingChar));
		}
		if (left != null) {
			pInd.setLeft(new BigInteger(left));
		}
		if (leftChar != null) {
			pInd.setLeftChars(new BigInteger(leftChar));
		}
		if (right != null) {
			pInd.setRight(new BigInteger(right));
		}
		if (rigthChar != null) {
			pInd.setRightChars(new BigInteger(rigthChar));
		}
	}

	// 设置段落间距信息
	// 一行=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 = null;
		if (p.getCTP() != null) {
			if (p.getCTP().getPPr() != null) {
				pPPr = p.getCTP().getPPr();
			} else {
				pPPr = p.getCTP().addNewPPr();
			}
		}
		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);
			}
		}
	}

	/**
	 * @param verticalAlign
	 *            SUPERSCRIPT上标 SUBSCRIPT下标
	 * @param position
	 *            字符位置 1磅=2
	 */
	// 设置字体信息 设置字符间距信息(CTSignedTwipsMeasure)
	public void setTextFontInfo(XWPFParagraph p, boolean isInsert,
			boolean isNewLine, String content, String fontFamily,
			String colorVal, String fontSize, boolean isBlod,
			UnderlinePatterns underPatterns, boolean isItalic,
			boolean isStrike, VerticalAlign verticalAlign, int position,String spacingValue) {
		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();
		}
		pRun.setText(content);
		// 设置字体样式
		pRun.setBold(isBlod);
		pRun.setItalic(isItalic);
		pRun.setStrike(isStrike);
		if (underPatterns != null) {
			pRun.setUnderline(underPatterns);
		}
		pRun.setColor(colorVal);
		if (verticalAlign != null) {
			pRun.setSubscript(verticalAlign);
		}
		pRun.setTextPosition(position);

		CTRPr pRpr = null;
		if (pRun.getCTR() != null) {
			pRpr = pRun.getCTR().getRPr();
			if (pRpr == null) {
				pRpr = pRun.getCTR().addNewRPr();
			}
		} else {
			// pRpr = p.getCTP().addNewR().addNewRPr();
		}
		// 设置字体
		CTFonts fonts = pRpr.isSetRFonts() ? pRpr.getRFonts() : pRpr
				.addNewRFonts();
		fonts.setAscii(fontFamily);
		fonts.setEastAsia(fontFamily);
		fonts.setHAnsi(fontFamily);

		// 设置字体大小
		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(spacingValue!=null){
			//设置字符间距信息
			CTSignedTwipsMeasure ctSTwipsMeasure=pRpr.isSetSpacing()?pRpr.getSpacing(): pRpr.addNewSpacing();
			ctSTwipsMeasure.setVal(new BigInteger(spacingValue));
		}
	}

	/**
	 * 
	 * @Description: 添加超链接
	 * @param position
	 *            1磅=2
	 */
	// 为段落添加超链接
	public void appendExternalHyperlink(String url, String text,
			XWPFParagraph paragraph, String fontFamily, String fontSize,
			boolean isBlod, boolean isItalic, boolean isStrike,
			String verticalAlign, String position,String spacingValue) {
		// Add the link as External relationship
		String id = paragraph
				.getDocument()
				.getPackagePart()
				.addExternalRelationship(url,
						XWPFRelation.HYPERLINK.getRelation()).getId();
		// Append the link and bind it to the relationship
		CTHyperlink cLink = paragraph.getCTP().addNewHyperlink();
		cLink.setId(id);

		// Create the linked text
		CTText ctText = CTText.Factory.newInstance();
		ctText.setStringValue(text);
		CTR ctr = CTR.Factory.newInstance();
		CTRPr rpr = ctr.addNewRPr();

		// 设置超链接样式
		CTColor color = CTColor.Factory.newInstance();
		color.setVal("0000FF");
		rpr.setColor(color);
		rpr.addNewU().setVal(STUnderline.SINGLE);
		if (isBlod) {
			rpr.addNewB().setVal(STOnOff.Enum.forString("true"));
		}
		if (isItalic) {
			rpr.addNewI().setVal(STOnOff.Enum.forString("true"));
		}
		if (isStrike) {
			rpr.addNewStrike().setVal(STOnOff.Enum.forString("true"));
		}
		if (verticalAlign != null) {
			rpr.addNewVertAlign().setVal(
					STVerticalAlignRun.Enum.forString(verticalAlign));
		}
		rpr.addNewPosition().setVal(new BigInteger(position));

		// 设置字体
		CTFonts fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr
				.addNewRFonts();
		fonts.setAscii(fontFamily);
		fonts.setEastAsia(fontFamily);
		fonts.setHAnsi(fontFamily);

		// 设置字体大小
		CTHpsMeasure sz = rpr.isSetSz() ? rpr.getSz() : rpr.addNewSz();
		sz.setVal(new BigInteger(fontSize));

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

		if(spacingValue!=null){
			//设置字符间距信息
			CTSignedTwipsMeasure ctSTwipsMeasure=rpr.isSetSpacing()?rpr.getSpacing(): rpr.addNewSpacing();
			ctSTwipsMeasure.setVal(new BigInteger(spacingValue));
		}
		
		ctr.setTArray(new CTText[] { ctText });
		cLink.setRArray(new CTR[] { ctr });
	}

	public void addNewPage(XWPFDocument document, BreakType breakType) {
		XWPFParagraph xp = document.createParagraph();
		xp.createRun().addBreak(breakType);
	}

	//设置页边距 1厘米约等于567
	public void setDocumentMargin(XWPFDocument document,String left,String top,String right,String bottom){
		CTSectPr sectPr =document.getDocument().getBody().isSetSectPr()?document.getDocument().getBody().getSectPr():document.getDocument().getBody().addNewSectPr();
		CTPageMar ctpagemar=sectPr.addNewPgMar();
		ctpagemar.setLeft(new BigInteger(left));
		ctpagemar.setTop(new BigInteger(top));
		ctpagemar.setRight(new BigInteger(right));
		ctpagemar.setBottom(new BigInteger(bottom));
	}
	
	public void saveDocument(XWPFDocument document, String savePath)
			throws Exception {
		FileOutputStream fos = new FileOutputStream(savePath);
		document.write(fos);
		fos.close();
	}

}

class CustomXWPFDocument_S_2 extends XWPFDocument {
	public CustomXWPFDocument_S_2() {
		super();
	}

	public CustomXWPFDocument_S_2(InputStream in) throws IOException {
		super(in);
	}

	public CustomXWPFDocument_S_2(OPCPackage pkg) throws IOException {
		super(pkg);
	}

	public void createPicture(String blipId, int id, int width, int height,
			XWPFParagraph paragraph) {
		final int EMU = 9525;
		width *= EMU;
		height *= EMU;
		// String blipId =
		// getAllPictures().get(id).getPackageRelationship().getId();
		if (paragraph == null) {
			paragraph = createParagraph();
		}
		CTInline inline = paragraph.createRun().getCTR().addNewDrawing()
				.addNewInline();
		String picXml = ""
				+ "<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">"
				+ "   <a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">"
				+ "      <pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">"
				+ "         <pic:nvPicPr>" + "            <pic:cNvPr id=\""
				+ id
				+ "\" name=\"img_"
				+ id
				+ "\"/>"
				+ "            <pic:cNvPicPr/>"
				+ "         </pic:nvPicPr>"
				+ "         <pic:blipFill>"
				+ "            <a:blip r:embed=\""
				+ blipId
				+ "\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\"/>"
				+ "            <a:stretch>"
				+ "               <a:fillRect/>"
				+ "            </a:stretch>"
				+ "         </pic:blipFill>"
				+ "         <pic:spPr>"
				+ "            <a:xfrm>"
				+ "               <a:off x=\"0\" y=\"0\"/>"
				+ "               <a:ext cx=\""
				+ width
				+ "\" cy=\""
				+ height
				+ "\"/>"
				+ "            </a:xfrm>"
				+ "            <a:prstGeom prst=\"rect\">"
				+ "               <a:avLst/>"
				+ "            </a:prstGeom>"
				+ "         </pic:spPr>"
				+ "      </pic:pic>"
				+ "   </a:graphicData>" + "</a:graphic>";
		// CTGraphicalObjectData graphicData =
		// inline.addNewGraphic().addNewGraphicData();
		XmlToken xmlToken = null;
		try {
			xmlToken = XmlToken.Factory.parse(picXml);
		} catch (XmlException xe) {
			xe.printStackTrace();
		}
		inline.set(xmlToken);
		// graphicData.set(xmlToken);
		inline.setDistT(0);
		inline.setDistB(0);
		inline.setDistL(0);
		inline.setDistR(0);
		CTPositiveSize2D extent = inline.addNewExtent();
		extent.setCx(width);
		extent.setCy(height);
		CTNonVisualDrawingProps docPr = inline.addNewDocPr();
		docPr.setId(id);
		docPr.setName("img_ " + id);
		docPr.setDescr("Picture");
	}
}

    结果如下:

    

  

   

 

    需要的jar包如下:

   

 

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

    全文完

 

  • 大小: 39.5 KB
  • 大小: 55.2 KB
  • 大小: 59.3 KB
  • 大小: 34.2 KB
1
0
分享到:
评论
1 楼 向往前途 2016-09-21  
非常感谢你的例子,对我很有帮助

相关推荐

    Android读取并显示word文件的代码例子

    在Android平台上,开发人员...通过以上步骤,你可以在Android应用中实现读取和显示Word文档的功能,覆盖了从doc到docx的格式,并能正确处理图文混排的内容。实际开发中,可以根据需求进行调整,优化性能和用户体验。

    数据集-苹果果目标检测-labelme-4430

    包含4430张苹果目标检测图片和标签数据。 数据集介绍: https://blog.csdn.net/qq_21386397/article/details/147465394

    基于YOLOv5和Django实现了对道路交通标识的实时识别系统+项目说明(毕设作品).zip

    基于YOLOv5和Django实现了对道路交通标识的实时识别系统+项目说明(毕设作品).zip 项目简介 该项目基于YOLOv5和Django实现了对道路交通标识的实时识别并利用Django后端框架部署该项目,用户可以在网页上实时观看检测画面。 项目组成 detect文件夹 Django APP 主要是识别的代码、模型、以及相关的资源 主要功能点 基于YOLOv5的道路交通标识实时识别 利用Django后端框架部署项目,提供网页界面供用户实时观看检测结果 技术栈 计算机视觉: YOLOv5 Web框架: Django

    NetworkWordCount.py

    NetworkWordCount.py

    groovy-2.4.0-beta-3.jar中文文档.zip

    # 压缩文件中包含: 中文文档 jar包下载地址 Maven依赖 Gradle依赖 源代码下载地址 # 本文件关键字: jar中文文档.zip,java,jar包,Maven,第三方jar包,组件,开源组件,第三方组件,Gradle,中文API文档,手册,开发手册,使用手册,参考手册 # 使用方法: 解压最外层zip,再解压其中的zip包,双击 【index.html】 文件,即可用浏览器打开、进行查看。 # 特殊说明: ·本文档为人性化翻译,精心制作,请放心使用。 ·只翻译了该翻译的内容,如:注释、说明、描述、用法讲解 等; ·不该翻译的内容保持原样,如:类名、方法名、包名、类型、关键字、代码 等。 # 温馨提示: (1)为了防止解压后路径太长导致浏览器无法打开,推荐在解压时选择“解压到当前文件夹”(放心,自带文件夹,文件不会散落一地); (2)有时,一套Java组件会有多个jar,所以在下载前,请仔细阅读本篇描述,以确保这就是你需要的文件;

    groovy-2.3.0-beta-2.jar中文文档.zip

    # 压缩文件中包含: 中文文档 jar包下载地址 Maven依赖 Gradle依赖 源代码下载地址 # 本文件关键字: jar中文文档.zip,java,jar包,Maven,第三方jar包,组件,开源组件,第三方组件,Gradle,中文API文档,手册,开发手册,使用手册,参考手册 # 使用方法: 解压最外层zip,再解压其中的zip包,双击 【index.html】 文件,即可用浏览器打开、进行查看。 # 特殊说明: ·本文档为人性化翻译,精心制作,请放心使用。 ·只翻译了该翻译的内容,如:注释、说明、描述、用法讲解 等; ·不该翻译的内容保持原样,如:类名、方法名、包名、类型、关键字、代码 等。 # 温馨提示: (1)为了防止解压后路径太长导致浏览器无法打开,推荐在解压时选择“解压到当前文件夹”(放心,自带文件夹,文件不会散落一地); (2)有时,一套Java组件会有多个jar,所以在下载前,请仔细阅读本篇描述,以确保这就是你需要的文件;

    Python新手入门学习方法指南.pdf

    内容概要:本文档为Python新手提供了全面的学习指南,涵盖从零基础到独立编程所需的知识和技能。首先介绍了Python的核心优势和应用场景,强调其简洁的语法、丰富的生态以及跨平台支持。接着详细规划了四个学习阶段:基础语法(1-2周),包括变量、数据类型、流程控制等;数据结构与文件操作(2-3周),涉及列表、字典、文件读写;面向对象与模块化编程(3-4周),讲解类与对象、继承、模块化开发;实战项目(持续练习),通过具体项目巩固所学知识。此外,还提供了开发环境搭建指导、高效学习技巧、常见问题避坑指南及学习资源推荐,帮助初学者顺利入门。 适合人群:零基础或有少量编程经验,希望系统学习Python的新手程序员。 使用场景及目标:①为初学者提供系统的Python学习路径,从基础到实战逐步提升编程能力;②帮助学习者掌握Python核心语法和常用工具,能够独立完成小型项目;③通过实战项目积累经验,培养解决实际问题的能力。 其他说明:建议学习者按照规划的学习路径循序渐进,每天坚持练习,并积极参与社区交流。遇到问题时,善用官方文档和在线资源,保持学习动力,逐步成长为自信的开发者。

    flink-table-api-java-1.14.1.jar中文-英文对照文档.zip

    # 压缩文件中包含: 中文-英文对照文档 jar包下载地址 Maven依赖 Gradle依赖 源代码下载地址 # 本文件关键字: jar中文-英文对照文档.zip,java,jar包,Maven,第三方jar包,组件,开源组件,第三方组件,Gradle,中文API文档,手册,开发手册,使用手册,参考手册 # 使用方法: 解压最外层zip,再解压其中的zip包,双击 【index.html】 文件,即可用浏览器打开、进行查看。 # 特殊说明: ·本文档为人性化翻译,精心制作,请放心使用。 ·只翻译了该翻译的内容,如:注释、说明、描述、用法讲解 等; ·不该翻译的内容保持原样,如:类名、方法名、包名、类型、关键字、代码 等。 # 温馨提示: (1)为了防止解压后路径太长导致浏览器无法打开,推荐在解压时选择“解压到当前文件夹”(放心,自带文件夹,文件不会散落一地); (2)有时,一套Java组件会有多个jar,所以在下载前,请仔细阅读本篇描述,以确保这就是你需要的文件;

    Python 实现的爬取汽车之家数据并进行可视化展示项目源代码+全部数据

    Python 实现的爬取汽车之家数据并进行可视化展示项目源代码+全部数据,个人经导师指导并认可通过的高分设计项目,评审分99分,代码完整确保可以运行,小白也可以亲自搞定,主要针对计算机相关专业的正在做大作业的学生和需要项目实战练习的学习者,可作为毕业设计、课程设计、期末大作业,代码资料完整,下载可用。 Python 实现的爬取汽车之家数据并进行可视化展示项目源代码+全部数据Python 实现的爬取汽车之家数据并进行可视化展示项目源代码+全部数据Python 实现的爬取汽车之家数据并进行可视化展示项目源代码+全部数据Python 实现的爬取汽车之家数据并进行可视化展示项目源代码+全部数据Python 实现的爬取汽车之家数据并进行可视化展示项目源代码+全部数据Python 实现的爬取汽车之家数据并进行可视化展示项目源代码+全部数据Python 实现的爬取汽车之家数据并进行可视化展示项目源代码+全部数据Python 实现的爬取汽车之家数据并进行可视化展示项目源代码+全部数据Python 实现的爬取汽车之家数据并进行可视化展示项目源代码+全部数据Python 实现的爬取汽车之家数据并进行可视化展示项目源代码+全部数据Python 实现的爬取汽车之家数据并进行可视化展示项目源代码+全部数据Python 实现的爬取汽车之家数据并进行可视化展示项目源代码+全部数据Python 实现的爬取汽车之家数据并进行可视化展示项目源代码+全部数据Python 实现的爬取汽车之家数据并进行可视化展示项目源代码+全部数据Python 实现的爬取汽车之家数据并进行可视化展示项目源代码+全部数据Python 实现的爬取汽车之家数据并进行可视化展示项目源代码+全部数据Python 实现的爬取汽车之家数据并进行可视化展示项目源代码+全部数据Python 实现的爬取汽车之家数据并进行可视化展示项目源代码+全部数

    基于Gensim和Jieba的中文文本聚类LDA模型构建与优化

    内容概要:本文详细介绍了如何利用Gensim库和Jieba分词工具进行中文文本聚类,尤其是LDA(Latent Dirichlet Allocation)主题模型的应用。首先,通过自定义词典和停用词表来提高分词准确性,确保专业术语不会被错误分割。然后,将分词后的文本转换为词袋模型,作为LDA模型的输入。文中还探讨了多个重要参数的选择与调优方法,如主题数量(num_topics)、迭代次数(passes)、以及随机种子(random_state)。此外,作者分享了一些实用的经验,例如如何通过coherence score评估模型质量,以及如何使用pyLDAvis进行可视化展示。 适合人群:有一定编程基础的数据分析师、自然语言处理工程师、文本挖掘研究人员。 使用场景及目标:适用于需要从大量非结构化文本中抽取潜在主题的场景,如舆情分析、市场调研、文献分类等。主要目标是帮助用户掌握LDA模型的基本原理及其在中文环境下的具体实现方法。 其他说明:本文不仅提供了完整的代码示例,还强调了实践中需要注意的问题和技巧,使读者能够更好地理解和应用这一强大的文本分析工具。

    毕业设计基于Python+Yolov5路面桥梁裂缝检测识别项目源代码+模型

    毕业设计基于Python+Yolov5路面桥梁裂缝检测识别项目源代码+模型,个人经导师指导并认可通过的高分设计项目,评审分99分,代码完整确保可以运行,小白也可以亲自搞定,主要针对计算机相关专业的正在做大作业的学生和需要项目实战练习的学习者,可作为毕业设计、课程设计、期末大作业,代码资料完整,下载可用。 毕业设计基于Python+Yolov5路面桥梁裂缝检测识别项目源代码+模型毕业设计基于Python+Yolov5路面桥梁裂缝检测识别项目源代码+模型毕业设计基于Python+Yolov5路面桥梁裂缝检测识别项目源代码+模型毕业设计基于Python+Yolov5路面桥梁裂缝检测识别项目源代码+模型毕业设计基于Python+Yolov5路面桥梁裂缝检测识别项目源代码+模型毕业设计基于Python+Yolov5路面桥梁裂缝检测识别项目源代码+模型毕业设计基于Python+Yolov5路面桥梁裂缝检测识别项目源代码+模型毕业设计基于Python+Yolov5路面桥梁裂缝检测识别项目源代码+模型毕业设计基于Python+Yolov5路面桥梁裂缝检测识别项目源代码+模型毕业设计基于Python+Yolov5路面桥梁裂缝检测识别项目源代码+模型毕业设计基于Python+Yolov5路面桥梁裂缝检测识别项目源代码+模型毕业设计基于Python+Yolov5路面桥梁裂缝检测识别项目源代码+模型毕业设计基于Python+Yolov5路面桥梁裂缝检测识别项目源代码+模型毕业设计基于Python+Yolov5路面桥梁裂缝检测识别项目源代码+模型毕业设计基于Python+Yolov5路面桥梁裂缝检测识别项目源代码+模型毕业设计基于Python+Yolov5路面桥梁裂缝检测识别项目源代码+模型毕业设计基于Python+Yolov5路面桥梁裂缝检测识别项目源代码+模型毕业设计基于Python+Yolo

    go2rtc流媒体平台,支持rtsp大华摄像头海康H264 H265 WEBRTC

    go2rtc流媒体平台,支持rtsp大华摄像头海康H264 H265 WEBRTC,有支持http接口

    基于Python实现Boss直聘岗位数据采集及分析可视化项目源代码+数据+文档说明

    基于Python实现Boss直聘岗位数据采集及分析可视化项目源代码+数据+文档说明,个人经导师指导并认可通过的高分设计项目,评审分99分,代码完整确保可以运行,小白也可以亲自搞定,主要针对计算机相关专业的正在做大作业的学生和需要项目实战练习的学习者,可作为毕业设计、课程设计、期末大作业,代码资料完整,下载可用。 基于Python实现Boss直聘岗位数据采集及分析可视化项目源代码+数据+文档说明基于Python实现Boss直聘岗位数据采集及分析可视化项目源代码+数据+文档说明基于Python实现Boss直聘岗位数据采集及分析可视化项目源代码+数据+文档说明基于Python实现Boss直聘岗位数据采集及分析可视化项目源代码+数据+文档说明基于Python实现Boss直聘岗位数据采集及分析可视化项目源代码+数据+文档说明基于Python实现Boss直聘岗位数据采集及分析可视化项目源代码+数据+文档说明基于Python实现Boss直聘岗位数据采集及分析可视化项目源代码+数据+文档说明基于Python实现Boss直聘岗位数据采集及分析可视化项目源代码+数据+文档说明基于Python实现Boss直聘岗位数据采集及分析可视化项目源代码+数据+文档说明基于Python实现Boss直聘岗位数据采集及分析可视化项目源代码+数据+文档说明基于Python实现Boss直聘岗位数据采集及分析可视化项目源代码+数据+文档说明基于Python实现Boss直聘岗位数据采集及分析可视化项目源代码+数据+文档说明基于Python实现Boss直聘岗位数据采集及分析可视化项目源代码+数据+文档说明基于Python实现Boss直聘岗位数据采集及分析可视化项目源代码+数据+文档说明基于Python实现Boss直聘岗位数据采集及分析可视化项目源代码+数据+文档说明基于Python实现Boss直聘岗位数据采集及分析可视

    STM32CubeIDE 1.18.1自动补全插件

    STM32CubeIDE自动补全代码功能插件,覆盖STM32CubeIDE\plugins对应文件!

    基于springboot+vue前后端分离,科研工作量管理系统(源码+Mysql数据库+视频+教程),高分项目,开箱即用(毕业设计)(课堂设计)

    基于springboot+vue前后端分离,科研工作量管理系统(源码+Mysql数据库+视频+教程),高分项目,开箱即用(毕业设计)(课堂设计) 现代经济快节奏发展以及不断完善升级的信息化技术,让传统数据信息的管理升级为软件存储,归纳,集中处理数据信息的管理方式。本科研工作量管理系统就是在这样的大环境下诞生,其可以帮助管理者在短时间内处理完毕庞大的数据信息,使用这种软件工具可以帮助管理人员提高事务处理效率,达到事半功倍的效果。此科研工作量管理系统利用当下成熟完善的SSM框架,使用跨平台的可开发大型商业网站的Java语言,以及最受欢迎的RDBMS应用软件之一的Mysql数据库进行程序开发。实现了用户在线选择试题并完成答题,在线查看考核分数。管理员管理字典管理、工作量管理、科研获奖管理、科研论文管理、秘书管理、科研项目管理、教师管理、管理员管理等功能。科研工作量管理系统的开发根据操作人员需要设计的界面简洁美观,在功能模块布局上跟同类型网站保持一致,程序在实现基本要求功能时,也为数据信息面临的安全问题提供了一些实用的解决方案。可以说该程序在帮助管理者高效率地处理工作事务的同时,也实现了数据信息的整体化,规范化与自动化。

    集装箱号码自动识别软件-DEMO演示程序

    如因版本过旧,测试过程中有任何问题可联系作者获取最新版本,可提供私有化部署API。 1、集装箱箱号OCR识别技术实现流程 (1)图像预处理 目标检测:使用启智畅想模型定位集装箱区域,缩小处理范围。 角度矫正:通过透视变换(如霍夫变换检测边缘)校正倾斜或扭曲的箱号。 图像增强:灰度化、二值化、去噪、对比度调整等,提升文本可读性。 (2)字符区域定位 字符检测:基于深度学习的文本检测模型定位箱号区域。 区域筛选:根据集装箱号长度(11字符)和排列规则筛选候选区域。 (3)字符识别 端到端方法:使用网络神经以及深度学习模型直接识别字符序列,避免传统分割步骤。 字符分割:投影法、连通域分析或U-Net分割粘连字符。 字符识别:训练CNN分类模型,支持数字以及大小写字母(0-9,A-Z,排除部分易混字符如I和1/O和0)。 (4)校验码验证 校验码比对:将识别的前10位转换为ISO6346标准数值,按权重计算并与OCR结果比对。 校验机制:若校验失败,触发重新识别或人工复核。 2、集装箱箱号OCR识别技术的多场景应用 复杂环境:应对光照不均、污渍、锈蚀、反光等干扰。 特殊字体:集装箱号的特殊字体(如OCR-B字体)需针对性训练。 3.数据集与训练 数据收集:自建数据集。 数据增强:模拟真实场景的噪声、模糊、旋转、仿射变换等。 算法迭代:基于预训练模型(如ImageNet)微调,提升训练效率,通过在线学习更新集装箱箱号OCR识别模型,适应新字体或环境变化。 4.评估指标 字符级准确率:99.9%以上 校验码通过率:99.9%以上 推理速度(FPS):毫秒级识别 通过结合深度学习的集装箱箱号OCR识别技术与规则校验,集装箱号OCR识别系统可达到高精度与高可靠性,广泛应用于物流追踪、海关通关和智能港口管理等场景

    基于Matlab的自动泊车系统中垂直车位路径规划仿真

    内容概要:本文详细介绍了使用Matlab进行自动泊车系统的垂直车位路径规划仿真。首先解释了Hybrid A*算法的基本原理及其在垂直车位泊车中的应用,重点讨论了路径规划的关键步骤,如外摆车头、转向角调整、碰撞检测以及路径生成。文中提供了具体的Matlab代码示例,展示了从车辆参数定义、路径点生成到最终路径验证的全过程。此外,还探讨了几何分析阶段的车辆运动轨迹建模,包括最小转弯半径的计算和转向圆心的确定。同时,为了确保路径的安全性和可行性,引入了边界圆检测法进行碰撞检测,并对路径进行了优化以满足实际驾驶的需求。 适合人群:对自动驾驶技术感兴趣的科研人员、工程师以及希望深入了解自动泊车系统的学生。 使用场景及目标:适用于研究和开发自动泊车系统的路径规划算法,帮助开发者理解和实现自动泊车过程中遇到的技术挑战,如路径规划、碰撞检测和路径优化。 其他说明:本文不仅提供了理论分析,还有详细的代码实现,便于读者快速上手并进行实验。同时,文中提到的一些技巧和注意事项对于提高仿真的准确性和实用性非常有帮助。

    基于轨迹预测的辅助驾驶安全预警系统:Carsim2019+Simulink周向防碰撞技术解析

    内容概要:本文详细介绍了基于轨迹预测的周向防碰撞系统,重点探讨了CTRV(恒定转向率和速度)轨迹预测模型的应用。该系统利用Carsim2019和Simulink进行建模和仿真,结合车载激光雷达获取的环境信息,实现了对未来几秒钟内车辆轨迹的精准预测。文中不仅提供了Python和MATLAB的伪代码示例,还讨论了如何通过动态安全距离策略、运动趋势权重等方法提高系统的鲁棒性和准确性。此外,文章还涉及了传感器数据处理、状态预测、决策模块的设计等方面的内容。 适合人群:从事自动驾驶技术研发的工程师和技术爱好者,尤其是对车辆轨迹预测、防碰撞算法感兴趣的读者。 使用场景及目标:适用于研究和开发辅助驾驶系统的机构和个人。主要目标是在各种危险碰撞场景下,提前预测并采取措施,确保行车安全。同时,也为未来自动驾驶技术的发展提供了理论依据和技术支持。 其他说明:文章强调了系统在实际应用中的挑战和优化方法,如噪声模型的改进、传感器数据的处理等。通过实例展示了系统在不同工况下的表现,如连续S弯、鬼探头等情况下的应对能力。

    工业激光设备上位机开发:基于欧姆龙NJ PLC与多品牌激光器通信控制的C#实现

    内容概要:本文详细介绍了工业激光设备上位机开发的技术细节,主要围绕欧姆龙NJ PLC与多种品牌激光器(如IPG、通快、锐科等)之间的通信控制展开。文中提供了多个具体的代码示例,涵盖了从基本的TCP/IP连接、协议解析、异常处理到高级的OPC UA集成等多个方面。作者还分享了许多实际开发过程中遇到的问题及其解决方案,如字节序处理、超时重试机制、状态同步以及界面设计的最佳实践等。 适合人群:具备一定工业自动化背景的研发工程师和技术人员,尤其是从事激光设备上位机开发的相关人员。 使用场景及目标:帮助开发者更好地理解和掌握工业激光设备上位机开发的关键技术和最佳实践,提高系统的稳定性和可靠性,减少开发和调试时间。 其他说明:文章不仅提供了详细的代码示例,还分享了作者的实际经验教训,对于初学者来说是非常宝贵的参考资料。此外,文章强调了在工业环境中进行开发时需要注意的安全性和稳定性问题。

    生物信息学算法:理论与实践

    本书《生物信息学中的算法:理论与实现》由Paul A. Gagniuc撰写,是生物信息学领域的重要参考书。书中详细介绍了生物信息学的基本概念,包括生命的起源、分类和机制、染色质结构以及分子机制等。作者深入探讨了基因组在生命之树中的角色,包括基因组大小、器官体基因组、质粒和病毒基因组等。本书还重点讲解了序列对齐技术,包括全局对齐、局部对齐以及自我序列对齐等,并探讨了序列比对的初始化、得分计算、优化步骤和追溯方法。此外,书中还涉及了频率和百分比分析、目标数字污渍等高级主题。本书不仅适合生物信息学专业的学生和研究人员,也适合对生物信息学算法感兴趣的其他专业人士。

Global site tag (gtag.js) - Google Analytics