use of org.apache.poi.xwpf.usermodel.XWPFRun in project selenium_java by sergueik.
the class TableReader method main.
public static void main(String[] args) {
try {
XWPFDocument xdoc = openDocument("test.docx");
Iterator<IBodyElement> bodyElementIterator = xdoc.getBodyElementsIterator();
while (bodyElementIterator.hasNext()) {
IBodyElement element = bodyElementIterator.next();
if ("TABLE".equalsIgnoreCase(element.getElementType().name())) {
List<XWPFTable> tableList = element.getBody().getTables();
for (XWPFTable table : tableList) {
System.out.println("Total Number of Rows of Table:" + table.getNumberOfRows());
for (int rowNum = 0; rowNum < table.getRows().size(); rowNum++) {
XWPFTableRow row = table.getRow(rowNum);
for (int colNum = 0; colNum < row.getTableCells().size(); colNum++) {
XWPFTableCell cell = row.getCell(colNum);
if (cell.getText().contains(findText)) {
List<XWPFParagraph> paragraphs = cell.getParagraphs();
for (XWPFParagraph paragraph : paragraphs) {
List<XWPFRun> runElemens = paragraph.getRuns();
for (XWPFRun runElement : runElemens) {
String text = runElement.getText(0);
if (text.contains(findText)) {
System.out.println(findText + " ~> " + replaceText);
runElement.setText(String.format("%-30s", text.replaceFirst(findText, replaceText)), 0);
}
}
}
}
System.out.println("-->" + cell.getText());
}
}
}
}
}
saveDocument(xdoc, "new.docx");
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of org.apache.poi.xwpf.usermodel.XWPFRun in project selenium_java by sergueik.
the class StyleReader method main.
public static void main(String[] args) {
try {
FileInputStream fis = new FileInputStream("test.docx");
XWPFDocument xdoc = new XWPFDocument(OPCPackage.open(fis));
List<XWPFParagraph> paragraphList = xdoc.getParagraphs();
for (XWPFParagraph paragraph : paragraphList) {
for (XWPFRun rn : paragraph.getRuns()) {
System.out.println(rn.isBold());
System.out.println(rn.isHighlighted());
System.out.println(rn.isCapitalized());
System.out.println(rn.getFontSize());
}
System.out.println("********************************************************************");
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of org.apache.poi.xwpf.usermodel.XWPFRun in project sw360portal by sw360.
the class DocxGenerator method fillReleaseDetailList.
private void fillReleaseDetailList(XWPFDocument document, Collection<LicenseInfoParsingResult> projectLicenseInfoResults, boolean includeObligations) throws TException {
addFormattedText(document.createParagraph().createRun(), "Detailed Releases Information", FONT_SIZE + 2, true);
setText(document.createParagraph().createRun(), "Please note the following license conditions and copyright " + "notices applicable to Open Source Software and/or other components (or parts thereof):");
addNewLines(document, 0);
for (LicenseInfoParsingResult parsingResult : projectLicenseInfoResults) {
addReleaseTitle(document, parsingResult);
if (parsingResult.getStatus() == LicenseInfoRequestStatus.SUCCESS) {
addCopyrights(document, parsingResult);
addLicenses(document, parsingResult, includeObligations);
} else {
XWPFRun errorRun = document.createParagraph().createRun();
String errorText = nullToEmptyString(parsingResult.getMessage());
String filename = getFilename(parsingResult);
addFormattedText(errorRun, String.format("Error reading license information: %s", errorText), FONT_SIZE, false, ALERT_COLOR);
addFormattedText(errorRun, String.format("Source file: %s", filename), FONT_SIZE, false, ALERT_COLOR);
}
addNewLines(document, 1);
}
addPageBreak(document);
}
use of org.apache.poi.xwpf.usermodel.XWPFRun in project sw360portal by sw360.
the class DocxGenerator method addLicenseObligations.
private void addLicenseObligations(XWPFDocument document, String spdxLicense) throws TException {
List<License> sw360Licenses = getLicenses();
XWPFRun todoTitleRun = document.createParagraph().createRun();
addNewLines(todoTitleRun, 0);
Set<String> todos = getTodosFromLicenses(spdxLicense, sw360Licenses);
addFormattedText(todoTitleRun, "Obligations for license " + spdxLicense + ":", FONT_SIZE, true);
for (String todo : todos) {
XWPFParagraph copyPara = document.createParagraph();
copyPara.setSpacingAfter(0);
XWPFRun todoRun = copyPara.createRun();
setText(todoRun, todo);
addNewLines(todoRun, 1);
}
}
use of org.apache.poi.xwpf.usermodel.XWPFRun in project sw360portal by sw360.
the class DocxGenerator method fillLicenseList.
private void fillLicenseList(XWPFDocument document, Collection<LicenseInfoParsingResult> projectLicenseInfoResults) {
List<LicenseNameWithText> licenseNameWithTexts = OutputGenerator.getSortedLicenseNameWithTexts(projectLicenseInfoResults);
XWPFRun licenseHeaderRun = document.createParagraph().createRun();
addFormattedText(licenseHeaderRun, "License texts", FONT_SIZE + 2, true);
addNewLines(document, 0);
for (LicenseNameWithText licenseNameWithText : licenseNameWithTexts) {
XWPFParagraph licenseParagraph = document.createParagraph();
licenseParagraph.setStyle(STYLE_HEADING);
String licenseName = licenseNameWithText.isSetLicenseName() ? licenseNameWithText.getLicenseName() : UNKNOWN_LICENSE_NAME;
addBookmark(licenseParagraph, licenseName, licenseName);
addNewLines(document, 0);
setText(document.createParagraph().createRun(), nullToEmptyString(licenseNameWithText.getLicenseText()));
addNewLines(document, 1);
}
}
Aggregations