`
53873039oycg
  • 浏览: 853800 次
  • 性别: 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的格式,并能正确处理图文混排的内容。实际开发中,可以根据需求进行调整,优化性能和用户体验。

    COMSOL中金属纳米盘光学截面计算及应用:散射、消光与吸收截面的详细解析

    内容概要:本文详细介绍了如何使用COMSOL Multiphysics进行金属纳米盘的散射、消光和吸收截面的计算。首先,通过几何建模创建一个直径80nm、厚度20nm的金纳米盘,并设置了精确的材料参数(如Drude模型),确保模拟的准确性。接着,选择了电磁波频域作为物理场,配置了合适的边界条件(如散射边界条件和端口激发),并进行了精细的网格划分,特别是在纳米盘边缘加密网格以提高计算精度。然后,利用后处理脚本提取了散射、消光和吸收截面的数据,提供了具体的计算公式和注意事项。最后,强调了验证结果的重要性和一些常见的错误避免方法,如检查能量守恒和调整网格密度。 适合人群:从事纳米光子学研究的科研人员和技术爱好者,尤其是对COMSOL Multiphysics有一定基础的用户。 使用场景及目标:适用于需要精确计算金属纳米盘光学特性的研究人员,帮助他们理解和掌握COMSOL中相关参数的设置和优化方法,从而更好地进行科学研究和发表高质量论文。 其他说明:文中还提供了一个详细的录屏教程,涵盖了从建模到后处理的完整流程,方便用户跟随操作。同时,提醒用户注意单位转换和数据归一化等问题,以确保计算结果的正确性。

    DL/T 645-2007 java 读写编码及解码

    DL/T 645-2007 的规定帧编写读写函数,对收到原始数据进行解码

    NFC碰一碰,碰碰卡,支持贴牌源码部署,为商家做赋能,1:一键发布抖音、小红书笔记,小红书视频、快手、视频号 2:一键大众点评、美团、抖音、高德、百度打卡收藏

    餐饮行业: 店外引流:在餐厅门口放置爆店码,顾客进店前碰一碰,就能了解今日特色菜品、优惠套餐等信息,吸引顾客进店消费。 店内互动:在餐桌等位置设置爆店码,顾客用餐过程中碰一碰,可参与抽奖活动、领取餐后优惠券,或跳转到电子菜单进行加菜,增加顾客的用餐乐趣和二次消费几率。 零售店铺: 服装门店:在橱窗展示新品时,贴上爆店码,顾客碰一碰可查看模特穿搭视频、获取商品详情和尺码信息,以及该商品的会员专属折扣。在试衣镜旁放置爆店码,顾客碰一碰能查看搭配建议、关注公众号或加入会员,提升引流转粉效率。 便利店:在收银台设置爆店码,顾客付款时碰一碰,可领取满减优惠券、了解会员积分规则,或获取当季新品推荐,促进顾客当场购买或成为会员,提升销售额和顾客忠诚度。 线下活动: 展会:在展会入口、展位等位置放置爆店码,参与者碰一碰就能快速获取展会详情、参展商名单、活动议程、展位地图等信息,方便活动的推广和组织,同时也能收集参与者的信息,为后续营销做准备。 促销活动:在商场中庭、店铺门口等举办促销活动时,使用爆店码。顾客碰一碰可了解活动规则、参与方式,还能直接领取电子优惠券或参与线上互动游戏,增加活动的参与度和传播度。 服务行业: 美业:在美甲美睫店的服务台、镜子旁等地方设置爆店码,顾客碰一碰可自动引导添加美业小助理微信,方便预约下次服务,也可获取美容护肤知识、会员专属优惠等信息。 健身行业:在健身房的前台、更衣室门口、器械旁放置爆店码。顾客碰一碰能了解课程安排、教练介绍,还可参与打卡活动,分享训练成果到社交平台,领取健身优惠券或小礼品,吸引更多潜在顾客。 旅游行业: 景区:在景区入口、景点打卡处等设置爆店码,游客碰一碰可获取景区地图、景点介绍、语音讲解,还能领取景区纪念品优惠券或参与线上互动活动,提升游客的旅游体验和景区的知名度。 酒店:在酒店大堂、客房门口、餐厅等位置放置爆店码。客人碰一碰可了解酒店

    MIL-STD-454N.PDF

    MIL-STD-454N.PDF

    基于优化特征平面和标准视频编解码器的3D高斯点云压缩方法

    内容概要:本文提出了一种基于标准视频编解码器和优化特征平面的高效压缩方法,用于处理3D高斯点阵(3D Gaussian Splatting)。该方法通过引入统一架构将点云数据和特征平面结合,利用2D特征平面实现连续空间表示,并通过频率域熵建模和通道位分配优化压缩性能。实验结果表明,该方法在显著减少存储需求的同时保持了高质量的渲染效果,特别是在“自行车”场景中实现了146倍的压缩率而图像质量几乎无损。此外,该模型与现有3DGS渲染管道无缝集成,维持了相似的渲染速度。 适合人群:对3D场景压缩和渲染技术感兴趣的计算机视觉研究人员及工程师,特别是关注实时应用和移动设备性能优化的专业人士。 使用场景及目标:①需要在资源受限环境中(如移动设备或头戴显示器)进行高效3D场景表示的应用开发者;②寻求在不牺牲渲染质量的前提下大幅降低存储和传输成本的技术团队;③希望利用标准视频编解码器实现快速硬件解码的研究者。 其他说明:该研究不仅适用于特定的数据集,还为未来3D表示技术的发展提供了关键见解,促进了更高效的3D压缩技术发展。实验验证了该方法的有效性,展示了显著的存储节省和视觉保真度。

    超声波焊接技术在汽车门板塑焊机中的应用:从源码到硬件加工的全面解析

    内容概要:本文详细介绍了超声波焊接技术在汽车门板塑焊机中的应用,涵盖了从源码程序到硬件加工的各个方面。首先强调了超声波焊接在汽车制造中的重要性,然后展示了控制板和显示板的源码程序,包括初始化代码、PID控制算法、频率跟踪算法等。此外,还讨论了超声波换能器、手柄外壳、铝件和焊头的加工技术及其具体要求。文中提供了多个代码示例,如STM32的PWM配置、DMA传输、PID算法实现等,展示了如何通过软件和硬件的紧密结合实现高效的超声波焊接。 适合人群:从事汽车制造业、电子工程、嵌入式开发等相关领域的技术人员,尤其是对超声波焊接技术和嵌入式系统感兴趣的工程师。 使用场景及目标:适用于希望深入了解超声波焊接技术原理和技术实现的读者,帮助他们掌握从源码编写到硬件加工的全流程知识,提高焊接系统的稳定性和可靠性。 其他说明:文章不仅提供了详细的代码示例,还分享了许多实践经验,如频率跟踪算法、温度补偿、硬件互锁机制等,有助于读者更好地理解和应用这些技术。

    可配置阶数和位宽的级联型IIR滤波器

    可配置阶数和位宽的级联型IIR滤波器(具体代码和工程私聊qq947336191)

    程序设计语言基础JAVAWEB_Java的常用工具类[2025网盘版.备考复习].doc

    程序设计语言基础JAVAWEB_Java的常用工具类[2025网盘版.备考复习]

    Halcon与C#联合开发的工业视觉框架:图像处理、异常处理及内存管理的最佳实践

    内容概要:本文详细介绍了Halcon与C#联合开发的一个稳定版工业视觉框架,涵盖环境配置、图像处理流水线设计、异常处理、内存管理和算法模块化等方面的内容。首先,文章强调了环境配置的重要性,确保Halcon的runtime版本与开发环境一致,避免常见的dll版本不匹配问题。接着,描述了图像处理流水线的设计,采用了Task+async/await的方式提高效率,并通过状态机实现流程引擎,使配置更加灵活。此外,文章深入探讨了内存管理,提供了多个实例,如使用using语句确保HRegion对象正确释放,以及通过HalconMemoryKiller类防止内存泄漏。异常处理方面,文章展示了如何将Halcon的错误码转化为易读的信息,并实现了全局异常捕获和日志记录。最后,文章提到了框架的实际应用场景,如PCB板检测,并分享了许多实战经验和技巧,如相机断线自动重连、图像显示控件的手势操作等。 适合人群:具备一定编程基础并希望深入了解Halcon与C#联合开发的工程师和技术爱好者。 使用场景及目标:适用于工业视觉项目的开发,旨在帮助开发者构建高效稳定的图像处理系统,提高系统的鲁棒性和维护性。 其他说明:文中提供的代码片段和实战经验对于解决常见问题非常有价值,尤其是内存管理和异常处理方面的最佳实践。

    三菱PLC与威纶触摸屏整合的恒压供水系统实战解析

    内容概要:本文详细介绍了基于三菱FX1N-30MR PLC和威纶TK6070触摸屏的恒压供水系统的实战应用。主要内容涵盖系统的关键功能如定时锁定、模式切换、PID控制、故障联锁以及小泵控制等。文中不仅提供了具体的梯形图代码片段,还分享了许多实际调试经验和注意事项。例如,定时锁定功能通过M384和M385实现,确保系统稳定运行;模式切换由M400-M403控制,可在触摸屏上进行选择;PID控制可以选择变频器或3A模块,后者提供更平稳的压力曲线;故障联锁机制能够在变频器故障时自动切换到工频泵,保障供水安全;小泵控制则用于应对压力波动,保持管网压力稳定。 适用人群:从事工业自动化领域的工程师和技术人员,尤其是对PLC编程和触摸屏应用有一定基础的人群。 使用场景及目标:适用于需要理解和实施恒压供水系统的工程项目。目标是帮助读者掌握三菱PLC和威纶触摸屏的具体应用技巧,提高系统的可靠性和效率。 其他说明:文中提到的一些特殊操作和调试技巧,如通过D129输入4016解锁系统,以及在触摸屏上设置隐藏菜单等,有助于解决实际工程中的常见问题。此外,文章强调了硬件配置和通信设置的重要性,提醒读者在实际操作中避免常见的错误。

    基于51单片机的全自动洗衣机系统:手动自动双操作模式及Proteus仿真设计

    内容概要:本文详细介绍了基于51单片机的全自动洗衣机系统的设计与实现。系统支持手动和自动两种操作模式,能够灵活调整水位、洗涤时间和漂洗次数等参数。文中提供了详细的Proteus 8仿真图、C语言源码及Hex文件的使用说明。硬件方面,采用STC89C52作为主控芯片,搭配LCD1602显示屏、按键阵列、直流电机驱动模块、水位传感器和门磁开关等组件。软件部分涵盖了按键处理、电机控制、水位检测等功能模块的具体实现方法。此外,还讨论了一些常见的调试技巧和注意事项。 适合人群:具有一定单片机基础知识的学习者、电子爱好者、嵌入式系统开发者。 使用场景及目标:适用于希望深入了解51单片机及其外围设备的应用开发,特别是对于嵌入式控制系统感兴趣的读者。通过本项目的实践,读者可以掌握单片机的基本编程技能,学会如何构建和调试小型自动化系统。 其他说明:文中提供的代码和仿真图可以帮助初学者更好地理解和掌握相关知识点。同时,针对可能出现的问题给出了实用的解决方案,如按键消抖、电机驱动保护等。

    Java在线教育学习平台LW PPT.pptx

    Java在线教育学习平台LW PPT

    基于ssm+mysql的小说阅读网站书城(含LW+PPT+源码+系统演示视频+安装说明).zip

    系统名称:基于SSM实现的小说网站 技术栈:SSM框架、MYSQL数据库、JS语言、B/S架构 系统功能:前台界面功能包括站内信息查看(通过作者、小说名、小说类型查找小说)、用户注册、小说列表查看(按章节查看并阅读,用户登录后收藏,付费或免费查看)、在线支付、排行榜(热门小说、点击率);后台功能包括用户管理(管理员和注册用户)、站内信息管理、小说类别管理、小说信息管理、章节信息管理、支付信息管理。 摘要:简单而言信息化就是为了人们的生活便利所带来的新时代的东西,有了淘宝、京东,我们可以进行网购漂亮的衣服;有了快手、抖音我们可以真实的感受主播给我们带来最真实的货物;有了美团我们可以在家就吃到全城的美食。这就是信息化带给我们的福利,别看一个小小的APP或者WEB应用,它能够解决的是社会上的某一类问题。企业资源计划ERP这类软件可能有很多人都听到过,熟悉它的人都知道一个小小的TOB应用软件可以指挥数以万计的企业员工有条不紊的进行着企业各项的生产任务。可想而知,信息化软件的力量足可以撼动整个企业乃至整个行业的情况。此次我们的设计所做的应用也是根据现实生活当中的需求来进行针对性的功能解决的,所有的业务也好,功能啥的都是根据实际的需求设计而来。各种各样应运而生的信息化软件都是为了解决生活当中的问题的,我们也不例外,就是为了能够解决这样或者那样的问题才进行的设计。随着近几年的疫情不断发展,居家办公的情况更多出现在人们的生活当中,那么一些单调无味的工作和生活就影响着人们的心情。小说的需求场景也就越来越多了,人们的娱乐方式也由此变得更加丰富些。电子小说的出现可以大概率的帮助人们随时随地进行小说的阅读,同时还能够搜寻出自己喜欢小说。

    异步电机模型预测电流控制(MPCC)仿真研究:双闭环矢量控制框架下的电流环改进

    内容概要:本文详细介绍了基于模型预测控制(MPC)的异步电机电流环改进仿真项目。首先,文章阐述了双闭环矢量控制框架的整体架构,即外层采用PI控制的速度环和内层采用MPC控制的电流环。接着,深入探讨了电机模型的核心代码,包括磁链观测器的简化处理以及预测控制器的代价函数设计。文中还分享了多个实际调试过程中遇到的技术挑战及其解决方案,如离散化方法的选择、开关频率惩罚项的设定、预测步长的影响等。此外,作者通过实验数据展示了MPC相较于传统PI控制在动态响应、电流跟踪精度等方面的显著优势。 适合人群:电气工程专业学生、从事电机控制系统研究的研发人员和技术爱好者。 使用场景及目标:适用于希望深入了解并掌握异步电机模型预测电流控制技术的研究人员。主要目标是通过理论与实践相结合的方式,提高对MPC的理解和应用能力,特别是在电流环控制方面的优化。 其他说明:文章不仅提供了详细的数学公式和代码实现,还附带了一些实用的小技巧和注意事项,有助于读者更好地理解和复现相关研究成果。同时,文中引用了多篇权威文献作为参考,进一步增强了内容的专业性和可信度。

    LVGL-8.3.0资源源码

    lvgl-8.3.0 在github下载了好久才下载下来,希望方便大家使用。

    兰州石化职业技术大学岗位实习手册(学生)印9200册.doc

    兰州石化职业技术大学岗位实习手册(学生)印9200册.doc

    On-device Model 在 KMP 的集成与用例.pptx

    On-device Model 在 KMP 的集成与用例.pptx

    验证码数据数据集-zip

    数据集介绍 整理平台上的几个数据集,调整格式,将验证码内容作为图片名称 整理相关验证码数据集57800张,统一使用验证码内容作为对应图片的文件名,使用的时候可以根据根据需求自行决定切分比例。

    中职语文《一碗清汤荞麦面》教学设计.docx

    中职语文《一碗清汤荞麦面》教学设计.docx

Global site tag (gtag.js) - Google Analytics