@@ -47,6 +47,7 @@ import org.apache.poi.xssf.usermodel.XSSFShape; | |||||
import org.apache.poi.xssf.usermodel.XSSFSheet; | import org.apache.poi.xssf.usermodel.XSSFSheet; | ||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook; | import org.apache.poi.xssf.usermodel.XSSFWorkbook; | ||||
import org.apache.poi.xwpf.usermodel.XWPFDocument; | 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.Excel; | ||||
import org.jeecgframework.poi.excel.annotation.ExcelCollection; | import org.jeecgframework.poi.excel.annotation.ExcelCollection; | ||||
import org.jeecgframework.poi.excel.annotation.ExcelEntity; | import org.jeecgframework.poi.excel.annotation.ExcelEntity; | ||||
@@ -457,5 +458,23 @@ public final class PoiPublicUtil { | |||||
} | } | ||||
return defalut; | 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); | |||||
} | |||||
} | |||||
} | } |
@@ -94,7 +94,7 @@ public class ParseWord07 { | |||||
addAnImage((WordImageEntity) obj, currentRun); | addAnImage((WordImageEntity) obj, currentRun); | ||||
} else { | } else { | ||||
currentText = obj.toString(); | currentText = obj.toString(); | ||||
currentRun.setText(currentText, 0); | |||||
PoiPublicUtil.setWordText(currentRun, currentText); | |||||
} | } | ||||
for (int k = 0; k < runIndex.size(); k++) { | for (int k = 0; k < runIndex.size(); k++) { | ||||
paragraph.getRuns().get(runIndex.get(k)).setText("", 0); | paragraph.getRuns().get(runIndex.get(k)).setText("", 0); | ||||
@@ -183,8 +183,9 @@ public class ExcelEntityParse extends ExportBase { | |||||
private void setCellValue(XWPFTableRow row, Object value, int cellNum) { | private void setCellValue(XWPFTableRow row, Object value, int cellNum) { | ||||
if (row.getCell(cellNum++) != null) { | if (row.getCell(cellNum++) != null) { | ||||
row.getCell(cellNum - 1).setText(value == null ? "" : value.toString()); | row.getCell(cellNum - 1).setText(value == null ? "" : value.toString()); | ||||
PoiPublicUtil.setWordText(row.createCell().addParagraph().createRun(),value == null ? "" : value.toString()); | |||||
} else { | } else { | ||||
row.createCell().setText(value == null ? "" : value.toString()); | |||||
PoiPublicUtil.setWordText(row.createCell().addParagraph().createRun(),value == null ? "" : value.toString()); | |||||
} | } | ||||
} | } | ||||
@@ -20,9 +20,11 @@ import static org.jeecgframework.poi.util.PoiElUtil.*; | |||||
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
import org.apache.poi.xwpf.usermodel.XWPFParagraph; | |||||
import org.apache.poi.xwpf.usermodel.XWPFTable; | import org.apache.poi.xwpf.usermodel.XWPFTable; | ||||
import org.apache.poi.xwpf.usermodel.XWPFTableCell; | import org.apache.poi.xwpf.usermodel.XWPFTableCell; | ||||
import org.apache.poi.xwpf.usermodel.XWPFTableRow; | import org.apache.poi.xwpf.usermodel.XWPFTableRow; | ||||
import org.jeecgframework.poi.util.PoiPublicUtil; | |||||
import com.google.common.collect.Maps; | import com.google.common.collect.Maps; | ||||
@@ -79,12 +81,13 @@ public final class ExcelMapParse { | |||||
tempMap.put("t", obj); | tempMap.put("t", obj); | ||||
for (cellIndex = 0; cellIndex < currentRow.getTableCells().size(); cellIndex++) { | for (cellIndex = 0; cellIndex < currentRow.getTableCells().size(); cellIndex++) { | ||||
String val = eval(params[cellIndex], tempMap).toString(); | 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++) { | for (; cellIndex < params.length; cellIndex++) { | ||||
String val = eval(params[cellIndex], tempMap).toString(); | String val = eval(params[cellIndex], tempMap).toString(); | ||||
currentRow.createCell().setText(val); | |||||
PoiPublicUtil.setWordText(currentRow.createCell().addParagraph().createRun(),val); | |||||
} | } | ||||
} | } | ||||