Browse Source

word 换行

4.1.3.A
jueyue 9 years ago
parent
commit
f5c12773bd
4 changed files with 27 additions and 4 deletions
  1. +19
    -0
      easypoi-base/src/main/java/org/jeecgframework/poi/util/PoiPublicUtil.java
  2. +1
    -1
      easypoi-base/src/main/java/org/jeecgframework/poi/word/parse/ParseWord07.java
  3. +2
    -1
      easypoi-base/src/main/java/org/jeecgframework/poi/word/parse/excel/ExcelEntityParse.java
  4. +5
    -2
      easypoi-base/src/main/java/org/jeecgframework/poi/word/parse/excel/ExcelMapParse.java

+ 19
- 0
easypoi-base/src/main/java/org/jeecgframework/poi/util/PoiPublicUtil.java View File

@@ -47,6 +47,7 @@ import org.apache.poi.xssf.usermodel.XSSFShape;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.jeecgframework.poi.excel.annotation.ExcelCollection;
import org.jeecgframework.poi.excel.annotation.ExcelEntity;
@@ -457,5 +458,23 @@ public final class PoiPublicUtil {
}
return defalut;
}
/**
* 支持换行操作
* @param currentRun
* @param currentText
*/
public static void setWordText(XWPFRun currentRun, String currentText) {
if(StringUtils.isNotBlank(currentText)){
String[] tempArr = currentText.split("\r\n");
for (int i = 0, le = tempArr.length - 1; i < le; i++) {
currentRun.setText(tempArr[i], i);
currentRun.addBreak();
}
currentRun.setText(tempArr[tempArr.length - 1], tempArr.length - 1);
}
}
}

+ 1
- 1
easypoi-base/src/main/java/org/jeecgframework/poi/word/parse/ParseWord07.java View File

@@ -94,7 +94,7 @@ public class ParseWord07 {
addAnImage((WordImageEntity) obj, currentRun);
} else {
currentText = obj.toString();
currentRun.setText(currentText, 0);
PoiPublicUtil.setWordText(currentRun, currentText);
}
for (int k = 0; k < runIndex.size(); k++) {
paragraph.getRuns().get(runIndex.get(k)).setText("", 0);


+ 2
- 1
easypoi-base/src/main/java/org/jeecgframework/poi/word/parse/excel/ExcelEntityParse.java View File

@@ -183,8 +183,9 @@ public class ExcelEntityParse extends ExportBase {
private void setCellValue(XWPFTableRow row, Object value, int cellNum) {
if (row.getCell(cellNum++) != null) {
row.getCell(cellNum - 1).setText(value == null ? "" : value.toString());
PoiPublicUtil.setWordText(row.createCell().addParagraph().createRun(),value == null ? "" : value.toString());
} else {
row.createCell().setText(value == null ? "" : value.toString());
PoiPublicUtil.setWordText(row.createCell().addParagraph().createRun(),value == null ? "" : value.toString());
}
}


+ 5
- 2
easypoi-base/src/main/java/org/jeecgframework/poi/word/parse/excel/ExcelMapParse.java View File

@@ -20,9 +20,11 @@ import static org.jeecgframework.poi.util.PoiElUtil.*;
import java.util.List;
import java.util.Map;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;
import org.jeecgframework.poi.util.PoiPublicUtil;
import com.google.common.collect.Maps;
@@ -79,12 +81,13 @@ public final class ExcelMapParse {
tempMap.put("t", obj);
for (cellIndex = 0; cellIndex < currentRow.getTableCells().size(); cellIndex++) {
String val = eval(params[cellIndex], tempMap).toString();
currentRow.getTableCells().get(cellIndex).setText(val);
currentRow.getTableCells().get(cellIndex).setText("");
PoiPublicUtil.setWordText(currentRow.getTableCells().get(cellIndex).addParagraph().createRun(),val);
}
for (; cellIndex < params.length; cellIndex++) {
String val = eval(params[cellIndex], tempMap).toString();
currentRow.createCell().setText(val);
PoiPublicUtil.setWordText(currentRow.createCell().addParagraph().createRun(),val);
}
}


Loading…
Cancel
Save