月报整合导出--word固定长度

This commit is contained in:
zhn
2022-09-07 18:55:54 +08:00
parent c6dabec4dc
commit 8a93dffd5c
2 changed files with 93 additions and 55 deletions
@@ -494,7 +494,7 @@ public class LawsMonthlyReportWriteEOServiceImpl extends ServiceImpl<LawsMonthly
os.close(); os.close();
fis.close(); fis.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
}finally { }finally {
IOUtils.closeQuietly(os); IOUtils.closeQuietly(os);
File file = new File(uploadpath + "/tempZip"+l); File file = new File(uploadpath + "/tempZip"+l);
@@ -28,17 +28,22 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFldChar;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPageMar; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPageMar;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSectPr; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSectPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblLayoutType;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblPr; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STFldCharType; import org.openxmlformats.schemas.wordprocessingml.x2006.main.STFldCharType;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc; import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblLayoutType;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth; import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
import java.io.InputStream; import java.io.InputStream;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class WordUtil { public class WordUtil {
@@ -410,11 +415,12 @@ public class WordUtil {
String stateName = dictItem(sysDictItems, state,cut, DictCodeReportEnum.STATE.getValue()); String stateName = dictItem(sysDictItems, state,cut, DictCodeReportEnum.STATE.getValue());
String useMethodName = dictItem(sysDictItems, useMethod,cut, DictCodeReportEnum.USEMETHOD.getValue()); String useMethodName = dictItem(sysDictItems, useMethod,cut, DictCodeReportEnum.USEMETHOD.getValue());
XWPFTable table = document.createTable(12, 2); XWPFTable table = document.createTable(12, 2);
//表格属性 //表格属性
CTTblPr tablePr = table.getCTTbl().addNewTblPr(); CTTblPr tablePr = table.getCTTbl().addNewTblPr();
//固定列宽(英文和数字的时候自动换行)
CTTblLayoutType ctTblLayoutType = tablePr.isSetTblLayout() ? tablePr.getTblLayout() : tablePr.addNewTblLayout();
ctTblLayoutType.setType(STTblLayoutType.FIXED);
//表格宽度 //表格宽度
CTJc cTJc = tablePr.addNewJc(); CTJc cTJc = tablePr.addNewJc();
//居中 //居中
@@ -478,57 +484,62 @@ public class WordUtil {
//第12行 //第12行
setCell(table, 11,"Link",link); setCell(table, 11,"Link",link);
} }
// if(CutEnum.CN.getValue().equals(cut)){ // ctTblLayoutType.setType(STTblLayoutType.FIXED);
// //第1行
// setCell(table.getRow(0), "相关领域",technologyTerritoryName); }
// //第2行
// setCell(table.getRow(1), "适用车型",applyCarName); /**
// //第3行 * 已固定长度分隔字符串
// setCell(table.getRow(2), "适用范围",applyScopeName); * @param str
// //第4行 * @return
// setCell(table.getRow(3), "状态",stateName); */
// //第5行 public List<String> splitStr(String str){
// setCell(table.getRow(4), "用法",useMethodName); //检查参数是否合法
// //第6行 if (null == str || str.equals("")) {
// setCell(table.getRow(5), "实施车型",implementCar); return new ArrayList<>();
// //第7行 }
// setCell(table.getRow(6), "新车型实施日期",newCarImplementTime); int length = 3;
// //第8行 int n = (str.length() + length - 1) / length; //获取整个字符串可以被切割成字符子串的个数
// setCell(table.getRow(7), "在产车实施日期",productionCarImplementTime); List<String> list = new ArrayList<>();
// //第9行 for (int i = 0; i < n; i++) {
// setCell(table.getRow(8), "主要内容",contentCn); if (i < (n - 1)) {
// //第10行 list.add(str.substring(i * length, (i + 1) * length)) ;
// setCell(table.getRow(9), "NIO工作进展",workProgressCn); } else {
// //第11行 list.add(str.substring(i * length));
// setCell(table.getRow(10), "法规联系人",lawsContact); }
// //第12行 }
// setCell(table.getRow(11), "链接",link); return list;
// }else{ }
// //第1行
// setCell(table.getRow(0), "Related Areas",technologyTerritoryName); /**
// //第2行 * 判断字符串是否完全由数字组成
// setCell(table.getRow(1), "Vehicle Type",applyCarName); * @param str
// //第3行 * @return
// setCell(table.getRow(2), "Scope",applyScopeName); */
// //第4行 public boolean verifyFigure(String str){
// setCell(table.getRow(3), "Status",stateName); Pattern p = Pattern.compile("[0-9]*");
// //第5行 Matcher m = p.matcher(str);
// setCell(table.getRow(4), "usage",useMethodName); return m.matches();
// //第6行 }
// setCell(table.getRow(5), "Implementation Model",implementCar); /**
// //第7行 * 判断字符串是否完全由字母组成
// setCell(table.getRow(6), "New Type Execution Date",newCarImplementTime); * @param str
// //第8行 * @return
// setCell(table.getRow(7), "New Vehicle Execution Date",productionCarImplementTime); */
// //第9行 public boolean verifyEn(String str){
// setCell(table.getRow(8), "Main Content",contentEn); Pattern enPatten = Pattern.compile("^[a-zA-Z]*");
// //第10行 Matcher enMatch = enPatten.matcher(str);
// setCell(table.getRow(9), "NIO Work Progress",workProgressEn); return enMatch.matches();
// //第11行 }
// setCell(table.getRow(10), "Regulatory Contact",lawsContact); /**
// //第12行 * 判断字符串是否完全由数字和字母组成
// setCell(table.getRow(11), "Link",link); * @param str
// } * @return
*/
public boolean verifyFigureAndEn(String str){
Pattern figureAndEnPattern = Pattern.compile("[0-9a-zA-Z]{1,}");
Matcher figureAndEnMatcher = figureAndEnPattern.matcher(str);
return figureAndEnMatcher.matches();
} }
/** /**
@@ -553,6 +564,9 @@ public class WordUtil {
//表格属性 //表格属性
CTTblPr tablePr = table.getCTTbl().addNewTblPr(); CTTblPr tablePr = table.getCTTbl().addNewTblPr();
//固定列宽(英文和数字的时候自动换行)
CTTblLayoutType ctTblLayoutType = tablePr.isSetTblLayout() ? tablePr.getTblLayout() : tablePr.addNewTblLayout();
ctTblLayoutType.setType(STTblLayoutType.FIXED);
//表格宽度 //表格宽度
CTJc cTJc = tablePr.addNewJc(); CTJc cTJc = tablePr.addNewJc();
//居中 //居中
@@ -597,6 +611,9 @@ public class WordUtil {
XWPFTable table = document.createTable(newOpinionTemplateEOList.size()+1, 4); XWPFTable table = document.createTable(newOpinionTemplateEOList.size()+1, 4);
//表格属性 //表格属性
CTTblPr tablePr = table.getCTTbl().addNewTblPr(); CTTblPr tablePr = table.getCTTbl().addNewTblPr();
//固定列宽(英文和数字的时候自动换行)
CTTblLayoutType ctTblLayoutType = tablePr.isSetTblLayout() ? tablePr.getTblLayout() : tablePr.addNewTblLayout();
ctTblLayoutType.setType(STTblLayoutType.FIXED);
//表格宽度 //表格宽度
CTJc cTJc = tablePr.addNewJc(); CTJc cTJc = tablePr.addNewJc();
//居中 //居中
@@ -632,6 +649,9 @@ public class WordUtil {
XWPFTable table = document.createTable(newStandardTemplateEOList.size()+1, 5); XWPFTable table = document.createTable(newStandardTemplateEOList.size()+1, 5);
//表格属性 //表格属性
CTTblPr tablePr = table.getCTTbl().addNewTblPr(); CTTblPr tablePr = table.getCTTbl().addNewTblPr();
//固定列宽(英文和数字的时候自动换行)
CTTblLayoutType ctTblLayoutType = tablePr.isSetTblLayout() ? tablePr.getTblLayout() : tablePr.addNewTblLayout();
ctTblLayoutType.setType(STTblLayoutType.FIXED);
//表格宽度 //表格宽度
CTJc cTJc = tablePr.addNewJc(); CTJc cTJc = tablePr.addNewJc();
//居中 //居中
@@ -809,11 +829,29 @@ public class WordUtil {
ctTblWidth0.setW(BigInteger.valueOf(2000)); ctTblWidth0.setW(BigInteger.valueOf(2000));
CTTblWidth ctTblWidth1 = table.getRow(number).getCell(1).getCTTc().addNewTcPr().addNewTcW(); CTTblWidth ctTblWidth1 = table.getRow(number).getCell(1).getCTTc().addNewTcPr().addNewTcW();
ctTblWidth1.setType(STTblWidth.DXA); ctTblWidth1.setType(STTblWidth.DXA);
ctTblWidth1.setW(BigInteger.valueOf(5000)); ctTblWidth1.setW(BigInteger.valueOf(6000));
// XWPFParagraph para = table.getRow(number).getCell(1).getParagraphs().get(0);
// XWPFRun run = para.createRun();//对某个段落设置格式
// run.addBreak();//换行
table.getRow(number).getCell(0).setText(fieldName); table.getRow(number).getCell(0).setText(fieldName);
table.getRow(number).getCell(1).setText(technologyTerritory); table.getRow(number).getCell(1).setText(technologyTerritory);
} }
// private static void setCell(XWPFTable table, int number, String fieldName,String technologyTerritory) {
//
// table.getRow(number).setHeight(500);
// CTTblWidth ctTblWidth0 = table.getRow(number).getCell(0).getCTTc().addNewTcPr().addNewTcW();
// ctTblWidth0.setType(STTblWidth.DXA);
// ctTblWidth0.setW(BigInteger.valueOf(2000));
// CTTblWidth ctTblWidth1 = table.getRow(number).getCell(1).getCTTc().addNewTcPr().addNewTcW();
// ctTblWidth1.setType(STTblWidth.DXA);
// ctTblWidth1.setW(BigInteger.valueOf(5000));
//
// table.getRow(number).getCell(0).setText(fieldName);
// table.getRow(number).getCell(1).setText(technologyTerritory);
// }
// private static void setCell(XWPFTableRow tableRow, String fieldName,String technologyTerritory) { // private static void setCell(XWPFTableRow tableRow, String fieldName,String technologyTerritory) {
// //
// tableRow.setHeight(500); // tableRow.setHeight(500);