Java Examples for org.apache.poi.xwpf.usermodel.XWPFTable
The following java examples will help you to understand the usage of org.apache.poi.xwpf.usermodel.XWPFTable. These source code samples are taken from different open source projects.
Example 1
| Project: poi-tl-master File: TemplateResolver.java View source code |
private static List<ElementTemplate> parseTable(List<XWPFTable> tables) { List<ElementTemplate> result = new ArrayList<ElementTemplate>(); if (null != tables && !tables.isEmpty()) { for (XWPFTable tb : tables) { List<ElementTemplate> parseTable = parseTable(tb); if (null != parseTable) result.addAll(parseTable); } } return result; }
Example 2
| Project: Aspose_Words_for_Apache_POI-master File: ApacheFormattedTable.java View source code |
public static void main(String[] args) throws Exception {
String dataPath = "src/featurescomparison/workingwithtables/formattable/data/";
// Create a new document from scratch
XWPFDocument doc = new XWPFDocument();
// -- OR --
// open an existing empty document with styles already defined
//XWPFDocument doc = new XWPFDocument(new FileInputStream("base_document.docx"));
// Create a new table with 6 rows and 3 columns
int nRows = 6;
int nCols = 3;
XWPFTable table = doc.createTable(nRows, nCols);
// 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");
// Get a list of the rows in the table
List<XWPFTableRow> rows = table.getRows();
int rowCt = 0;
int colCt = 0;
for (XWPFTableRow row : rows) {
// get table row properties (trPr)
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));
// get the cells in this row
List<XWPFTableCell> cells = row.getTableCells();
// add content to each cell
for (XWPFTableCell cell : cells) {
// get a table cell properties element (tcPr)
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("A7BFDE");
} else if (rowCt % 2 == 0) {
// even row
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
XWPFRun rh = para.createRun();
// style cell as desired
if (colCt == nCols - 1) {
// last column is 10pt Courier
rh.setFontSize(10);
rh.setFontFamily("Courier");
}
if (rowCt == 0) {
// header row
rh.setText("header row, col " + colCt);
rh.setBold(true);
para.setAlignment(ParagraphAlignment.CENTER);
} else if (rowCt % 2 == 0) {
// even row
rh.setText("row " + rowCt + ", col " + colCt);
para.setAlignment(ParagraphAlignment.LEFT);
} else {
// odd row
rh.setText("row " + rowCt + ", col " + colCt);
para.setAlignment(ParagraphAlignment.LEFT);
}
colCt++;
}
// for cell
colCt = 0;
rowCt++;
}
// for row
// write the file
FileOutputStream out = new FileOutputStream(dataPath + "Apache_styledTable_Out.docx");
doc.write(out);
out.close();
System.out.println("Process Completed Successfully");
}Example 3
| Project: sw360portal-master File: DocxGenerator.java View source code |
private void fillDocument(XWPFDocument document, Collection<LicenseInfoParsingResult> projectLicenseInfoResults, String projectName) throws IOException {
cleanUpTemplate(document);
setProjectNameInDocument(document, projectName);
String[] tableHeaders = { "Name of OSS Component", "Version of OSS Component", "Name and Version of License (see Appendix for License Text)", "Acknowledgements", "More Information" };
XWPFTable table = createTableAndAddReleasesTableHeaders(document, tableHeaders);
fillReleasesTable(table, projectLicenseInfoResults);
addLicenseTextsHeader(document, "Appendix - License Texts");
addLicenseTexts(document, projectLicenseInfoResults);
}Example 4
| Project: OOXML-master File: XWPFWordExtractor.java View source code |
public String getText() {
StringBuffer text = new StringBuffer();
XWPFHeaderFooterPolicy hfPolicy = document.getHeaderFooterPolicy();
// Start out with all headers
extractHeaders(text, hfPolicy);
// First up, all our paragraph based text
Iterator<XWPFParagraph> i = document.getParagraphsIterator();
while (i.hasNext()) {
XWPFParagraph paragraph = i.next();
try {
CTSectPr ctSectPr = null;
if (paragraph.getCTP().getPPr() != null) {
ctSectPr = paragraph.getCTP().getPPr().getSectPr();
}
XWPFHeaderFooterPolicy headerFooterPolicy = null;
if (ctSectPr != null) {
headerFooterPolicy = new XWPFHeaderFooterPolicy(document, ctSectPr);
extractHeaders(text, headerFooterPolicy);
}
XWPFParagraphDecorator decorator = new XWPFCommentsDecorator(new XWPFHyperlinkDecorator(paragraph, null, fetchHyperlinks));
text.append(decorator.getText()).append('\n');
if (ctSectPr != null) {
extractFooters(text, headerFooterPolicy);
}
} catch (IOException e) {
throw new POIXMLException(e);
} catch (XmlException e) {
throw new POIXMLException(e);
}
}
// Then our table based text
Iterator<XWPFTable> j = document.getTablesIterator();
while (j.hasNext()) {
text.append(j.next().getText()).append('\n');
}
// Finish up with all the footers
extractFooters(text, hfPolicy);
return text.toString();
}Example 5
| Project: poi-master File: XWPFTableCell.java View source code |
public XWPFTable insertNewTbl(final XmlCursor cursor) { if (isCursorInTableCell(cursor)) { String uri = CTTbl.type.getName().getNamespaceURI(); String localPart = "tbl"; cursor.beginElement(localPart, uri); cursor.toParent(); CTTbl t = (CTTbl) cursor.getObject(); XWPFTable newT = new XWPFTable(t, this); cursor.removeXmlContents(); XmlObject o = null; while (!(o instanceof CTTbl) && (cursor.toPrevSibling())) { o = cursor.getObject(); } if (!(o instanceof CTTbl)) { tables.add(0, newT); } else { int pos = tables.indexOf(getTable((CTTbl) o)) + 1; tables.add(pos, newT); } int i = 0; XmlCursor cursor2 = t.newCursor(); while (cursor2.toPrevSibling()) { o = cursor2.getObject(); if (o instanceof CTP || o instanceof CTTbl) i++; } cursor2.dispose(); bodyElements.add(i, newT); cursor2 = t.newCursor(); cursor.toCursor(cursor2); cursor.toEndToken(); cursor2.dispose(); return newT; } return null; }
Example 6
| Project: xdocreport-master File: XWPFStylesDocument.java View source code |
/**
* Returns the table cell borders with conflicts.
*
* @param cell
* @param borderSide
* @return
* @see http://officeopenxml.com/WPtableCellBorderConflicts.php
*/
public TableCellBorder getTableCellBorderWithConflicts(XWPFTableCell cell, BorderSide borderSide) {
/**
* Conflicts between cell borders and table and table-level exception borders If the cell spacing is zero, then
* there is a conflict. The following rules apply as between cell borders and table and table-level exception
* (row) borders (Reference: ECMA-376, 3rd Edition (June, 2011), Fundamentals and Markup Language Reference
* 17.4.40.):
*/
/**
* 1) If there is a cell border, then the cell border is displayed.
*/
/**
* 2) If there is no cell border but there is a table-level exception border on the row, then that table-level
* exception border is displayed.
*/
TableCellBorder border = getTableCellBorder(cell, borderSide);
if (border == null) {
XWPFTable table = cell.getTableRow().getTable();
boolean borderInside = isBorderInside(cell, borderSide);
if (borderInside) {
border = getTableCellBorderInside(cell, borderSide);
if (border == null) {
border = getTableBorderInside(table, borderSide);
}
}
if (border == null && !borderInside) {
/**
* 3) If there is no cell or table-level exception border, then the table border is displayed.
*/
border = getTableBorder(table, borderSide);
}
}
return border;
}Example 7
| Project: WhiteRabbit-master File: ETLDocumentGenerator.java View source code |
private static void addSourceTablesAppendix(CustomXWPFDocument document, ETL etl) {
XWPFParagraph paragraph = document.createParagraph();
XWPFRun run = paragraph.createRun();
run.addBreak(BreakType.PAGE);
run.setText("Appendix: source tables");
run.setFontSize(18);
for (Table sourceTable : etl.getSourceDatabase().getTables()) {
paragraph = document.createParagraph();
run = paragraph.createRun();
run.setText("Table: " + sourceTable.getName());
run.setFontSize(14);
createDocumentParagraph(document, sourceTable.getComment());
XWPFTable table = document.createTable(sourceTable.getFields().size() + 1, 4);
// table.setWidth(2000);
XWPFTableRow header = table.getRow(0);
setTextAndHeaderShading(header.getCell(0), "Field");
setTextAndHeaderShading(header.getCell(1), "Type");
setTextAndHeaderShading(header.getCell(2), "Most freq. value");
setTextAndHeaderShading(header.getCell(3), "Comment");
int rowNr = 1;
for (Field sourceField : sourceTable.getFields()) {
XWPFTableRow row = table.getRow(rowNr++);
row.getCell(0).setText(sourceField.getName());
row.getCell(1).setText(sourceField.getType());
if (sourceField.getValueCounts() != null && sourceField.getValueCounts().length != 0)
row.getCell(2).setText(sourceField.getValueCounts()[0][0]);
createCellParagraph(row.getCell(3), sourceField.getComment().trim());
}
}
run.setFontSize(18);
}Example 8
| Project: DBDocTool-master File: Word2007.java View source code |
/**
* 生成word,表格
*
* @param data
* @throws Exception
*/
public static void productWordForm(Map<String, String> tableinfo, Map<String, LinkedHashMap<String, LinkedHashMap<String, String>>> data, Parameters parameters) throws Exception {
XWPFDocument xDocument = new XWPFDocument();
Iterator<String> tableNameIter = data.keySet().iterator();
while (tableNameIter.hasNext()) {
String table_name = tableNameIter.next();
XWPFParagraph xp = xDocument.createParagraph();
XWPFRun r1 = xp.createRun();
r1.setText(table_name + " " + tableinfo.get(table_name));
r1.setFontSize(18);
r1.setTextPosition(10);
XWPFParagraph p = xDocument.createParagraph();
p.setAlignment(ParagraphAlignment.CENTER);
p.setWordWrap(true);
LinkedHashMap<String, LinkedHashMap<String, String>> columns = data.get(table_name);
int rows = columns.size();
XWPFTable xTable = xDocument.createTable(rows + 1, 7);
//表格属性
CTTblPr tablePr = xTable.getCTTbl().addNewTblPr();
//表格宽度
CTTblWidth width = tablePr.addNewTblW();
width.setW(BigInteger.valueOf(8600));
int i = 0;
xTable.getRow(i).setHeight(380);
setCellText(xDocument, xTable.getRow(i).getCell(0), "代码", "CCCCCC", getCellWidth(0));
setCellText(xDocument, xTable.getRow(i).getCell(1), "注释", "CCCCCC", getCellWidth(1));
setCellText(xDocument, xTable.getRow(i).getCell(2), "类型", "CCCCCC", getCellWidth(2));
setCellText(xDocument, xTable.getRow(i).getCell(3), "默认值", "CCCCCC", getCellWidth(3));
setCellText(xDocument, xTable.getRow(i).getCell(4), "标识", "CCCCCC", getCellWidth(4));
setCellText(xDocument, xTable.getRow(i).getCell(5), "主键", "CCCCCC", getCellWidth(5));
setCellText(xDocument, xTable.getRow(i).getCell(6), "空值", "CCCCCC", getCellWidth(6));
// 下一行
i = i + 1;
// 列column索引
int j = 0;
Map<String, LinkedHashMap<String, String>> keyColumnMap = keyColumns(columns);
for (Iterator<String> columnNameIter = keyColumnMap.keySet().iterator(); columnNameIter.hasNext(); ) {
String column_name = columnNameIter.next();
LinkedHashMap<String, String> columnsAtt = keyColumnMap.get(column_name);
int cwidth = getCellWidth(j);
setCellText(xDocument, xTable.getRow(i).getCell(j), column_name, "FFFFFF", cwidth);
++j;
Iterator<String> columnTypeIter = columnsAtt.keySet().iterator();
while (columnTypeIter.hasNext()) {
String colum_type = columnTypeIter.next();
cwidth = getCellWidth(j);
setCellText(xDocument, xTable.getRow(i).getCell(j), columnsAtt.get(colum_type), "FFFFFF", cwidth);
j++;
}
// 下一行
++i;
// 恢复第一列
j = 0;
}
Iterator<String> cloumnsNameIter = columns.keySet().iterator();
while (cloumnsNameIter.hasNext()) {
xTable.getRow(i).setHeight(380);
String colum_name = cloumnsNameIter.next();
LinkedHashMap<String, String> columnsAtt = columns.get(colum_name);
int cwidth = getCellWidth(j);
if (xTable.getRow(i) == null)
continue;
setCellText(xDocument, xTable.getRow(i).getCell(j), colum_name, "FFFFFF", cwidth);
j++;
Iterator<String> columnTypeIter = columnsAtt.keySet().iterator();
while (columnTypeIter.hasNext()) {
String colum_type = columnTypeIter.next();
cwidth = getCellWidth(j);
setCellText(xDocument, xTable.getRow(i).getCell(j), columnsAtt.get(colum_type), "FFFFFF", cwidth);
j++;
}
// 恢复第一列
j = 0;
//下一行
++i;
}
XWPFTableRow row = xTable.insertNewTableRow(0);
row.setHeight(380);
row.addNewTableCell();
CTTcPr cellPr = row.getCell(0).getCTTc().addNewTcPr();
cellPr.addNewTcW().setW(BigInteger.valueOf(1600));
row.getCell(0).setColor("CCCCCC");
row.getCell(0).setText("中文名称");
row.addNewTableCell();
cellPr = row.getCell(0).getCTTc().addNewTcPr();
cellPr.addNewTcW().setW(BigInteger.valueOf(3000));
row.getCell(1).setColor("FFFFFF");
row.getCell(1).setText(tableinfo.get(table_name));
row.addNewTableCell();
cellPr = row.getCell(0).getCTTc().addNewTcPr();
cellPr.addNewTcW().setW(BigInteger.valueOf(1200));
row.getCell(2).setColor("CCCCCC");
row.getCell(2).setText("英文名称");
row.addNewTableCell();
CTTc cttc = row.getCell(3).getCTTc();
CTTcPr ctPr = cttc.addNewTcPr();
cellPr = row.getCell(0).getCTTc().addNewTcPr();
cellPr.addNewTcW().setW(BigInteger.valueOf(2800));
ctPr.addNewGridSpan().setVal(BigInteger.valueOf(4));
ctPr.addNewHMerge().setVal(STMerge.CONTINUE);
cttc.getPList().get(0).addNewPPr().addNewJc().setVal(STJc.CENTER);
cttc.getPList().get(0).addNewR().addNewT().setStringValue(table_name);
row = xTable.insertNewTableRow(1);
row.setHeight(380);
row.addNewTableCell();
cellPr = row.getCell(0).getCTTc().addNewTcPr();
cellPr.addNewTcW().setW(BigInteger.valueOf(1600));
row.getCell(0).setColor("CCCCCC");
row.getCell(0).setText("功能描述");
row.addNewTableCell();
cellPr = row.getCell(0).getCTTc().addNewTcPr();
cellPr.addNewTcW().setW(BigInteger.valueOf(7000));
cttc = row.getCell(1).getCTTc();
ctPr = cttc.addNewTcPr();
ctPr.addNewGridSpan().setVal(BigInteger.valueOf(6));
ctPr.addNewHMerge().setVal(STMerge.CONTINUE);
cttc.getPList().get(0).addNewPPr().addNewJc().setVal(STJc.LEFT);
cttc.getPList().get(0).addNewR().addNewT().setStringValue("");
}
FileOutputStream fos = new FileOutputStream(parameters.getPath() + parameters.getDatabase() + "_doc.docx");
xDocument.write(fos);
fos.close();
}Example 9
| Project: minos-master File: PrintResult.java View source code |
public void print(int actorsID, String outputFileName, String sinnerFIO) {
double commonResult = 0.0;
String sql = " select mc.name, mc.variety, mrp.cost, mp.min_level from MinosRoundProfile mrp " + " inner join MinosProfile mp on mp.id = mrp.profile_id " + " inner join MinosRoundActors mra on mra.id = mrp.actors_id " + " inner join MinosRound mr on mr.id = mra.round_id " + " inner join MinosCompetence mc on mc.incarnatio = mp.competence_incarnatio " + " where mr.round_start between mc.date_create and mc.date_remove " + " and mrp.actors_id = %id% " + " order by mc.variety";
String request = kdb.makeSQLString(sql, "%id%", String.valueOf(actorsID));
Preconditions.checkNotNull(request, "PrintResult.print() : makeListParam() return null");
TableKeeper tk = null;
try {
tk = kdb.selectRows(request);
if ((tk == null) || (tk.getRowCount() == 0))
return;
int profileSum = 0;
double resultSum = 0.0;
for (int i = 0; i < tk.getRowCount(); i++) {
profileSum += (Integer) tk.getValue(i + 1, 4);
resultSum += (Double) tk.getValue(i + 1, 3);
}
commonResult = resultSum * 100 / profileSum;
// open and save pattern file
XWPFDocument patternDoc = new XWPFDocument(new FileInputStream(patternWordFile));
patternDoc.write(new FileOutputStream(outputFileName));
XWPFDocument workDoc = new XWPFDocument(new FileInputStream(outputFileName));
List<XWPFTable> tbls = workDoc.getTables();
List<XWPFTableRow> rows = tbls.get(0).getRows();
int competenceNum = 1;
boolean fCompetenceWrite = false;
boolean fProfileWrite = false;
String profileColor = null;
boolean fResultWrite = false;
String resultColor = null;
int counter;
boolean flagCompetenceListFinish = false;
int rowForDeleteStart = -1;
int rowForDeleteStop = -1;
System.out.println(rows.size());
for (int i = 0; i < rows.size(); i++) {
// ��������� ������������� ������ � �������� ��� ������ ����������
int num = findCompetenceTestResult(rows.get(i), TEST_RESULT_PATTERN);
if (num >= 0) {
clearParagraphsAndRuns(rows.get(i).getCell(num));
rows.get(i).getCell(num).getParagraphs().get(0).getRuns().get(0).setText(String.format("%4.1f", commonResult) + " %", 0);
continue;
}
// ��������� ������������� ������ � �������� ��� ������ ����������
num = findCompetenceTestResult(rows.get(i), SINNNER_FIO_PATTERN);
if (num >= 0) {
clearParagraphsAndRuns(rows.get(i).getCell(num));
rows.get(i).getCell(num).getParagraphs().get(0).getRuns().get(0).setText(sinnerFIO, 0);
continue;
}
// ������� ������ ������
if (flagCompetenceListFinish) {
rowForDeleteStart = (rowForDeleteStart < 0 ? i : rowForDeleteStart);
rowForDeleteStop = i;
}
resultColor = profileColor = null;
counter = 0;
List<XWPFTableCell> cells = rows.get(i).getTableCells();
for (int j = 0; j < cells.size(); j++) {
if (cells.get(j).getText().equalsIgnoreCase(COMPETENCE_PATTERN) && !flagCompetenceListFinish) {
clearParagraphsAndRuns(cells.get(j));
cells.get(j).getParagraphs().get(0).getRuns().get(0).setText((String) tk.getValue(competenceNum, 1), 0);
fCompetenceWrite = true;
continue;
}
if (cells.get(j).getText().equalsIgnoreCase("profile_level") && !flagCompetenceListFinish) {
clearParagraphsAndRuns(cells.get(j));
XWPFRun run = cells.get(j).getParagraphs().get(0).getRuns().get(0);
run.setText(" ", 0);
profileColor = run.getColor();
counter = 1;
fProfileWrite = true;
if (counter > (Integer) tk.getValue(competenceNum, 4))
break;
}
if (profileColor != null) {
if (counter <= ((Integer) tk.getValue(competenceNum, 4))) {
cells.get(j).setColor(profileColor);
counter++;
continue;
}
break;
}
if (cells.get(j).getText().equalsIgnoreCase("Result_level") && !flagCompetenceListFinish) {
clearParagraphsAndRuns(cells.get(j));
XWPFRun run = cells.get(j).getParagraphs().get(0).getRuns().get(0);
run.setText(" ", 0);
resultColor = run.getColor();
counter = 1;
fResultWrite = true;
Double d = (Double) tk.getValue(competenceNum, 3);
if (counter > d.intValue())
break;
}
if (resultColor != null) {
Double d = (Double) tk.getValue(competenceNum, 3);
if (counter <= d.intValue()) {
cells.get(j).setColor(resultColor);
counter++;
continue;
}
break;
}
}
if (fCompetenceWrite && fProfileWrite && fResultWrite) {
fCompetenceWrite = fResultWrite = fProfileWrite = false;
competenceNum++;
if (competenceNum > tk.getRowCount())
flagCompetenceListFinish = true;
}
}
//remove superfluous rows
int diff = rowForDeleteStop - rowForDeleteStart + 1;
for (int i = 0; i < diff; i++) tbls.get(0).removeRow(rowForDeleteStart);
workDoc.write(new FileOutputStream(outputFileName));
} catch (Exception e) {
e.printStackTrace();
tk = null;
}
}Example 10
| Project: OCRaptor-master File: XWPFWordExtractorDecorator.java View source code |
private void extractIBodyText(IBody bodyElement, XHTMLContentHandler xhtml) throws SAXException, XmlException, IOException {
for (IBodyElement element : bodyElement.getBodyElements()) {
if (element instanceof XWPFParagraph) {
XWPFParagraph paragraph = (XWPFParagraph) element;
extractParagraph(paragraph, xhtml);
}
if (element instanceof XWPFTable) {
XWPFTable table = (XWPFTable) element;
extractTable(table, xhtml);
}
if (element instanceof XWPFSDT) {
extractSDT((XWPFSDT) element, xhtml);
}
}
}Example 11
| Project: HazardTrackingSystem-master File: HazardReportGenerator.java View source code |
// private void createFooter(XWPFDocument doc, Hazards h) throws
// IOException, XmlException {
// //
// http://stackoverflow.com/questions/16442347/counting-pages-in-a-word-document
//
// XWPFHeaderFooterPolicy headerFooterPolicy = doc.getHeaderFooterPolicy();
// headerFooterPolicy.createFooter(STHdrFtr.DEFAULT);
// XWPFFooter footer = headerFooterPolicy.getDefaultFooter();
// // new ParagraphBuilder().text("test").createFooterText(footer);
// XmlDocumentProperties documentProperties =
// doc.getDocument().documentProperties();
//
// doc.createNumbering();
// }
/**
* Adds the header section of NF1825 to the document. The header section
* contains hazard number, phases affected, author, etc.
*
* @param doc
* the template document that hazard data is being added to
* @param h
* the hazard that is currently being written to the document
* @param reviewPhases
* a list of ALL possible Review Phases in the system. This is
* NOT the review phase for the hazard.
*/
private void createHeader(XWPFDocument doc, Hazards h, List<Review_Phases> reviewPhases) {
// Remove the default paragraph in Template.docx
doc.removeBodyElement(0);
XWPFTable top = new TableBuilder().size(1, 2).createTable(doc);
XWPFTableRow row;
XWPFTableCell cell;
row = top.getRow(0);
// "Payload Hazard Report"
cell = row.getCell(0);
cell.setVerticalAlignment(XWPFVertAlign.CENTER);
setColSpan(cell, 3);
new ParagraphBuilder().text("NASA Expendable Launch Vehicle (ELV)").bold(true).fontSize(14).createCellText(cell);
new ParagraphBuilder().text("Payload Safety Hazard Report").bold(true).fontSize(14).createCellText(cell);
new ParagraphBuilder().text("(NPR 8715.7 and NASA-STD 8719.24)").fontSize(8).createCellText(cell);
// Hazard report number and initiation date.
// Can't do row spans, so these "two" cells in the Payload Form are
// actually one cell with a paragraph border.
cell = row.getCell(1);
new CellHeaderBuilder().text("1. Hazard Report #:").createCellHeader(cell);
new ParagraphBuilder().text(h.getHazardNumber()).bold(true).fontSize(10).leftMargin(0).alignment(ParagraphAlignment.CENTER).bottomBorder().createCellText(cell);
new CellHeaderBuilder().text("2. Initiation Date: ").createCellHeader(cell);
String date = h.getInitiationDate() != null ? df.format(h.getInitiationDate()) : "";
new ParagraphBuilder().text(date).createCellText(cell);
// --------------------------------------
row = new TableBuilder().size(1, 2).createTable(doc).getRow(0);
// Payload and Payload Safety Engineer
cell = row.getCell(0);
cell.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(5000));
setColSpan(cell, 3);
new CellHeaderBuilder().text("3. Project Name:").createCellHeader(cell);
Project projectObj = projectManager.getProjectObj(h.getProjectID());
String hProjectName = projectObj == null ? "" : projectObj.getName();
new ParagraphBuilder().text(hProjectName).bottomBorder().createCellText(cell);
new CellHeaderBuilder().text("Payload System Safety Engineer:").createCellHeader(cell);
new ParagraphBuilder().text(h.getPreparer()).createCellText(cell);
// Review Phase
cell = row.getCell(1);
new CellHeaderBuilder().text("4. Review Phase: ").createCellHeader(cell);
for (Review_Phases phase : reviewPhases) {
if (h.getReviewPhase() != null) {
if (phase.getID() == h.getReviewPhase().getID())
new ParagraphBuilder().text("☒\t\t" + phase.getLabel()).leftMargin(100).createCellText(cell);
else
new ParagraphBuilder().text("☐\t\t" + phase.getLabel()).leftMargin(100).createCellText(cell);
}
}
// --------------------------------------
row = new TableBuilder().size(1, 3).createTable(doc).getRow(0);
// Subsystems
cell = row.getCell(0);
setColSpan(cell, 2);
new CellHeaderBuilder().text("5. System/Subsystem: ").createCellHeader(cell);
for (Subsystems s : h.getSubsystems()) {
new ParagraphBuilder().text(s.getLabel()).createCellText(cell);
}
// Hazard groups
cell = row.getCell(1);
new CellHeaderBuilder().text("6. Hazard Group(s): ").createCellHeader(cell);
for (Hazard_Group g : h.getHazardGroups()) {
new ParagraphBuilder().text(g.getLabel()).createCellText(cell);
}
// Date
cell = row.getCell(2);
new CellHeaderBuilder().text("7. Date: ").createCellHeader(cell);
String revisionDate = h.getRevisionDate() != null ? df.format(h.getRevisionDate()) : "";
new ParagraphBuilder().text(revisionDate).createCellText(cell);
// --------------------------------------
row = new TableBuilder().size(1, 1).createTable(doc).getRow(0);
// TODO: Applicable Safety Requirements
cell = row.getCell(0);
setColSpan(cell, 4);
new CellHeaderBuilder().text("8. Applicable Safety Requirements: ").createCellHeader(cell);
new ParagraphBuilder().text("N/A").createCellText(cell);
}Example 12
| Project: MonthlyReport-master File: SearchBean.java View source code |
public void getValues(String[] tables) {
for (int i = 0; i < tables.length; i++) {
System.out.println(tables[i]);
}
String[] searchQuery = new String[10];
for (int i = 0; i < tables.length; i++) {
if (tables[i].equals("Organized")) {
// and start_date=2012-12-13";
searchQuery[i] = "select * from " + tables[i] + " where start_date>='" + start_date + "' and start_date<='" + end_date + "' and verified=1";
type_flag[i] = type1_flag[0];
} else if (tables[i].equals("Conducted")) {
// and start_date=2012-12-13";
searchQuery[i] = "select * from " + tables[i] + " where start_date>='" + start_date + "' and start_date<='" + end_date + "' and verified=1";
type_flag[i] = type1_flag[1];
} else if (tables[i].equals("Attended")) {
// and start_date=2012-12-13";
searchQuery[i] = "select * from " + tables[i] + " where start_date>='" + start_date + "' and start_date<='" + end_date + "' and verified=1";
type_flag[i] = type1_flag[2];
} else if (tables[i].equals("Publication")) {
// and start_date=2012-12-13";
searchQuery[i] = "select * from " + tables[i] + " where date>='" + start_date + "' and date<='" + end_date + "' and verified=1";
type_flag[i] = type1_flag[3];
} else if (tables[i].equals("Stud_achieve")) {
// and start_date=2012-12-13";
searchQuery[i] = "select * from " + tables[i] + " where date>='" + start_date + "' and date<='" + end_date + "' and verified=1";
type_flag[i] = type1_flag[4];
} else if (tables[i].equals("Project")) {
// and start_date=2012-12-13";
searchQuery[i] = "select * from " + tables[i] + " where date>='" + start_date + "' and date<='" + end_date + "' and verified=1";
type_flag[i] = type1_flag[5];
}
}
String str = null, str1 = null, cntQuery;
try {
currentCon = ConnectionManager.getConnection();
stmt = currentCon.createStatement();
for (int i = 0; i < tables.length; i++) {
c = 0;
c1 = 0;
cntQuery = "select count(*) from " + tables[i] + " where verified =1";
rs_cnt = stmt.executeQuery(cntQuery);
while (rs_cnt.next()) {
c1 = rs_cnt.getInt(1);
}
count[i] = c1;
XWPFParagraph p1 = doc.createParagraph();
XWPFRun r1 = p1.createRun();
r1.setText(tables[i]);
r1.setBold(true);
r1.setFontFamily("Calibri");
r1.setFontSize(18);
rs[i] = stmt.executeQuery(searchQuery[i]);
if (type_flag[i].equals("Numbering")) {
while (rs[i].next()) {
c++;
try {
XWPFParagraph p0 = doc.createParagraph();
XWPFRun r0 = p0.createRun();
if (tables[i].equals("Organized")) {
if (rs[i].getString("type").equals("FDP")) {
r0.setText((c) + ". " + getfullname(rs[i].getString("user_iduser"))[0] + " " + getfullname(rs[i].getString("user_iduser"))[1] + " of " + getfullname(rs[i].getString("user_iduser"))[2] + " " + rs[i].getString(2) + " has organized a FDP on " + rs[i].getString(8) + " in association with " + rs[i].getString(6) + " held on " + changedate(rs[i].getString(4)) + ". The title sponsors of the event were " + rs[i].getString(7) + ". The number of participants attending the event were " + rs[i].getString(9) + ".The speaker was " + rs[i].getString(11) + "\n\n");
XWPFParagraph p2 = doc.createParagraph();
XWPFRun r2 = p2.createRun();
r2.setText(" ");
} else if (rs[i].getString("type").equals("Seminar")) {
r0.setText((c) + ". " + getfullname(rs[i].getString("user_iduser"))[0] + " " + getfullname(rs[i].getString("user_iduser"))[1] + " of " + getfullname(rs[i].getString("user_iduser"))[2] + " has organized a seminar on " + rs[i].getString(2) + " , " + rs[i].getString(8) + " in association with " + rs[i].getString(6) + " held on " + changedate(rs[i].getString(4)) + ". The title sponsors of the event were " + rs[i].getString(7) + ". The number of participants attending the event were " + rs[i].getString(9) + ".The speaker was " + rs[i].getString(11) + "\n\n");
XWPFParagraph p2 = doc.createParagraph();
XWPFRun r2 = p2.createRun();
r2.setText(" ");
} else if (rs[i].getString("type").equals("Workshop")) {
r0.setText((c) + ". " + getfullname(rs[i].getString("user_iduser"))[0] + " " + getfullname(rs[i].getString("user_iduser"))[1] + " of " + getfullname(rs[i].getString("user_iduser"))[2] + " " + rs[i].getString(2) + " has organized a workshop on " + rs[i].getString(2) + " , " + rs[i].getString(8) + " in association with " + rs[i].getString(6) + " held on " + changedate(rs[i].getString(4)) + ". The title sponsors of the event were " + rs[i].getString(7) + ". The number of participants attending the event were " + rs[i].getString(9) + ".The speaker was " + rs[i].getString(11) + "\n\n");
XWPFParagraph p2 = doc.createParagraph();
XWPFRun r2 = p2.createRun();
r2.setText(" ");
}
}
if (tables[i].equals("Conducted")) {
if (rs[i].getString(11).equals("1")) {
if (rs[i].getString("type").equals("FDP")) {
r0.setText((c) + ". " + getfullname(rs[i].getString("user_iduser"))[0] + " " + getfullname(rs[i].getString("user_iduser"))[1] + " of " + getfullname(rs[i].getString("user_iduser"))[2] + " " + " has conducted a FDP on " + rs[i].getString(2) + " , " + rs[i].getString(8) + " in association with " + rs[i].getString(6) + " as a keynote speaker " + " held on " + changedate(rs[i].getString(4)) + " .The event witnessed " + rs[i].getString(9) + " particpants.");
XWPFParagraph p2 = doc.createParagraph();
XWPFRun r2 = p2.createRun();
r2.setText(" ");
} else if (rs[i].getString("type").equals("Seminar")) {
r0.setText((c) + ". " + getfullname(rs[i].getString("user_iduser"))[0] + " " + getfullname(rs[i].getString("user_iduser"))[1] + " of " + getfullname(rs[i].getString("user_iduser"))[2] + " " + " has conducted a seminar on " + rs[i].getString(2) + " , " + rs[i].getString(8) + "in association with " + rs[i].getString(6) + "as a keynote speaker " + " held on " + changedate(rs[i].getString(4)) + " .The event witnessed " + rs[i].getString(9) + " particpants.");
XWPFParagraph p2 = doc.createParagraph();
XWPFRun r2 = p2.createRun();
r2.setText(" ");
} else if (rs[i].getString("type").equals("Workshop")) {
r0.setText((c) + ". " + getfullname(rs[i].getString("user_iduser"))[0] + " " + getfullname(rs[i].getString("user_iduser"))[1] + " of " + getfullname(rs[i].getString("user_iduser"))[2] + " " + " has conducted a workshop on " + rs[i].getString(2) + " , " + rs[i].getString(8) + " in association with " + rs[i].getString(6) + "as a keynote speaker " + " held on " + changedate(rs[i].getString(4)) + " .The event witnessed " + rs[i].getString(9) + " particpants.");
XWPFParagraph p2 = doc.createParagraph();
XWPFRun r2 = p2.createRun();
r2.setText(" ");
}
} else {
if (rs[i].getString("type").equals("FDP")) {
r0.setText((c) + ". " + getfullname(rs[i].getString("user_iduser"))[0] + " " + getfullname(rs[i].getString("user_iduser"))[1] + " of " + getfullname(rs[i].getString("user_iduser"))[2] + " " + " has conducted a FDP on " + rs[i].getString(2) + " , " + rs[i].getString(8) + " in association with " + rs[i].getString(6) + " held on " + changedate(rs[i].getString(4)) + " .The event witnessed " + rs[i].getString(9) + " particpants.");
XWPFParagraph p2 = doc.createParagraph();
XWPFRun r2 = p2.createRun();
r2.setText(" ");
} else if (rs[i].getString("type").equals("Seminar")) {
r0.setText((c) + ". " + getfullname(rs[i].getString("user_iduser"))[0] + " " + getfullname(rs[i].getString("user_iduser"))[1] + " of " + getfullname(rs[i].getString("user_iduser"))[2] + " " + " has conducted a seminar on " + rs[i].getString(2) + " , " + rs[i].getString(8) + "in association with " + rs[i].getString(6) + "as a keynote speaker " + " held on " + changedate(rs[i].getString(4)) + " .The event witnessed " + rs[i].getString(9) + " particpants.");
XWPFParagraph p2 = doc.createParagraph();
XWPFRun r2 = p2.createRun();
r2.setText(" ");
} else if (rs[i].getString("type").equals("Workshop")) {
r0.setText((c) + ". " + getfullname(rs[i].getString("user_iduser"))[0] + " " + getfullname(rs[i].getString("user_iduser"))[1] + " of " + getfullname(rs[i].getString("user_iduser"))[2] + " " + " has conducted a workshop on " + rs[i].getString(2) + " , " + rs[i].getString(8) + " in association with " + rs[i].getString(6) + " held on " + changedate(rs[i].getString(4)) + " .The event witnessed " + rs[i].getString(9) + " particpants.");
XWPFParagraph p2 = doc.createParagraph();
XWPFRun r2 = p2.createRun();
r2.setText(" ");
}
}
}
if (tables[i].equals("Attended")) {
if (rs[i].getString("type").equals("FDP")) {
r0.setText((c) + ". " + getfullname(rs[i].getString("user_iduser"))[0] + " " + getfullname(rs[i].getString("user_iduser"))[1] + " of " + getfullname(rs[i].getString("user_iduser"))[2] + " " + " department has attended a FDP on " + rs[i].getString(2) + " in association with " + rs[i].getString(7) + " held on " + changedate(rs[i].getString(4)));
XWPFParagraph p2 = doc.createParagraph();
XWPFRun r2 = p2.createRun();
r2.setText(" ");
} else if (rs[i].getString("type").equals("Seminar")) {
r0.setText((c) + ". " + getfullname(rs[i].getString("user_iduser"))[0] + " " + getfullname(rs[i].getString("user_iduser"))[1] + " of " + getfullname(rs[i].getString("user_iduser"))[2] + " " + " department has attended a seminar on " + rs[i].getString(2) + " in association with " + rs[i].getString(7) + " held on " + changedate(rs[i].getString(4)));
XWPFParagraph p2 = doc.createParagraph();
XWPFRun r2 = p2.createRun();
r2.setText(" ");
} else if (rs[i].getString("type").equals("Workshop")) {
r0.setText((c) + ". " + getfullname(rs[i].getString("user_iduser"))[0] + " " + getfullname(rs[i].getString("user_iduser"))[1] + " of " + getfullname(rs[i].getString("user_iduser"))[2] + " " + " department has attended a workshop on " + rs[i].getString(2) + " in association with " + rs[i].getString(7) + " held on " + changedate(rs[i].getString(4)));
XWPFParagraph p2 = doc.createParagraph();
XWPFRun r2 = p2.createRun();
r2.setText(" ");
}
}
if (tables[i].equals("Publication")) {
if (rs[i].getString(11).equals("1")) {
nat_int = "international";
} else {
nat_int = "national";
}
r0.setText((c) + ". " + getfullname(rs[i].getString("user_iduser"))[0] + " " + getfullname(rs[i].getString("user_iduser"))[1] + " of " + getfullname(rs[i].getString("user_iduser"))[2] + " " + " department has published a paper on " + rs[i].getString(2) + " in " + rs[i].getString(4) + " " + rs[i].getString(3) + " issue " + rs[i].getString(6) + " ,volume " + rs[i].getString(7) + " page nos. " + rs[i].getString(8) + " and the authors are " + rs[i].getString(9) + " on " + changedate(rs[i].getString(5)) + " The scope of the paper was " + nat_int);
XWPFParagraph p2 = doc.createParagraph();
XWPFRun r2 = p2.createRun();
r2.setText(" ");
}
if (tables[i].equals("Stud_achieve")) {
r0.setText((c) + ". " + getstud_details(rs[i].getString("student_idstudent"))[0] + " roll no " + getstud_details(rs[i].getString("student_idstudent"))[1] + " alongwith " + rs[i].getString("co_participants") + "of " + getstud_details(rs[i].getString("student_idstudent"))[2] + " " + " department have participated in " + rs[i].getString("event_name") + " held at " + rs[i].getString("place") + " . The team secured " + rs[i].getString("position") + " position in " + rs[i].getString("type") + " .");
XWPFParagraph p2 = doc.createParagraph();
XWPFRun r2 = p2.createRun();
r2.setText(" ");
}
if (tables[i].equals("Project")) {
r0.setText((c) + ". " + getstud_details(rs[i].getString("student_idstudent"))[0] + " roll no " + getstud_details(rs[i].getString("student_idstudent"))[1] + " alongwith " + rs[i].getString("co_participants") + " of " + getstud_details(rs[i].getString("student_idstudent"))[2] + " " + " department have submitted a project in " + rs[i].getString("title") + " in the domain of " + rs[i].getString("domain") + " at " + rs[i].getString("event_name") + " held in " + rs[i].getString("place") + " . The team secured " + rs[i].getString("position") + " position. The basic description is as follows : " + rs[i].getString("description") + " .");
XWPFParagraph p2 = doc.createParagraph();
XWPFRun r2 = p2.createRun();
r2.setText(" ");
}
r0.setBold(false);
r0.setFontFamily("Times New Roman");
r0.setFontSize(12);
} catch (NullPointerException ex) {
ex.printStackTrace();
System.out.println(ex);
}
}
} else {
XWPFTable t0 = null;
if (tables[i].equals("Conducted")) {
t0 = doc.createTable(count[i] + 1, 10);
t0.getRow(0).getCell(0).setText("Name");
t0.getRow(0).getCell(1).setText("Name of Event");
t0.getRow(0).getCell(2).setText("Type");
t0.getRow(0).getCell(3).setText("Start Date");
t0.getRow(0).getCell(4).setText("No. of days");
t0.getRow(0).getCell(5).setText("Association");
t0.getRow(0).getCell(6).setText("Sponsor");
t0.getRow(0).getCell(7).setText("Place");
t0.getRow(0).getCell(8).setText("No. of Particpants");
t0.getRow(0).getCell(9).setText("Keynote");
}
if (tables[i].equals("Attended")) {
t0 = doc.createTable(count[i] + 1, 6);
t0.getRow(0).getCell(0).setText("Name");
t0.getRow(0).getCell(1).setText("Name of Event");
t0.getRow(0).getCell(2).setText("Type");
t0.getRow(0).getCell(3).setText("Start Date");
t0.getRow(0).getCell(4).setText("No. of days");
t0.getRow(0).getCell(5).setText("Association");
}
if (tables[i].equals("Organized")) {
t0 = doc.createTable(count[i] + 1, 10);
t0.getRow(0).getCell(0).setText("Name");
t0.getRow(0).getCell(1).setText("Name of Event");
t0.getRow(0).getCell(2).setText("Type");
t0.getRow(0).getCell(3).setText("Start Date");
t0.getRow(0).getCell(4).setText("No. of days");
t0.getRow(0).getCell(5).setText("Association");
t0.getRow(0).getCell(6).setText("Sponsor");
t0.getRow(0).getCell(7).setText("Place");
t0.getRow(0).getCell(8).setText("No. of Particpants");
t0.getRow(0).getCell(9).setText("Speaker");
}
if (tables[i].equals("Stud_achieve")) {
t0 = doc.createTable(count[i] + 1, 7);
t0.getRow(0).getCell(0).setText("Name");
t0.getRow(0).getCell(1).setText("Co-Participant");
t0.getRow(0).getCell(2).setText("Event");
t0.getRow(0).getCell(3).setText("Place");
t0.getRow(0).getCell(4).setText("Date");
t0.getRow(0).getCell(5).setText("Position");
t0.getRow(0).getCell(6).setText("Type");
}
if (tables[i].equals("Publication")) {
t0 = doc.createTable(count[i] + 1, 10);
t0.getRow(0).getCell(0).setText("Name");
t0.getRow(0).getCell(1).setText("Title");
t0.getRow(0).getCell(2).setText("Type");
t0.getRow(0).getCell(3).setText("Published In");
t0.getRow(0).getCell(4).setText("Date");
t0.getRow(0).getCell(5).setText("Volume");
t0.getRow(0).getCell(6).setText("Issue");
t0.getRow(0).getCell(7).setText("Page No.");
t0.getRow(0).getCell(8).setText("Author");
t0.getRow(0).getCell(9).setText("Scope");
}
if (tables[i].equals("Project")) {
t0 = doc.createTable(count[i] + 1, 9);
t0.getRow(0).getCell(0).setText("Name");
t0.getRow(0).getCell(1).setText("Co-Participant");
t0.getRow(0).getCell(2).setText("Title");
t0.getRow(0).getCell(3).setText("Domain");
t0.getRow(0).getCell(4).setText("Description");
t0.getRow(0).getCell(5).setText("Event");
t0.getRow(0).getCell(6).setText("Place");
t0.getRow(0).getCell(7).setText("Date");
t0.getRow(0).getCell(8).setText("Position");
}
c = 1;
while (rs[i].next()) {
String date;
if (tables[i].equals("Publication"))
date = rs[i].getString(5);
else if (tables[i].equals("Stud_achieve")) {
date = rs[i].getString(3);
} else if (tables[i].equals("Project")) {
date = rs[i].getString(7);
} else
date = rs[i].getString(4);
SimpleDateFormat fromUser = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat myFormat = new SimpleDateFormat("dd-MM-yyyy");
try {
date = myFormat.format(fromUser.parse(date));
} catch (ParseException e) {
e.printStackTrace();
}
try {
if (tables[i].equals("Attended")) {
t0.getRow(c).getCell(0).setText(getfullname(rs[i].getString("user_iduser"))[0] + ". " + getfullname(rs[i].getString("user_iduser"))[1]);
t0.getRow(c).getCell(1).setText(rs[i].getString(2));
t0.getRow(c).getCell(2).setText(rs[i].getString(3));
t0.getRow(c).getCell(3).setText(date);
t0.getRow(c).getCell(4).setText(rs[i].getString(5));
t0.getRow(c).getCell(5).setText(rs[i].getString(7));
}
if (tables[i].equals("Organized")) {
t0.getRow(c).getCell(0).setText(getfullname(rs[i].getString("user_iduser"))[0] + ". " + getfullname(rs[i].getString("user_iduser"))[1]);
t0.getRow(c).getCell(1).setText(rs[i].getString(2));
t0.getRow(c).getCell(2).setText(rs[i].getString(3));
t0.getRow(c).getCell(3).setText(date);
t0.getRow(c).getCell(4).setText(rs[i].getString(5));
t0.getRow(c).getCell(5).setText(rs[i].getString(6));
t0.getRow(c).getCell(6).setText(rs[i].getString(7));
t0.getRow(c).getCell(7).setText(rs[i].getString(8));
t0.getRow(c).getCell(8).setText(rs[i].getString(9));
t0.getRow(c).getCell(9).setText(rs[i].getString(11));
}
if (tables[i].equals("Conducted")) {
t0.getRow(c).getCell(0).setText(getfullname(rs[i].getString("user_iduser"))[0] + ". " + getfullname(rs[i].getString("user_iduser"))[1]);
t0.getRow(c).getCell(1).setText(rs[i].getString(2));
t0.getRow(c).getCell(2).setText(rs[i].getString(3));
t0.getRow(c).getCell(3).setText(date);
t0.getRow(c).getCell(4).setText(rs[i].getString(5));
t0.getRow(c).getCell(5).setText(rs[i].getString(6));
t0.getRow(c).getCell(6).setText(rs[i].getString(7));
t0.getRow(c).getCell(7).setText(rs[i].getString(8));
t0.getRow(c).getCell(8).setText(rs[i].getString(9));
if (rs[i].getString(11).equals("1")) {
key_speaker = "yes";
} else {
key_speaker = "no";
}
t0.getRow(c).getCell(9).setText(key_speaker);
}
if (tables[i].equals("Stud_achieve")) {
t0.getRow(c).getCell(0).setText(getstud_details(rs[i].getString("student_idstudent"))[0]);
t0.getRow(c).getCell(1).setText(rs[i].getString("co_participants"));
t0.getRow(c).getCell(2).setText(rs[i].getString("event_name"));
t0.getRow(c).getCell(3).setText(rs[i].getString("place"));
t0.getRow(c).getCell(4).setText(date);
t0.getRow(c).getCell(5).setText(rs[i].getString("position"));
t0.getRow(c).getCell(6).setText(rs[i].getString("type"));
}
if (tables[i].equals("Project")) {
t0.getRow(c).getCell(0).setText(getstud_details(rs[i].getString("student_idstudent"))[0]);
t0.getRow(c).getCell(1).setText(rs[i].getString("co_participants"));
t0.getRow(c).getCell(2).setText(rs[i].getString("title"));
t0.getRow(c).getCell(3).setText(rs[i].getString("domain"));
t0.getRow(c).getCell(4).setText(rs[i].getString("description"));
t0.getRow(c).getCell(5).setText(rs[i].getString("event_name"));
t0.getRow(c).getCell(6).setText(rs[i].getString("place"));
t0.getRow(c).getCell(7).setText(date);
t0.getRow(c).getCell(8).setText(rs[i].getString("position"));
}
if (tables[i].equals("Publication")) {
t0.getRow(c).getCell(0).setText(getfullname(rs[i].getString("user_iduser"))[0] + ". " + getfullname(rs[i].getString("user_iduser"))[1]);
t0.getRow(c).getCell(1).setText(rs[i].getString(2));
t0.getRow(c).getCell(2).setText(rs[i].getString(3));
t0.getRow(c).getCell(3).setText(rs[i].getString(4));
t0.getRow(c).getCell(4).setText(date);
t0.getRow(c).getCell(5).setText(rs[i].getString(6));
t0.getRow(c).getCell(6).setText(rs[i].getString(7));
t0.getRow(c).getCell(7).setText(rs[i].getString(8));
t0.getRow(c).getCell(8).setText(rs[i].getString(9));
if (rs[i].getString(11).equals("1")) {
nat_int = "international";
} else {
nat_int = "national";
}
t0.getRow(c).getCell(9).setText(nat_int);
}
} catch (NullPointerException ex) {
ex.printStackTrace();
System.out.println(ex);
}
c++;
}
}
}
FileOutputStream out = new FileOutputStream("D:/report_trial.docx");
doc.write(out);
out.close();
System.out.println("copied successfully");
} catch (Throwable e) {
System.out.println(e);
e.printStackTrace();
}
}Example 13
| Project: Aspose_Words_Java-master File: ApacheFormattedTable.java View source code |
public static void main(String[] args) throws Exception {
// The path to the documents directory.
String dataDir = Utils.getDataDir(ApacheFormattedTable.class);
// Create a new document from scratch
XWPFDocument doc = new XWPFDocument();
// -- OR --
// open an existing empty document with styles already defined
//XWPFDocument doc = new XWPFDocument(new FileInputStream("base_document.docx"));
// Create a new table with 6 rows and 3 columns
int nRows = 6;
int nCols = 3;
XWPFTable table = doc.createTable(nRows, nCols);
// 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");
// Get a list of the rows in the table
List<XWPFTableRow> rows = table.getRows();
int rowCt = 0;
int colCt = 0;
for (XWPFTableRow row : rows) {
// get table row properties (trPr)
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));
// get the cells in this row
List<XWPFTableCell> cells = row.getTableCells();
// add content to each cell
for (XWPFTableCell cell : cells) {
// get a table cell properties element (tcPr)
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("A7BFDE");
} else if (rowCt % 2 == 0) {
// even row
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
XWPFRun rh = para.createRun();
// style cell as desired
if (colCt == nCols - 1) {
// last column is 10pt Courier
rh.setFontSize(10);
rh.setFontFamily("Courier");
}
if (rowCt == 0) {
// header row
rh.setText("header row, col " + colCt);
rh.setBold(true);
para.setAlignment(ParagraphAlignment.CENTER);
} else if (rowCt % 2 == 0) {
// even row
rh.setText("row " + rowCt + ", col " + colCt);
para.setAlignment(ParagraphAlignment.LEFT);
} else {
// odd row
rh.setText("row " + rowCt + ", col " + colCt);
para.setAlignment(ParagraphAlignment.LEFT);
}
colCt++;
}
// for cell
colCt = 0;
rowCt++;
}
// for row
// write the file
FileOutputStream out = new FileOutputStream(dataDir + "Apache_styledTable.docx");
doc.write(out);
out.close();
System.out.println("Process Completed Successfully");
}Example 14
| Project: Aspose_for_Apache_POI-master File: ApacheFormattedTable.java View source code |
public static void main(String[] args) throws Exception {
// Create a new document from scratch
XWPFDocument doc = new XWPFDocument();
// -- OR --
// open an existing empty document with styles already defined
//XWPFDocument doc = new XWPFDocument(new FileInputStream("base_document.docx"));
// Create a new table with 6 rows and 3 columns
int nRows = 6;
int nCols = 3;
XWPFTable table = doc.createTable(nRows, nCols);
// 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");
// Get a list of the rows in the table
List<XWPFTableRow> rows = table.getRows();
int rowCt = 0;
int colCt = 0;
for (XWPFTableRow row : rows) {
// get table row properties (trPr)
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));
// get the cells in this row
List<XWPFTableCell> cells = row.getTableCells();
// add content to each cell
for (XWPFTableCell cell : cells) {
// get a table cell properties element (tcPr)
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("A7BFDE");
} else if (rowCt % 2 == 0) {
// even row
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
XWPFRun rh = para.createRun();
// style cell as desired
if (colCt == nCols - 1) {
// last column is 10pt Courier
rh.setFontSize(10);
rh.setFontFamily("Courier");
}
if (rowCt == 0) {
// header row
rh.setText("header row, col " + colCt);
rh.setBold(true);
para.setAlignment(ParagraphAlignment.CENTER);
} else if (rowCt % 2 == 0) {
// even row
rh.setText("row " + rowCt + ", col " + colCt);
para.setAlignment(ParagraphAlignment.LEFT);
} else {
// odd row
rh.setText("row " + rowCt + ", col " + colCt);
para.setAlignment(ParagraphAlignment.LEFT);
}
colCt++;
}
// for cell
colCt = 0;
rowCt++;
}
// for row
// write the file
FileOutputStream out = new FileOutputStream("data/Apache_styledTable.docx");
doc.write(out);
out.close();
System.out.println("Process Completed Successfully");
}Example 15
| Project: tika-master File: XWPFWordExtractorDecorator.java View source code |
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);
}
}
}