public XWPFCommentsDecorator(XWPFParagraph paragraph, XWPFParagraphDecorator nextDecorator) { super(paragraph, nextDecorator); XWPFComment comment; commentText = new StringBuilder(64); for (CTMarkupRange anchor : paragraph.getCTP().getCommentRangeStartArray()) { if ((comment = paragraph.getDocument().getCommentByID(anchor.getId().toString())) != null) { commentText.append("\tComment by ") .append(comment.getAuthor()) .append(": ") .append(comment.getText()); } } }
public XWPFHyperlinkRun createHyperLinkRun(String link) { PackageRelationship relationship = paragraph.getDocument().getPackagePart() .addExternalRelationship(link, XWPFRelation.HYPERLINK.getRelation()); CTHyperlink hyperlink = paragraph.getCTP().addNewHyperlink(); hyperlink.setId(relationship.getId()); CTR ctr = hyperlink.addNewR(); XWPFHyperlinkRun xwpfRun = new XWPFHyperlinkRun(hyperlink, ctr, (IRunBody) paragraph); getRuns().add(xwpfRun); getIRuns().add(xwpfRun); return xwpfRun; }
PackageRelationship relationship = paragraph.getDocument().getPackagePart() .addExternalRelationship(link, XWPFRelation.HYPERLINK.getRelation()); CTHyperlink hyperlink = paragraph.getCTP().insertNewHyperlink(pos);
/** * @return The {@link XWPFDocument} instance, this run belongs to, or * <code>null</code> if parent structure (paragraph > document) is not properly set. */ public XWPFDocument getDocument() { if (paragraph != null) { return paragraph.getDocument(); } return null; }
public XWPFCommentsDecorator(XWPFParagraph paragraph, XWPFParagraphDecorator nextDecorator) { super(paragraph, nextDecorator); XWPFComment comment; commentText = new StringBuilder(64); for (CTMarkupRange anchor : paragraph.getCTP().getCommentRangeStartArray()) { if ((comment = paragraph.getDocument().getCommentByID(anchor.getId().toString())) != null) { commentText.append("\tComment by ") .append(comment.getAuthor()) .append(": ") .append(comment.getText()); } } }
public XWPFCommentsDecorator(XWPFParagraph paragraph, XWPFParagraphDecorator nextDecorator) { super(paragraph, nextDecorator); XWPFComment comment; commentText = new StringBuffer(); for(CTMarkupRange anchor : paragraph.getCTP().getCommentRangeStartList()) { if((comment = paragraph.getDocument().getCommentByID(anchor.getId().toString())) != null) commentText.append("\tComment by " + comment.getAuthor()+": "+comment.getText()); } }
if (paragraph.getDocument() != null) { XWPFPictureData data = picture.getPictureData(); if (data != null) {
/** * 添加图片 * * @Author JueYue * @date 2013-11-20 * @param obj * @param currentRun * @throws Exception */ private void addAnImage(WordImageEntity obj, XWPFRun currentRun) throws Exception { Object[] isAndType = PoiPublicUtil.getIsAndType(obj); String picId; try { picId = currentRun.getParagraph().getDocument().addPictureData((byte[]) isAndType[0], (Integer) isAndType[1]); ((MyXWPFDocument) currentRun.getParagraph().getDocument()).createPicture(currentRun, picId, currentRun.getParagraph().getDocument().getNextPicNameNumber((Integer) isAndType[1]), obj.getWidth(), obj.getHeight()); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } }
/** * 添加图片 * * @Author JueYue * @date 2013-11-20 * @param obj * @param currentRun * @throws Exception */ private void addAnImage(WordImageEntity obj, XWPFRun currentRun) throws Exception { Object[] isAndType = PoiPublicUtil.getIsAndType(obj); String picId; try { picId = currentRun.getParagraph().getDocument() .addPictureData((byte[]) isAndType[0], (Integer) isAndType[1]); ((MyXWPFDocument) currentRun.getParagraph().getDocument()).createPicture(currentRun, picId, currentRun.getParagraph().getDocument() .getNextPicNameNumber((Integer) isAndType[1]), obj.getWidth(), obj.getHeight()); } catch (Exception e) { LOGGER.error(e.getMessage(),e); } }
/** * @param prgrph The paragraph of text to work on * @param outputHyperlinkUrls Should we output the links too, or just the link text? */ public XWPFHyperlinkDecorator(XWPFParagraph prgrph, XWPFParagraphDecorator nextDecorator, boolean outputHyperlinkUrls) { super(prgrph, nextDecorator); hyperlinkText = new StringBuffer(); // loop over hyperlink anchors for(CTHyperlink link : paragraph.getCTP().getHyperlinkList()){ for (CTR r : link.getRList()) { // Loop over text runs for (CTText text : r.getTList()){ hyperlinkText.append(text.getStringValue()); } } if(outputHyperlinkUrls && paragraph.getDocument().getHyperlinkByID(link.getId()) != null) { hyperlinkText.append(" <"+paragraph.getDocument().getHyperlinkByID(link.getId()).getURL()+">"); } } }
public void example() throws Exception{ XWPFDocument document = new XWPFDocument(); //Append a link to appendExternalHyperlink("https://poi.apache.org", " Link to POI", document.createParagraph()); document.write(new FileOutputStream("resultat.docx")); } /** * Appends an external hyperlink to the paragraph. * * @param url The URL to the external target * @param text The linked text * @param paragraph the paragraph the link will be appended to. */ public static void appendExternalHyperlink(String url, String text, XWPFParagraph paragraph){ //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(); ctr.setTArray(new CTText[]{ctText}); //Insert the linked text into the link cLink.setRArray(new CTR[]{ctr}); }
paragraphX.setAlignment(ParagraphAlignment.CENTER); String blipId = paragraphX.getDocument().addPictureData( new FileInputStream(new File("D://c2//WLB.jpg")), Document.PICTURE_TYPE_JPEG);
private void createParagraphs(XWPFParagraph p, String[] paragraphs) { if (p != null) { XWPFDocument doc = p.getDocument(); XmlCursor cursor = p.getCTP().newCursor(); for (int i = 0; i < paragraphs.length; i++) { XWPFParagraph newP = doc.createParagraph(); newP.getCTP().setPPr(p.getCTP().getPPr()); XWPFRun newR = newP.createRun(); newR.getCTR().setRPr(p.getRuns().get(0).getCTR().getRPr()); newR.setText(paragraphs[i]); XmlCursor c2 = newP.getCTP().newCursor(); c2.moveXml(cursor); c2.dispose(); } cursor.removeXml(); // Removes replacement text paragraph cursor.dispose(); } }
if (paragraph.getDocument() != null) { XWPFPictureData data = picture.getPictureData(); if (data != null) {
if (paragraph.getDocument() != null) { XWPFPictureData data = picture.getPictureData(); if (data != null) {