use of org.apache.poi.xwpf.usermodel.XWPFParagraph in project poi by apache.
the class TestDocumentProtection method testIntegration.
@Test
public void testIntegration() throws IOException {
XWPFDocument doc1 = new XWPFDocument();
XWPFParagraph p1 = doc1.createParagraph();
XWPFRun r1 = p1.createRun();
r1.setText("Lorem ipsum dolor sit amet.");
doc1.enforceCommentsProtection();
File tempFile = TempFile.createTempFile("documentProtectionFile", ".docx");
FileOutputStream out = new FileOutputStream(tempFile);
doc1.write(out);
out.close();
FileInputStream inputStream = new FileInputStream(tempFile);
XWPFDocument doc2 = new XWPFDocument(inputStream);
inputStream.close();
assertTrue(doc2.isEnforcedCommentsProtection());
doc2.close();
doc1.close();
}
use of org.apache.poi.xwpf.usermodel.XWPFParagraph in project poi by apache.
the class TestXWPFDecorators method testHyperlink.
public void testHyperlink() {
XWPFParagraph ps;
XWPFParagraph ph;
assertEquals(7, simple.getParagraphs().size());
assertEquals(5, hyperlink.getParagraphs().size());
// Simple text
ps = simple.getParagraphs().get(0);
assertEquals("I am a test document", ps.getParagraphText());
assertEquals(1, ps.getRuns().size());
ph = hyperlink.getParagraphs().get(4);
assertEquals("We have a hyperlink here, and another.", ph.getParagraphText());
assertEquals(3, ph.getRuns().size());
// The proper way to do hyperlinks(!)
assertFalse(ps.getRuns().get(0) instanceof XWPFHyperlinkRun);
assertFalse(ph.getRuns().get(0) instanceof XWPFHyperlinkRun);
assertTrue(ph.getRuns().get(1) instanceof XWPFHyperlinkRun);
assertFalse(ph.getRuns().get(2) instanceof XWPFHyperlinkRun);
XWPFHyperlinkRun link = (XWPFHyperlinkRun) ph.getRuns().get(1);
assertEquals("http://poi.apache.org/", link.getHyperlink(hyperlink).getURL());
}
use of org.apache.poi.xwpf.usermodel.XWPFParagraph in project poi by apache.
the class TestXWPFDecorators method testComments.
public void testComments() {
int numComments = 0;
for (XWPFParagraph p : comments.getParagraphs()) {
XWPFCommentsDecorator d = new XWPFCommentsDecorator(p, null);
if (d.getCommentText().length() > 0) {
numComments++;
assertEquals("\tComment by", d.getCommentText().substring(0, 11));
}
}
assertEquals(3, numComments);
}
use of org.apache.poi.xwpf.usermodel.XWPFParagraph in project tika by apache.
the class XWPFWordExtractorDecorator method extractIBodyText.
private void extractIBodyText(IBody bodyElement, XWPFListManager listManager, XHTMLContentHandler xhtml) throws SAXException, XmlException, IOException {
for (IBodyElement element : bodyElement.getBodyElements()) {
if (element instanceof XWPFParagraph) {
XWPFParagraph paragraph = (XWPFParagraph) element;
extractParagraph(paragraph, listManager, xhtml);
}
if (element instanceof XWPFTable) {
XWPFTable table = (XWPFTable) element;
extractTable(table, listManager, xhtml);
}
if (element instanceof XWPFSDT) {
extractSDT((XWPFSDT) element, xhtml);
}
}
}
use of org.apache.poi.xwpf.usermodel.XWPFParagraph in project Gargoyle by callakrsos.
the class MSWord method addToTable.
/**
* 테이블을 추가한다.
*
* List의 로우는 각 행을 의미. TreeSet은 테이블 컬럼Index 데이터를 의미.
*
* @param list
*/
public XWPFTable addToTable(List<List<String>> list, ITableCustomProperty property) /*
* ,
* ThFunction
* <
* ,
* U
* ,
* V
* ,
* R
* >
*/
{
if (list == null || list.isEmpty()) {
return null;
}
// -- OR --
// open an existing empty document with styles already defined
// XWPFDocument doc = new XWPFDocument(new
// FileInputStream("base_document.docx"));
int rowSize = list.size();
int colSize = list.get(0).size();
XWPFTable table = doc.createTable(rowSize, colSize);
// Set the table style. If the style is not defined, the table style
// will become "Normal".
{
CTTblPr tblPr = table.getCTTbl().getTblPr();
CTString styleStr = tblPr.addNewTblStyle();
styleStr.setVal("StyledTable");
}
/* Table Width조절을 위한 작업 */
{
CTTbl ctTbl = table.getCTTbl();
CTTblPr tblPr = ctTbl.getTblPr();
CTTblWidth tblW = tblPr.getTblW();
// 화면에 WIDTH를 딱 맞춤.
tblW.setW(BigInteger.valueOf(5000));
tblW.setType(STTblWidth.PCT);
}
// Get a list of the rows in the table
// List<XWPFTableRow> rows = table.getRows();
int rowCt = 0;
int colCt = 0;
for (List<String> set : list) {
XWPFTableRow row = table.getRow(rowCt);
CTTrPr trPr = row.getCtRow().addNewTrPr();
// set row height; units = twentieth of a point, 360 = 0.25"
CTHeight ht = trPr.addNewTrHeight();
ht.setVal(BigInteger.valueOf(/* 360 */
240));
// get the cells in this row
List<XWPFTableCell> cells = row.getTableCells();
Iterator<String> it = set.iterator();
while (it.hasNext()) {
if (cells.size() == colCt) {
row.createCell();
}
// get a table cell properties element (tcPr)
XWPFTableCell cell = cells.get(colCt);
CTTcPr tcpr = cell.getCTTc().addNewTcPr();
// set vertical alignment to "center"
CTVerticalJc va = tcpr.addNewVAlign();
va.setVal(STVerticalJc.CENTER);
// create cell color element
CTShd ctshd = tcpr.addNewShd();
ctshd.setColor("auto");
ctshd.setVal(STShd.CLEAR);
if (rowCt == 0) {
// header row
ctshd.setFill("FFFE99");
} else if (rowCt % 2 == 0) {
// even row
// FFFFFF : 흰색
ctshd.setFill("D3DFEE");
} else {
// odd row
ctshd.setFill("EDF2F8");
}
// get 1st paragraph in cell's paragraph list
XWPFParagraph para = cell.getParagraphs().get(0);
// create a run to contain the content
// 2015.3.17 fix
// XWPFRun rh = para.createRun();
KrXWPFRun rh = new KrXWPFRun(para.createRun());
rh.setFontFamily(fontName);
// style cell as desired
if (colCt == colSize - 1) {
// last column is 10pt Courier
rh.setFontSize(DEFAULT_FONT_SIZE);
}
String content = it.next();
if (rowCt == 0) {
// header row
rh.setText(content);
rh.setFontSize(H5);
rh.setBold(true);
para.setAlignment(ParagraphAlignment.CENTER);
} else if (rowCt % 2 == 0) {
// even row
addTableText(rh, content);
rh.setSubscript(VerticalAlign.BASELINE);
para.setAlignment(ParagraphAlignment.LEFT);
} else {
addTableText(rh, content);
// odd row
rh.setSubscript(VerticalAlign.BASELINE);
para.setAlignment(ParagraphAlignment.LEFT);
}
colCt++;
}
// for cell
colCt = 0;
rowCt++;
}
if (property != null) {
property.doCustom(table);
}
return table;
}
Aggregations