master
wenyu441069198 5 months ago
parent f0fb100244
commit 45f7e375bf
  1. 109
      src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java
  2. BIN
      src/main/resources/templates/courses.docx

@ -395,21 +395,14 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
//获取第2个表格----------
XWPFTable table = document.getTables().get(1);
// // 获取表格行
// List<XWPFTableRow> rows = table.getRows();
// //获取第一行
// XWPFTableRow row = rows.get(0);
// //获取第一行第一列
// XWPFTableCell cell = row.getCell(0);
//获取此行的每列数据
// List<XWPFTableCell> cells = row.getTableCells();
// System.out.println(cells.size());// 打印单元格数量
for (int i = 0; i < course_number - 1; i++) {
//新增一行单元格
XWPFTableRow newRow = table.createRow();
newRow.getCell(0).setText("课程目标" + (i + 2));
// //垂直居中
// newRow.getCell(0).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
newRow.getCell(0).getParagraphArray(0).setAlignment(ParagraphAlignment.CENTER);//水平居中
newRow.getCell(0).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);//垂直居中
}
//获取第5个表格
@ -418,44 +411,21 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
for (int i = 0; i < course_number - 1; i++) {
//新增一行单元格
XWPFTableRow newRow = table5.createRow();
//获取第一列里的段落
// XWPFParagraph newPara = newRow.getCell(0).getParagraphArray(0);
// XWPFRun newRun = newPara.createRun();
//序号
// newRow.getCell(0).getParagraphArray(0).getRuns().get(0).setText((i + 2) + "");
newRow.getCell(0).setText(Integer.valueOf(i+2).toString());
// newRow.getCell(0).getTableCell()
newRow.getCell(0).getParagraphArray(0).setIndentationLeft(0);
newRow.getCell(0).getParagraphArray(0).setIndentationHanging(0);
// newRow.getCell(0).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.TOP);
// newRow.getCell(0).setText(Integer.valueOf(i+2).toString().replaceAll("[\\s\\u00A0]+","").trim());
// newRun.setText((i + 2) + "");
// newPara.setAlignment(ParagraphAlignment.CENTER);//水平居中
// newRow.getCell(0).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);//垂直居中
newRow.getCell(0).getParagraphArray(0).setAlignment(ParagraphAlignment.CENTER);//水平居中
newRow.getCell(0).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);//垂直居中
//课程目标
newRow.getCell(1).setText(" 课程目标" + (i + 2));
newRow.getCell(1).setText("课程目标" + (i + 2));
newRow.getCell(1).getParagraphArray(0).setAlignment(ParagraphAlignment.CENTER);//水平居中
newRow.getCell(1).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);//垂直居中
//扩四列
for (int j = 0; j < 4; j++) {
newRow.createCell();
}
}
table5.setTableAlignment(TableRowAlign.CENTER);
// //遍历单元格并打印内容
// for (XWPFTableCell cell : cells) {
// // 假设单元格只包含段落,遍历段落并打印文本
// for (XWPFParagraph paragraph : cell.getParagraphs()) {
// for (XWPFRun run : paragraph.getRuns()) {
// run.setText("xxx",0);
// System.out.print(run.getText(0)); // 打印文本内容,参数0表示不考虑样式分隔符
// }
// System.out.println(); // 在每个段落后打印换行符
// }
// }
// System.out.println("表格行数:"+rows.size());
//文件名=课程名+课程标准
@ -467,65 +437,6 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
document.write(outputStream);
}
// public static void insertRow(XWPFTable table, int copyrowIndex, int newrowIndex) {
// // 在表格中指定的位置新增一行
// XWPFTableRow targetRow = table.insertNewTableRow(newrowIndex);
// // 获取需要复制行对象
// XWPFTableRow copyRow = table.getRow(copyrowIndex);
// //复制行对象给新增的行对象
// targetRow.getCtRow().setTrPr(copyRow.getCtRow().getTrPr());
// //获取需要复制行对象的列
// List<XWPFTableCell> copyCells = copyRow.getTableCells();
// //新增的对象的列
// XWPFTableCell targetCell = null;
// //遍历复制行对象的列
// for (int i = 0; i < copyCells.size(); i++) {
// //复制行对象的列
// XWPFTableCell copyCell = copyCells.get(i);
// //新增的行对象创建一列
// targetCell = targetRow.addNewTableCell();
// //格式复制
// targetCell.getCTTc().setTcPr(copyCell.getCTTc().getTcPr());
// if (copyCell.getParagraphs() != null && copyCell.getParagraphs().size() > 0) {
// targetCell.getParagraphs().get(0).getCTP().setPPr(copyCell.getParagraphs().get(0).getCTP().getPPr());
// if (copyCell.getParagraphs().get(0).getRuns() != null
// && copyCell.getParagraphs().get(0).getRuns().size() > 0) {
// XWPFRun cellR = targetCell.getParagraphs().get(0).createRun();
// cellR.setBold(copyCell.getParagraphs().get(0).getRuns().get(0).isBold());
// }
// }
// }
//
// }
//
// private static void replaceVariable(XWPFDocument document, String variable, String replacement) {
// for (XWPFParagraph paragraph : document.getParagraphs()) {
// for (XWPFRun run : paragraph.getRuns()) {
// String text = run.getText(0);
// if (text != null && text.contains(variable)) {
// text = text.replace(variable, replacement);
// run.setText(text, 0);
// // run.setFontFamily("Arial");
// // run.setFontSize(14);
// }
// }
// }
// }
// private static void replaceVariableInTable(XWPFTable table, String variable, String replacement) {
// for (XWPFTableRow row : table.getRows()) {
// for (XWPFTableCell cell : row.getTableCells()) {
// for (XWPFParagraph paragraph : cell.getParagraphs()) {
// for (XWPFRun run : paragraph.getRuns()) {
// String text = run.getText(0);
// if (text != null && text.contains(variable)) {
// text = text.replace(variable, replacement);
// run.setText(text, 0);
// }
// }
// }
// }
// }
// }
}

Loading…
Cancel
Save