use of org.apache.poi.xwpf.usermodel.XWPFTableRow in project pmph by BCSquad.
the class WordHelper method fillDecTeachExpData.
private XWPFTable fillDecTeachExpData(XWPFTable table, List<DecTeachExp> decTeachExps) {
if (CollectionUtil.isEmpty(decTeachExps)) {
return table;
}
if (decTeachExps.size() > 1) {
int height = table.getRow(1).getHeight();
for (int i = 1; i < decTeachExps.size(); i++) {
table.createRow().setHeight(height);
}
}
List<XWPFTableRow> rows = table.getRows();
List<XWPFTableCell> cells;
int rowCount = 1;
for (DecTeachExp decTeachExp : decTeachExps) {
cells = rows.get(rowCount).getTableCells();
String dateBegin = decTeachExp.getDateBegin();
if (StringUtil.isEmpty(dateBegin)) {
dateBegin = "未知";
}
String dateEnd = decTeachExp.getDateEnd();
if (StringUtil.isEmpty(dateEnd)) {
dateEnd = "至今";
}
String value = dateBegin.concat("~").concat(dateEnd);
cells.get(0).setText(value);
value = decTeachExp.getSchoolName();
if (StringUtil.notEmpty(value)) {
cells.get(1).setText(value);
}
value = decTeachExp.getSubject();
if (StringUtil.notEmpty(value)) {
cells.get(2).setText(value);
}
value = decTeachExp.getNote();
if (StringUtil.notEmpty(value)) {
cells.get(3).setText(value);
}
for (XWPFTableCell cell : cells) {
cell.setVerticalAlignment(XWPFVertAlign.CENTER);
}
rowCount++;
}
return table;
}
use of org.apache.poi.xwpf.usermodel.XWPFTableRow in project pmph by BCSquad.
the class WordHelper method insertXWPFParagraph.
public static void insertXWPFParagraph(String key, XWPFDocument doc2, XWPFTable xwpfTable) {
List<XWPFParagraph> paragraphList = doc2.getParagraphs();
if (paragraphList != null && paragraphList.size() > 0) {
for (int i = 0; i < paragraphList.size(); i++) {
List<XWPFRun> runs = paragraphList.get(i).getRuns();
for (XWPFRun run : runs) {
String text = run.getText(0);
if (text != null) {
if (text.equals(key)) {
XmlCursor cursor = paragraphList.get(i + 1).getCTP().newCursor();
XWPFTable table = doc2.insertNewTbl(cursor);
XWPFTableRow tableRow = table.getRow(0);
for (int cellNum = 0; cellNum < 27; cellNum++) {
tableRow.addNewTableCell();
}
for (int rowNum = 0; rowNum < 3; rowNum++) {
table.createRow();
}
// 合并列(没有作用)
for (int rowNum = 0; rowNum < table.getRows().size(); rowNum++) {
for (int cellIndex = 0; cellIndex < tableRow.getTableCells().size(); cellIndex++) {
CTHMerge hmerge = CTHMerge.Factory.newInstance();
if (cellIndex == 0) {
// The first merged cell is set with RESTART merge value
hmerge.setVal(STMerge.RESTART);
} else {
// Cells which join (merge) the first one, are set with CONTINUE
hmerge.setVal(STMerge.CONTINUE);
}
XWPFTableCell cell = table.getRow(rowNum).getCell(cellIndex);
// Try getting the TcPr. Not simply setting an new one every time.
CTTcPr tcPr = cell.getCTTc().getTcPr();
if (tcPr != null) {
tcPr.setHMerge(hmerge);
} else {
// only set an new TcPr if there is not one already
tcPr = CTTcPr.Factory.newInstance();
tcPr.setHMerge(hmerge);
cell.getCTTc().setTcPr(tcPr);
}
}
}
// 合并行
for (int col = 0; col < tableRow.getTableCells().size(); col++) {
for (int rowIndex = 0; rowIndex < table.getRows().size(); rowIndex++) {
XWPFTableCell cell = table.getRow(rowIndex).getCell(col);
if (rowIndex == 0) {
// The first merged cell is set with RESTART merge value
cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.RESTART);
} else {
// Cells which join (merge) the first one, are set with CONTINUE
cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.CONTINUE);
}
}
}
}
}
}
}
}
}
use of org.apache.poi.xwpf.usermodel.XWPFTableRow in project pmph by BCSquad.
the class WordHelper method addTable.
public XWPFDocument addTable(XWPFDocument document) {
List<XWPFTable> tables = document.getTables();
XWPFTable old = tables.get(19);
XWPFTable t = document.createTable();
XWPFTableRow row = t.getRow(0);
XWPFTableCell cell = row.getCell(0);
CTTc cttc = cell.getCTTc();
CTTcPr tcpr = cttc.addNewTcPr();
CTTblWidth tcw = tcpr.addNewTcW();
tcw.setType(old.getRow(0).getCell(0).getCTTc().getTcPr().getTcW().getType());
tcw.setW(old.getRow(0).getCell(0).getCTTc().getTcPr().getTcW().getW());
if (old.getRow(0).getCell(0).getCTTc().getTcPr().getGridSpan() != null) {
tcpr.setGridSpan(old.getRow(0).getCell(0).getCTTc().getTcPr().getGridSpan());
}
XWPFRun run = cell.getParagraphs().get(0).createRun();
run.setText("Cells which join (merge) the first one, are set with CONTINUE");
return document;
}
use of org.apache.poi.xwpf.usermodel.XWPFTableRow in project pmph by BCSquad.
the class WordHelper method fillDecResearchData.
private XWPFTable fillDecResearchData(XWPFTable table, List<DecResearch> decResearchs) {
if (CollectionUtil.isEmpty(decResearchs)) {
return table;
}
if (decResearchs.size() > 1) {
int height = table.getRow(1).getHeight();
for (int i = 1; i < decResearchs.size(); i++) {
table.createRow().setHeight(height);
}
}
List<XWPFTableRow> rows = table.getRows();
List<XWPFTableCell> cells;
int rowCount = 1;
for (DecResearch decResearch : decResearchs) {
cells = rows.get(rowCount).getTableCells();
String value = decResearch.getResearchName();
if (StringUtil.notEmpty(value)) {
cells.get(0).setText(value);
}
value = decResearch.getApprovalUnit();
if (StringUtil.notEmpty(value)) {
cells.get(1).setText(value);
}
value = decResearch.getAward();
if (StringUtil.notEmpty(value)) {
cells.get(2).setText(value);
}
value = decResearch.getNote();
if (StringUtil.notEmpty(value)) {
cells.get(3).setText(value);
}
for (XWPFTableCell cell : cells) {
cell.setVerticalAlignment(XWPFVertAlign.CENTER);
}
rowCount++;
}
return table;
}
use of org.apache.poi.xwpf.usermodel.XWPFTableRow in project pmph by BCSquad.
the class WordHelper method fillDecEduExpData.
private XWPFTable fillDecEduExpData(XWPFTable table, List<DecEduExp> decEduExps) {
if (CollectionUtil.isEmpty(decEduExps)) {
return table;
}
if (decEduExps.size() > 1) {
int height = table.getRow(1).getHeight();
for (int i = 1; i < decEduExps.size(); i++) {
table.createRow().setHeight(height);
}
}
List<XWPFTableRow> rows = table.getRows();
List<XWPFTableCell> cells;
int rowCount = 1;
for (DecEduExp decEduExp : decEduExps) {
cells = rows.get(rowCount).getTableCells();
String dateBegin = decEduExp.getDateBegin();
if (StringUtil.isEmpty(dateBegin)) {
dateBegin = "未知";
}
String dateEnd = decEduExp.getDateEnd();
if (StringUtil.isEmpty(dateEnd)) {
dateEnd = "至今";
}
String value = dateBegin.concat("~").concat(dateEnd);
cells.get(0).setText(value);
value = decEduExp.getSchoolName();
if (StringUtil.notEmpty(value)) {
cells.get(1).setText(value);
}
value = decEduExp.getMajor();
if (StringUtil.notEmpty(value)) {
cells.get(2).setText(value);
}
value = decEduExp.getDegree();
if (StringUtil.notEmpty(value)) {
cells.get(3).setText(value);
}
value = decEduExp.getNote();
if (StringUtil.notEmpty(value)) {
cells.get(4).setText(value);
}
for (XWPFTableCell cell : cells) {
cell.setVerticalAlignment(XWPFVertAlign.CENTER);
}
rowCount++;
}
return table;
}
Aggregations