@@ -44,18 +44,18 @@ public class WordUtil {
/**
* 导出工具示例
*
* @param document POI文件类
* @param text 输出文本
* @param textColor 字体颜色
* @param align 字体位置,默认居左
* @param spaceNum 预留空格数,默认不留空格
* @param fontSize 字体大小,默认11
* @param isNewline 是否换行,换行后文本失效
* @param isBold 是否加粗,默认不加粗
* @param fontFamily 字体,默认宋体
* @param document POI文件类
* @param text 输出文本
* @param textColor 字体颜色
* @param align 字体位置,默认居左
* @param spaceNum 预留空格数,默认不留空格
* @param fontSize 字体大小,默认11
* @param isNewline 是否换行,换行后文本失效
* @param isBold 是否加粗,默认不加粗
* @param fontFamily 字体,默认宋体
* @param directoryLevel 目录级别
* @param styleName 标题样式
* @param flag 封面标识(不做行间距处理)
* @param styleName 标题样式
* @param flag 封面标识(不做行间距处理)
*/
public static void exportWord ( XWPFDocument document ,
String text ,
@@ -71,8 +71,8 @@ public class WordUtil {
String flag ) {
//设置标题级别
if ( StringUtils . isNotEmpty ( directoryLevel ) ) {
addCustomHeadingStyle ( document , styleName , Integer . parseInt ( directoryLevel ) ) ;
if ( StringUtils . isNotEmpty ( directoryLevel ) ) {
addCustomHeadingStyle ( document , styleName , Integer . parseInt ( directoryLevel ) ) ;
}
XWPFParagraph titleParagraph = document . createParagraph ( ) ;
@@ -80,10 +80,10 @@ public class WordUtil {
//设置行间距
if ( ! " cover " . equals ( flag ) & & ! " oneTitle " . equals ( flag ) ) {
if ( ! " cover " . equals ( flag ) & & ! " oneTitle " . equals ( flag ) ) {
CTP ctp = titleParagraph . getCTP ( ) ;
CTPPr ppr = ctp . isSetPPr ( ) ? ctp . getPPr ( ) : ctp . addNewPPr ( ) ;
CTSpacing spacing = ppr . isSetSpacing ( ) ? ppr . getSpacing ( ) : ppr . addNewSpacing ( ) ;
CTSpacing spacing = ppr . isSetSpacing ( ) ? ppr . getSpacing ( ) : ppr . addNewSpacing ( ) ;
spacing . setAfter ( BigInteger . valueOf ( 120 ) ) ; //行间距后段为6磅
spacing . setBefore ( BigInteger . valueOf ( 300 ) ) ; //行间距前段为15磅, 300是通过单位换算来的
// //设置行距类型为 EXACT
@@ -101,7 +101,7 @@ public class WordUtil {
XWPFRun titleParagraphRun = titleParagraph . createRun ( ) ;
//封面中的换行
if ( " break " . equals ( flag ) ) {
if ( " break " . equals ( flag ) ) {
titleParagraphRun . addBreak ( ) ;
}
if ( isNewline ) {
@@ -180,7 +180,7 @@ public class WordUtil {
//主要内容生成页眉页脚(office版本)
@SneakyThrows
public static void exportHeardAndFoot ( XWPFDocument document , String month , String cut ) {
public static void exportHeardAndFoot ( XWPFDocument document , String month , String cut ) {
XWPFHeaderFooterPolicy headerFooterPolicy = document . getHeaderFooterPolicy ( ) ;
if ( headerFooterPolicy = = null ) headerFooterPolicy = document . createHeaderFooterPolicy ( ) ;
XWPFHeader header = headerFooterPolicy . createHeader ( XWPFHeaderFooterPolicy . DEFAULT ) ;
@@ -198,18 +198,18 @@ public class WordUtil {
// InputStream is = new FileInputStream(imgFile);
XWPFPicture picture = run . addPicture ( is , XWPFDocument . PICTURE_TYPE_PNG , imgFile , Units . toEMU ( 95 ) , Units . toEMU ( 35 ) ) ;
String blipID = " " ;
for ( XWPFPictureData picturedata : header . getAllPackagePictures ( ) ) { //这段必须有,不然打开的logo图片不显示
for ( XWPFPictureData picturedata : header . getAllPackagePictures ( ) ) { //这段必须有,不然打开的logo图片不显示
blipID = header . getRelationId ( picturedata ) ;
}
picture . getCTPicture ( ) . getBlipFill ( ) . getBlip ( ) . setEmbed ( blipID ) ;
run . addTab ( ) ;
is . close ( ) ;
if ( CutEnum . CN . getValue ( ) . equals ( cut ) ) {
run . setText ( " " + month + " (总第 期) " ) ;
} else {
if ( CutEnum . CN . getValue ( ) . equals ( cut ) ) {
run . setText ( " " + month + " (总第 期) " ) ;
} else {
String replace = month . replace ( " 年 " , " " ) . replace ( " 月 " , " " ) ;
String monthTemp = replace . split ( " " ) [ 1 ] + " / " + replace . split ( " " ) [ 0 ] ;
run . setText ( " " + monthTemp + " (Issue No. ) " ) ;
String monthTemp = replace . split ( " " ) [ 1 ] + " / " + replace . split ( " " ) [ 0 ] ;
run . setText ( " " + monthTemp + " (Issue No. ) " ) ;
}
run . setFontSize ( 11 ) ;
@@ -255,7 +255,6 @@ public class WordUtil {
//----------------------------------------------------------------------------
CTSectPr sectPr = document . getDocument ( ) . getBody ( ) . getSectPr ( ) ;
if ( sectPr = = null ) sectPr = document . getDocument ( ) . getBody ( ) . addNewSectPr ( ) ;
//设置页面大小(21*29.7)
@@ -362,11 +361,12 @@ public class WordUtil {
/**
* 主页面(只有页脚)
*
* @param document
* @param month
*/
@SneakyThrows
public static void exportHeardAndFootMain ( XWPFDocument document , String month ) {
public static void exportHeardAndFootMain ( XWPFDocument document , String month ) {
XWPFHeaderFooterPolicy headerFooterPolicy = document . getHeaderFooterPolicy ( ) ;
if ( headerFooterPolicy = = null ) headerFooterPolicy = document . createHeaderFooterPolicy ( ) ;
// XWPFHeader header = headerFooterPolicy.createHeader(XWPFHeaderFooterPolicy.DEFAULT);
@@ -455,14 +455,14 @@ public class WordUtil {
* @param fontFamily 字体,默认宋体
*/
public static void exportWordMonth ( XWPFDocument document ,
String text ,
String textColor ,
ParagraphAlignment align ,
Integer spaceNum ,
Integer fontSize ,
Boolean isNewline ,
Boolean isBold ,
String fontFamily ) {
String text ,
String textColor ,
ParagraphAlignment align ,
Integer spaceNum ,
Integer fontSize ,
Boolean isNewline ,
Boolean isBold ,
String fontFamily ) {
//添加标题
XWPFParagraph titleParagraph = document . createParagraph ( ) ;
@@ -522,6 +522,8 @@ public class WordUtil {
String cut ,
List < LoginUser > loginUserList ) {
String technologyTerritory = lawsMonthlyReportWriteEO . getTechnologyTerritory ( ) ; //技术领域
String technologyTerritoryCn = lawsMonthlyReportWriteEO . getTechnologyTerritoryCn ( ) ; //技术领域补充中文
String technologyTerritoryEn = lawsMonthlyReportWriteEO . getTechnologyTerritoryEn ( ) ; //技术领域补充英文
String applyCar = lawsMonthlyReportWriteEO . getApplyCar ( ) ; //适用车型
String applyScope = lawsMonthlyReportWriteEO . getApplyScope ( ) ; //适用范围
String state = lawsMonthlyReportWriteEO . getState ( ) ; //状态
@@ -557,7 +559,7 @@ public class WordUtil {
String link = lawsMonthlyReportWriteEO . getLink ( ) ; //链接
String technologyTerritoryName = " " ;
if ( org . apache . commons . lang3 . StringUtils . isNotBlank ( technologyTerritory ) ) {
if ( org . apache . commons . lang3 . StringUtils . isNotBlank ( technologyTerritory ) ) {
List < String > technologyTerritoryList = Arrays . asList ( technologyTerritory . split ( " , " ) ) ;
StringBuilder sb = new StringBuilder ( ) ;
for ( String technologyTerritoryTemp : technologyTerritoryList ) {
@@ -566,16 +568,27 @@ public class WordUtil {
sb . append ( collect . get ( 0 ) . getName ( ) + " , " ) ;
}
}
//拼接技术领域补充内容
if ( cut . equals ( " cn " ) ) {
if ( StringUtils . isNotBlank ( technologyTerritoryCn ) ) {
sb . append ( " 补充: " + technologyTerritoryCn ) ;
}
} else {
if ( StringUtils . isNotBlank ( technologyTerritoryEn ) ) {
sb . append ( " replenish: " + technologyTerritoryEn ) ;
}
}
if ( org . apache . commons . lang3 . StringUtils . isNotBlank ( sb ) ) {
technologyTerritoryName = sb . substring ( 0 , sb . length ( ) - 1 ) ;
technologyTerritoryName = sb . substring ( 0 , sb . length ( ) ) ;
}
}
//适用车型中文名
String applyCarName = dictItem ( sysDictItems , applyCar , cut , DictCodeReportEnum . APPLYCAR . getValue ( ) ) ;
String applyScopeName = dictItem ( sysDictItems , applyScope , cut , DictCodeReportEnum . APPLYSCOPE . getValue ( ) ) ;
String stateName = dictItem ( sysDictItems , state , cut , DictCodeReportEnum . STATE_REPORT . getValue ( ) ) ;
String useMethodName = dictItem ( sysDictItems , useMethod , cut , DictCodeReportEnum . USEMETHOD . getValue ( ) ) ;
if ( useMethodName . equals ( " 安装即符合 " ) ) {
String applyCarName = dictItem ( sysDictItems , applyCar , cut , DictCodeReportEnum . APPLYCAR . getValue ( ) ) ;
String applyScopeName = dictItem ( sysDictItems , applyScope , cut , DictCodeReportEnum . APPLYSCOPE . getValue ( ) ) ;
String stateName = dictItem ( sysDictItems , state , cut , DictCodeReportEnum . STATE_REPORT . getValue ( ) ) ;
String useMethodName = dictItem ( sysDictItems , useMethod , cut , DictCodeReportEnum . USEMETHOD . getValue ( ) ) ;
if ( useMethodName . equals ( " 安装即符合 " ) ) {
useMethodName = " 安装需符合 " ;
}
XWPFTable table = document . createTable ( 10 , 2 ) ;
@@ -596,56 +609,56 @@ public class WordUtil {
//第1行
if ( CutEnum . CN . getValue ( ) . equals ( cut ) ) {
if ( CutEnum . CN . getValue ( ) . equals ( cut ) ) {
//第1行
setCell ( table , 0 , " 相关领域 " , technologyTerritoryName ) ;
setCell ( table , 0 , " 相关领域 " , technologyTerritoryName ) ;
//第2行
// setCell(table,1, "适用车型",applyCarName);
//第3行
setCellThree ( table , 1 , " 适用范围 " , applyScopeName , sysDictItems , DictCodeReportEnum . APPLYSCOPE . getValue ( ) ) ;
setCellThree ( table , 1 , " 适用范围 " , applyScopeName , sysDictItems , DictCodeReportEnum . APPLYSCOPE . getValue ( ) ) ;
//第4行
setCellThree ( table , 2 , " 状态 " , stateName , sysDictItems , DictCodeReportEnum . STATE . getValue ( ) ) ;
setCellThree ( table , 2 , " 状态 " , stateName , sysDictItems , DictCodeReportEnum . STATE . getValue ( ) ) ;
//第5行
setCellThree ( table , 3 , " 用法 " , useMethodName , sysDictItems , DictCodeReportEnum . USEMETHOD . getValue ( ) ) ;
setCellThree ( table , 3 , " 用法 " , useMethodName , sysDictItems , DictCodeReportEnum . USEMETHOD . getValue ( ) ) ;
//第6行
// setCell(table,4, "实施车型",implementCar);
//第7行
setCell ( table , 4 , " 发布日期 " , newCarImplementTime ) ;
setCell ( table , 4 , " 发布日期 " , newCarImplementTime ) ;
//第8行
setCell ( table , 5 , " 实施日期 " , productionCarImplementTime ) ;
setCell ( table , 5 , " 实施日期 " , productionCarImplementTime ) ;
//第9行
setCell ( table , 6 , " 主要内容 " , contentCn ) ;
setCell ( table , 6 , " 主要内容 " , contentCn ) ;
//第10行
setCell ( table , 7 , " NIO工作进展 " , workProgressCn ) ;
setCell ( table , 7 , " NIO工作进展 " , workProgressCn ) ;
//第11行
setCell ( table , 8 , " 法规联系人 " , lawsContact ) ;
setCell ( table , 8 , " 法规联系人 " , lawsContact ) ;
//第12行
setCell ( table , 9 , " 链接 " , link ) ;
} else {
setCell ( table , 9 , " 链接 " , link ) ;
} else {
//第1行
setCell ( table , 0 , " Related Areas " , technologyTerritoryName ) ;
setCell ( table , 0 , " Relevant Area " , technologyTerritoryName ) ;
//第2行
// setCell(table,1,"Vehicle Type",applyCarName);
//第3行
setCellThree ( table , 1 , " Scope " , applyScopeName , sysDictItems , DictCodeReportEnum . APPLYSCOPE . getValue ( ) ) ;
setCellThree ( table , 1 , " Scope " , applyScopeName , sysDictItems , DictCodeReportEnum . APPLYSCOPE . getValue ( ) ) ;
//第4行
setCellThree ( table , 2 , " Status " , stateName , sysDictItems , DictCodeReportEnum . APPLYSCOPE . getValue ( ) ) ;
setCellThree ( table , 2 , " Status " , stateName , sysDictItems , DictCodeReportEnum . APPLYSCOPE . getValue ( ) ) ;
//第5行
setCellThree ( table , 3 , " Usage " , useMethodName , sysDictItems , DictCodeReportEnum . APPLYSCOPE . getValue ( ) ) ;
setCellThree ( table , 3 , " Usage " , useMethodName , sysDictItems , DictCodeReportEnum . APPLYSCOPE . getValue ( ) ) ;
//第6行
// setCell(table,4,"Implementation Model",implementCar);
//第7行
setCell ( table , 4 , " Release Date " , newCarImplementTime ) ;
setCell ( table , 4 , " Release Date " , newCarImplementTime ) ;
//第8行
setCell ( table , 5 , " Ex ecu tion Date " , productionCarImplementTime ) ;
setCell ( table , 5 , " Eff ective Date " , productionCarImplementTime ) ;
//第9行
setCell ( table , 6 , " Main Content " , contentEn ) ;
setCell ( table , 6 , " Description " , contentEn ) ;
//第10行
setCell ( table , 7 , " NIO Work Progress " , workProgressEn ) ;
setCell ( table , 7 , " NIO Work Progress " , workProgressEn ) ;
//第11行
setCell ( table , 8 , " Regulatory Contact " , lawsContact ) ;
setCell ( table , 8 , " Reg. Contact " , lawsContact ) ;
//第12行
setCell ( table , 9 , " Link " , link ) ;
setCell ( table , 9 , " Link " , link ) ;
}
// ctTblLayoutType.setType(STTblLayoutType.FIXED);
@@ -653,10 +666,11 @@ public class WordUtil {
/**
* 已固定长度分隔字符串
*
* @param str
* @return
*/
public List < String > splitStr ( String str ) {
public List < String > splitStr ( String str ) {
//检查参数是否合法
if ( null = = str | | str . equals ( " " ) ) {
return new ArrayList < > ( ) ;
@@ -666,7 +680,7 @@ public class WordUtil {
List < String > list = new ArrayList < > ( ) ;
for ( int i = 0 ; i < n ; i + + ) {
if ( i < ( n - 1 ) ) {
list . add ( str . substring ( i * length , ( i + 1 ) * length ) ) ;
list . add ( str . substring ( i * length , ( i + 1 ) * length ) ) ;
} else {
list . add ( str . substring ( i * length ) ) ;
}
@@ -676,30 +690,35 @@ public class WordUtil {
/**
* 判断字符串是否完全由数字组成
*
* @param str
* @return
*/
public boolean verifyFigure ( String str ) {
public boolean verifyFigure ( String str ) {
Pattern p = Pattern . compile ( " [0-9]* " ) ;
Matcher m = p . matcher ( str ) ;
return m . matches ( ) ;
}
/**
* 判断字符串是否完全由字母组成
*
* @param str
* @return
*/
public boolean verifyEn ( String str ) {
public boolean verifyEn ( String str ) {
Pattern enPatten = Pattern . compile ( " ^[a-zA-Z]* " ) ;
Matcher enMatch = enPatten . matcher ( str ) ;
return enMatch . matches ( ) ;
}
/**
* 判断字符串是否完全由数字和字母组成
*
* @param str
* @return
*/
public boolean verifyFigureAndEn ( String str ) {
public boolean verifyFigureAndEn ( String str ) {
Pattern figureAndEnPattern = Pattern . compile ( " [0-9a-zA-Z]{1,} " ) ;
Matcher figureAndEnMatcher = figureAndEnPattern . matcher ( str ) ;
return figureAndEnMatcher . matches ( ) ;
@@ -707,13 +726,14 @@ public class WordUtil {
/**
* 行业资讯动态
*
* @param document
* @param lawsMonthlyReportWriteEO
* @param cut
*/
public static void exportWordExcelIndustry ( XWPFDocument document ,
LawsMonthlyReportWriteEO lawsMonthlyReportWriteEO ,
String cut ) {
LawsMonthlyReportWriteEO lawsMonthlyReportWriteEO ,
String cut ) {
String relatedAreasCn = lawsMonthlyReportWriteEO . getRelatedAreasCn ( ) ; //相关领域中文
String relatedAreasEn = lawsMonthlyReportWriteEO . getRelatedAreasEn ( ) ; //相关领域英文
String sourceCn = lawsMonthlyReportWriteEO . getSourceCn ( ) ; //来源
@@ -742,36 +762,37 @@ public class WordUtil {
//第1行
if ( CutEnum . CN . getValue ( ) . equals ( cut ) ) {
if ( CutEnum . CN . getValue ( ) . equals ( cut ) ) {
//第1行
setCell ( table , 0 , " 相关领域 " , relatedAreasCn ) ;
setCell ( table , 0 , " 相关领域 " , relatedAreasCn ) ;
//第2行
setCell ( table , 1 , " 来源 " , sourceCn ) ;
setCell ( table , 1 , " 来源 " , sourceCn ) ;
//第3行
setCell ( table , 2 , " 日期 " , time ) ;
setCell ( table , 2 , " 日期 " , time ) ;
//第4行
setCell ( table , 3 , " 主要内容 " , contentCn ) ;
setCell ( table , 3 , " 主要内容 " , contentCn ) ;
//第5行
setCell ( table , 4 , " 链接 " , link ) ;
} else {
setCell ( table , 4 , " 链接 " , link ) ;
} else {
//第1行
setCell ( table , 0 , " Related Areas " , relatedAreasEn ) ;
setCell ( table , 0 , " Relevant Area " , relatedAreasEn ) ;
//第2行
setCell ( table , 1 , " Source " , sourceEn ) ;
setCell ( table , 1 , " Source " , sourceEn ) ;
//第3行
setCell ( table , 2 , " Date " , time ) ;
setCell ( table , 2 , " Date " , time ) ;
//第4行
setCell ( table , 3 , " Main Content " , contentEn ) ;
setCell ( table , 3 , " Description " , contentEn ) ;
//第5行
setCell ( table , 4 , " Link " , link ) ;
setCell ( table , 4 , " Link " , link ) ;
}
}
public static void exportWordExcelAsk ( XWPFDocument document ,
LawsMonthlyReportWriteEO lawsMonthlyReportWriteEO ,
String cut ) {
LawsMonthlyReportWriteEO lawsMonthlyReportWriteEO ,
String cut ) {
List < NewOpinionTemplateEO > newOpinionTemplateEOList = lawsMonthlyReportWriteEO . getNewOpinionTemplateEOList ( ) ;
if ( ObjectUtils . isNotEmpty ( newOpinionTemplateEOList ) ) {
XWPFTable table = document . createTable ( newOpinionTemplateEOList . size ( ) + 1 , 4 ) ;
if ( ObjectUtils . isNotEmpty ( newOpinionTemplateEOList ) ) {
XWPFTable table = document . createTable ( newOpinionTemplateEOList . size ( ) + 1 , 4 ) ;
//表格属性
CTTblPr tablePr = table . getCTTbl ( ) . addNewTblPr ( ) ;
//固定列宽(英文和数字的时候自动换行)
@@ -786,30 +807,31 @@ public class WordUtil {
//设置表格宽度
tableWidth . setType ( STTblWidth . DXA ) ;
tableWidth . setW ( BigInteger . valueOf ( 8311 ) ) ;
if ( CutEnum . CN . getValue ( ) . equals ( cut ) ) {
setCellAskOne ( table , " 序号 " , " 计划号 " , " 标准名称 " , " 征求意见截止日期 " ) ;
} else {
setCellAskOne ( table , " Number " , " Plan Number " , " Standard Name " , " Deadline For Comments " ) ;
if ( CutEnum . CN . getValue ( ) . equals ( cut ) ) {
setCellAskOne ( table , " 序号 " , " 计划号 " , " 标准名称 " , " 征求意见截止日期 " ) ;
} else {
setCellAskOne ( table , " Number " , " Plan Number " , " Standard Name " , " Deadline For Comments " ) ;
}
for ( int i = 0 ; i < newOpinionTemplateEOList . size ( ) ; i + + ) {
String planNumberCn = newOpinionTemplateEOList . get ( i ) . getPlanNumberCn ( ) ; //计划号
String standardNameCn = newOpinionTemplateEOList . get ( i ) . getStandardNameCn ( ) ; //标准名称中文
String standardNameEn = newOpinionTemplateEOList . get ( i ) . getStandardNameEn ( ) ; //标准名称英文
String expirationDate = newOpinionTemplateEOList . get ( i ) . getExpirationDate ( ) ; //征求意见截止日期
if ( CutEnum . CN . getValue ( ) . equals ( cut ) ) {
setCellAsk ( table , i + 1 , planNumberCn , standardNameCn , expirationDate ) ;
} else {
setCellAsk ( table , i + 1 , planNumberCn , standardNameEn , expirationDate ) ;
if ( CutEnum . CN . getValue ( ) . equals ( cut ) ) {
setCellAsk ( table , i + 1 , planNumberCn , standardNameCn , expirationDate ) ;
} else {
setCellAsk ( table , i + 1 , planNumberCn , standardNameEn , expirationDate ) ;
}
}
}
}
public static void exportWordExcelIssue ( XWPFDocument document ,
LawsMonthlyReportWriteEO lawsMonthlyReportWriteEO ,
String cut ) {
LawsMonthlyReportWriteEO lawsMonthlyReportWriteEO ,
String cut ) {
List < NewStandardTemplateEO > newStandardTemplateEOList = lawsMonthlyReportWriteEO . getNewStandardTemplateEOList ( ) ;
if ( ObjectUtils . isNotEmpty ( newStandardTemplateEOList ) ) {
XWPFTable table = document . createTable ( newStandardTemplateEOList . size ( ) + 1 , 5 ) ;
if ( ObjectUtils . isNotEmpty ( newStandardTemplateEOList ) ) {
XWPFTable table = document . createTable ( newStandardTemplateEOList . size ( ) + 1 , 5 ) ;
//表格属性
CTTblPr tablePr = table . getCTTbl ( ) . addNewTblPr ( ) ;
//固定列宽(英文和数字的时候自动换行)
@@ -824,21 +846,21 @@ public class WordUtil {
//设置表格宽度
tableWidth . setType ( STTblWidth . DXA ) ;
tableWidth . setW ( BigInteger . valueOf ( 8311 ) ) ;
if ( CutEnum . CN . getValue ( ) . equals ( cut ) ) {
setCellIssueOne ( table , " 序号 " , " 标准编号 " , " 标准名称 " , " 发布日期 " , " 实施日期 " ) ;
} else {
setCellIssueOne ( table , " Number " , " Standard Number " , " Standard Name " , " Release Date " , " Implementation date " ) ;
if ( CutEnum . CN . getValue ( ) . equals ( cut ) ) {
setCellIssueOne ( table , " 序号 " , " 标准编号 " , " 标准名称 " , " 发布日期 " , " 实施日期 " ) ;
} else {
setCellIssueOne ( table , " Number " , " Standard Number " , " Standard Name " , " Release Date " , " Implementation date " ) ;
}
for ( int i = 0 ; i < newStandardTemplateEOList . size ( ) ; i + + ) {
String standardNumber = newStandardTemplateEOList . get ( i ) . getStandardNumber ( ) ; //标准编号
String standardNumber = newStandardTemplateEOList . get ( i ) . getStandardNumber ( ) ; //标准编号
String standardNameCn = newStandardTemplateEOList . get ( i ) . getStandardNameCn ( ) ; //标准名称中文
String standardNameEn = newStandardTemplateEOList . get ( i ) . getStandardNameEn ( ) ; //标准名称英文
String issueTime = newStandardTemplateEOList . get ( i ) . getIssueTime ( ) ; //发布日期
String implementTime = newStandardTemplateEOList . get ( i ) . getImplementTime ( ) ; //实施日期
if ( CutEnum . CN . getValue ( ) . equals ( cut ) ) {
setCellIssue ( table , i + 1 , standardNumber , standardNameCn , issueTime , implementTime ) ;
} else {
setCellIssue ( table , i + 1 , standardNumber , standardNameEn , issueTime , implementTime ) ;
if ( CutEnum . CN . getValue ( ) . equals ( cut ) ) {
setCellIssue ( table , i + 1 , standardNumber , standardNameCn , issueTime , implementTime ) ;
} else {
setCellIssue ( table , i + 1 , standardNumber , standardNameEn , issueTime , implementTime ) ;
}
}
}
@@ -854,35 +876,36 @@ public class WordUtil {
ctTblWidth0 . setW ( BigInteger . valueOf ( 703 ) ) ;
//设置单元格边距
XWPFTableCell cell0 = table . getRow ( i ) . getCell ( 0 ) ;
cellPadding ( cell0 , String . valueOf ( i ) ) ;
cellPadding ( cell0 , String . valueOf ( i ) ) ;
CTTblWidth ctTblWidth1 = table . getRow ( i ) . getCell ( 1 ) . getCTTc ( ) . addNewTcPr ( ) . addNewTcW ( ) ;
ctTblWidth1 . setType ( STTblWidth . DXA ) ;
ctTblWidth1 . setW ( BigInteger . valueOf ( 1984 ) ) ;
//设置单元格边距
XWPFTableCell cell1 = table . getRow ( i ) . getCell ( 1 ) ;
cellPadding ( cell1 , planNumber ) ;
cellPadding ( cell1 , planNumber ) ;
CTTblWidth ctTblWidth2 = table . getRow ( i ) . getCell ( 2 ) . getCTTc ( ) . addNewTcPr ( ) . addNewTcW ( ) ;
ctTblWidth2 . setType ( STTblWidth . DXA ) ;
ctTblWidth2 . setW ( BigInteger . valueOf ( 3543 ) ) ;
//设置单元格边距
XWPFTableCell cell2 = table . getRow ( i ) . getCell ( 2 ) ;
cellPadding ( cell2 , standardName ) ;
cellPadding ( cell2 , standardName ) ;
CTTblWidth ctTblWidth3 = table . getRow ( i ) . getCell ( 3 ) . getCTTc ( ) . addNewTcPr ( ) . addNewTcW ( ) ;
ctTblWidth3 . setType ( STTblWidth . DXA ) ;
ctTblWidth3 . setW ( BigInteger . valueOf ( 2081 ) ) ;
//设置单元格边距
XWPFTableCell cell3 = table . getRow ( i ) . getCell ( 3 ) ;
cellPadding ( cell3 , expirationDate ) ;
cellPadding ( cell3 , expirationDate ) ;
// table.getRow(i).getCell(0).setText(String.valueOf(i));
// table.getRow(i).getCell(1).setText(planNumber);
// table.getRow(i).getCell(2).setText(standardName);
// table.getRow(i).getCell(3).setText(expirationDate);
}
private static void setCellIssue ( XWPFTable table , int i , String planNumber , String standardName , String expirationDate , String implementTime ) {
private static void setCellIssue ( XWPFTable table , int i , String planNumber , String standardName , String expirationDate , String implementTime ) {
//设置单元格高度
table . getRow ( i ) . setHeight ( 500 ) ;
@@ -892,35 +915,35 @@ public class WordUtil {
ctTblWidth0 . setW ( BigInteger . valueOf ( 708 ) ) ;
//设置单元格边距
XWPFTableCell cell0 = table . getRow ( i ) . getCell ( 0 ) ;
cellPadding ( cell0 , String . valueOf ( i ) ) ;
cellPadding ( cell0 , String . valueOf ( i ) ) ;
CTTblWidth ctTblWidth1 = table . getRow ( i ) . getCell ( 1 ) . getCTTc ( ) . addNewTcPr ( ) . addNewTcW ( ) ;
ctTblWidth1 . setType ( STTblWidth . DXA ) ;
ctTblWidth1 . setW ( BigInteger . valueOf ( 1990 ) ) ;
//设置单元格边距
XWPFTableCell cell1 = table . getRow ( i ) . getCell ( 1 ) ;
cellPadding ( cell1 , planNumber ) ;
cellPadding ( cell1 , planNumber ) ;
CTTblWidth ctTblWidth2 = table . getRow ( i ) . getCell ( 2 ) . getCTTc ( ) . addNewTcPr ( ) . addNewTcW ( ) ;
ctTblWidth2 . setType ( STTblWidth . DXA ) ;
ctTblWidth2 . setW ( BigInteger . valueOf ( 3124 ) ) ;
//设置单元格边距
XWPFTableCell cell2 = table . getRow ( i ) . getCell ( 2 ) ;
cellPadding ( cell2 , standardName ) ;
cellPadding ( cell2 , standardName ) ;
CTTblWidth ctTblWidth3 = table . getRow ( i ) . getCell ( 3 ) . getCTTc ( ) . addNewTcPr ( ) . addNewTcW ( ) ;
ctTblWidth3 . setType ( STTblWidth . DXA ) ;
ctTblWidth3 . setW ( BigInteger . valueOf ( 1247 ) ) ;
//设置单元格边距
XWPFTableCell cell3 = table . getRow ( i ) . getCell ( 3 ) ;
cellPadding ( cell3 , expirationDate ) ;
cellPadding ( cell3 , expirationDate ) ;
CTTblWidth ctTblWidth4 = table . getRow ( i ) . getCell ( 4 ) . getCTTc ( ) . addNewTcPr ( ) . addNewTcW ( ) ;
ctTblWidth4 . setType ( STTblWidth . DXA ) ;
ctTblWidth4 . setW ( BigInteger . valueOf ( 1247 ) ) ;
//设置单元格边距
XWPFTableCell cell4 = table . getRow ( i ) . getCell ( 4 ) ;
cellPadding ( cell4 , implementTime ) ;
cellPadding ( cell4 , implementTime ) ;
// table.getRow(i).getCell(0).setText(String.valueOf(i));
// table.getRow(i).getCell(1).setText(planNumber);
@@ -928,7 +951,8 @@ public class WordUtil {
// table.getRow(i).getCell(3).setText(expirationDate);
// table.getRow(i).getCell(4).setText(implementTime);
}
private static void setCellIssueOne ( XWPFTable table , String number , String planNumber , String standardName , String expirationDate , String implementTime ) {
private static void setCellIssueOne ( XWPFTable table , String number , String planNumber , String standardName , String expirationDate , String implementTime ) {
//设置单元格高度
table . getRow ( 0 ) . setHeight ( 500 ) ;
@@ -938,35 +962,35 @@ public class WordUtil {
ctTblWidth0 . setW ( BigInteger . valueOf ( 708 ) ) ;
//设置单元格边距
XWPFTableCell cell0 = table . getRow ( 0 ) . getCell ( 0 ) ;
cellPadding ( cell0 , number ) ;
cellPadding ( cell0 , number ) ;
CTTblWidth ctTblWidth1 = table . getRow ( 0 ) . getCell ( 1 ) . getCTTc ( ) . addNewTcPr ( ) . addNewTcW ( ) ;
ctTblWidth1 . setType ( STTblWidth . DXA ) ;
ctTblWidth1 . setW ( BigInteger . valueOf ( 1990 ) ) ;
//设置单元格边距
XWPFTableCell cell1 = table . getRow ( 0 ) . getCell ( 1 ) ;
cellPadding ( cell1 , planNumber ) ;
cellPadding ( cell1 , planNumber ) ;
CTTblWidth ctTblWidth2 = table . getRow ( 0 ) . getCell ( 2 ) . getCTTc ( ) . addNewTcPr ( ) . addNewTcW ( ) ;
ctTblWidth2 . setType ( STTblWidth . DXA ) ;
ctTblWidth2 . setW ( BigInteger . valueOf ( 3124 ) ) ;
//设置单元格边距
XWPFTableCell cell2 = table . getRow ( 0 ) . getCell ( 2 ) ;
cellPadding ( cell2 , standardName ) ;
cellPadding ( cell2 , standardName ) ;
CTTblWidth ctTblWidth3 = table . getRow ( 0 ) . getCell ( 3 ) . getCTTc ( ) . addNewTcPr ( ) . addNewTcW ( ) ;
ctTblWidth3 . setType ( STTblWidth . DXA ) ;
ctTblWidth3 . setW ( BigInteger . valueOf ( 1247 ) ) ;
//设置单元格边距
XWPFTableCell cell3 = table . getRow ( 0 ) . getCell ( 3 ) ;
cellPadding ( cell3 , expirationDate ) ;
cellPadding ( cell3 , expirationDate ) ;
CTTblWidth ctTblWidth4 = table . getRow ( 0 ) . getCell ( 4 ) . getCTTc ( ) . addNewTcPr ( ) . addNewTcW ( ) ;
ctTblWidth4 . setType ( STTblWidth . DXA ) ;
ctTblWidth4 . setW ( BigInteger . valueOf ( 1247 ) ) ;
//设置单元格边距
XWPFTableCell cell4 = table . getRow ( 0 ) . getCell ( 4 ) ;
cellPadding ( cell4 , implementTime ) ;
cellPadding ( cell4 , implementTime ) ;
// table.getRow(0).getCell(0).setText(number);
// table.getRow(0).getCell(1).setText(planNumber);
@@ -974,7 +998,8 @@ public class WordUtil {
// table.getRow(0).getCell(3).setText(expirationDate);
// table.getRow(0).getCell(4).setText(implementTime);
}
private static void setCellAskOne ( XWPFTable table , String number , String planNumber , String standardName , String expirationDate ) {
private static void setCellAskOne ( XWPFTable table , String number , String planNumber , String standardName , String expirationDate ) {
//设置单元格高度
table . getRow ( 0 ) . setHeight ( 500 ) ;
@@ -984,28 +1009,28 @@ public class WordUtil {
ctTblWidth0 . setW ( BigInteger . valueOf ( 703 ) ) ;
//设置单元格边距
XWPFTableCell cell0 = table . getRow ( 0 ) . getCell ( 0 ) ;
cellPadding ( cell0 , number ) ;
cellPadding ( cell0 , number ) ;
CTTblWidth ctTblWidth1 = table . getRow ( 0 ) . getCell ( 1 ) . getCTTc ( ) . addNewTcPr ( ) . addNewTcW ( ) ;
ctTblWidth1 . setType ( STTblWidth . DXA ) ;
ctTblWidth1 . setW ( BigInteger . valueOf ( 1984 ) ) ;
//设置单元格边距
XWPFTableCell cell1 = table . getRow ( 0 ) . getCell ( 1 ) ;
cellPadding ( cell1 , planNumber ) ;
cellPadding ( cell1 , planNumber ) ;
CTTblWidth ctTblWidth2 = table . getRow ( 0 ) . getCell ( 2 ) . getCTTc ( ) . addNewTcPr ( ) . addNewTcW ( ) ;
ctTblWidth2 . setType ( STTblWidth . DXA ) ;
ctTblWidth2 . setW ( BigInteger . valueOf ( 3543 ) ) ;
//设置单元格边距
XWPFTableCell cell2 = table . getRow ( 0 ) . getCell ( 2 ) ;
cellPadding ( cell2 , standardName ) ;
cellPadding ( cell2 , standardName ) ;
CTTblWidth ctTblWidth3 = table . getRow ( 0 ) . getCell ( 3 ) . getCTTc ( ) . addNewTcPr ( ) . addNewTcW ( ) ;
ctTblWidth3 . setType ( STTblWidth . DXA ) ;
ctTblWidth3 . setW ( BigInteger . valueOf ( 2081 ) ) ;
//设置单元格边距
XWPFTableCell cell3 = table . getRow ( 0 ) . getCell ( 3 ) ;
cellPadding ( cell3 , expirationDate ) ;
cellPadding ( cell3 , expirationDate ) ;
// table.getRow(0).getCell(0).setText(number);
// table.getRow(0).getCell(1).setText(planNumber);
@@ -1014,51 +1039,51 @@ public class WordUtil {
}
private static String dictItem ( List < SysDictItem > sysDictItems , String fieldValue , String cut , String dictCode ) {
private static String dictItem ( List < SysDictItem > sysDictItems , String fieldValue , String cut , String dictCode ) {
String fieldValueName = " " ;
if ( StringUtils . isNotEmpty ( fieldValue ) ) {
if ( StringUtils . isNotEmpty ( fieldValue ) ) {
List < String > fieldValueList = Arrays . asList ( fieldValue . split ( " , " ) ) ;
StringBuilder sb = new StringBuilder ( ) ;
for ( String fieldValueTemp : fieldValueList ) {
List < SysDictItem > collect = sysDictItems . stream ( )
. filter ( e - > fieldValueTemp . equals ( e . getItemValue ( ) ) & & dictCode . equals ( e . getDictCode ( ) ) )
. collect ( Collectors . toList ( ) ) ;
if ( collect . size ( ) ! = 0 ) {
if ( CutEnum . CN . getValue ( ) . equals ( cut ) ) {
if ( collect . size ( ) ! = 0 ) {
if ( CutEnum . CN . getValue ( ) . equals ( cut ) ) {
sb . append ( collect . get ( 0 ) . getItemText ( ) + " , " ) ;
} else {
} else {
sb . append ( collect . get ( 0 ) . getEnName ( ) + " , " ) ;
}
}
}
if ( org . apache . commons . lang3 . StringUtils . isNotBlank ( sb ) ) {
if ( org . apache . commons . lang3 . StringUtils . isNotBlank ( sb ) ) {
fieldValueName = sb . substring ( 0 , sb . length ( ) - 1 ) ;
}
}
return fieldValueName ;
}
private static void setCell ( XWPFTable table , int number , String fieldName , String 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 ( 2296 ) ) ; //宽度通过计算得来-->列表实际宽度除以2.54再乘以1440
//设置单元格边距
XWPFTableCell cell0 = table . getRow ( number ) . getCell ( 0 ) ;
cellPadding ( cell0 , fieldName ) ;
cellPadding ( cell0 , fieldName ) ;
CTTblWidth ctTblWidth1 = table . getRow ( number ) . getCell ( 1 ) . getCTTc ( ) . addNewTcPr ( ) . addNewTcW ( ) ;
ctTblWidth1 . setType ( STTblWidth . DXA ) ;
ctTblWidth1 . setW ( BigInteger . valueOf ( 6015 ) ) ;
//设置单元格边距
XWPFTableCell cell1 = table . getRow ( number ) . getCell ( 1 ) ;
if ( " 链接 " . equals ( fieldName ) | | " Link " . equals ( fieldName ) ) {
if ( " 链接 " . equals ( fieldName ) | | " Link " . equals ( fieldName ) ) {
//设置超链接
if ( StringUtils . isNotEmpty ( technologyTerritory ) ) {
cellLink ( cell1 , technologyTerritory ) ;
if ( StringUtils . isNotEmpty ( technologyTerritory ) ) {
cellLink ( cell1 , technologyTerritory ) ;
}
} else {
cellPadding ( cell1 , technologyTerritory ) ;
} else {
cellPadding ( cell1 , technologyTerritory ) ;
}
// XWPFParagraph para = table.getRow(number).getCell(1).getParagraphs().get(0);
@@ -1069,32 +1094,33 @@ public class WordUtil {
// table.getRow(number).getCell(1).setText(technologyTerritory);
}
private static void setCellThree ( XWPFTable table , int number , String fieldName , String technologyTerritory ,
List < SysDictItem > sysDictItems , String code ) {
private static void setCellThree ( XWPFTable table , int number , String fieldName , String technologyTerritory ,
List < SysDictItem > sysDictItems , String code ) {
table . getRow ( number ) . setHeight ( 500 ) ;
CTTblWidth ctTblWidth0 = table . getRow ( number ) . getCell ( 0 ) . getCTTc ( ) . addNewTcPr ( ) . addNewTcW ( ) ;
ctTblWidth0 . setType ( STTblWidth . DXA ) ;
ctTblWidth0 . setW ( BigInteger . valueOf ( 2296 ) ) ; //宽度通过计算得来-->列表实际宽度除以2.54再乘以1440
//设置单元格边距
XWPFTableCell cell0 = table . getRow ( number ) . getCell ( 0 ) ;
cellPadding ( cell0 , fieldName ) ;
cellPadding ( cell0 , fieldName ) ;
CTTblWidth ctTblWidth1 = table . getRow ( number ) . getCell ( 1 ) . getCTTc ( ) . addNewTcPr ( ) . addNewTcW ( ) ;
ctTblWidth1 . setType ( STTblWidth . DXA ) ;
ctTblWidth1 . setW ( BigInteger . valueOf ( 6015 ) ) ;
//设置单元格边距
XWPFTableCell cell1 = table . getRow ( number ) . getCell ( 1 ) ;
if ( " 链接 " . equals ( fieldName ) | | " Link " . equals ( fieldName ) ) {
if ( " 链接 " . equals ( fieldName ) | | " Link " . equals ( fieldName ) ) {
//设置超链接
if ( StringUtils . isNotEmpty ( technologyTerritory ) ) {
cellLink ( cell1 , technologyTerritory ) ;
if ( StringUtils . isNotEmpty ( technologyTerritory ) ) {
cellLink ( cell1 , technologyTerritory ) ;
}
} else {
if ( " 适用范围 " . equals ( fieldName ) | | " 状态 " . equals ( fieldName ) | | " 用法 " . equals ( fieldName )
| | " Scope " . equals ( fieldName ) | | " Status " . equals ( fieldName ) | | " Usage " . equals ( fieldName ) ) {
threeSet ( cell1 , technologyTerritory , fieldName , sysDictItems , code ) ;
} else {
cellPadding ( cell1 , technologyTerritory ) ;
} else {
if ( " 适用范围 " . equals ( fieldName ) | | " 状态 " . equals ( fieldName ) | | " 用法 " . equals ( fieldName )
| | " Scope " . equals ( fieldName ) | | " Status " . equals ( fieldName ) | | " Usage " . equals ( fieldName ) ) {
threeSet ( cell1 , technologyTerritory , fieldName , sysDictItems , code ) ;
} else {
cellPadding ( cell1 , technologyTerritory ) ;
}
}
@@ -1108,16 +1134,16 @@ public class WordUtil {
}
private static String getLawsContact ( List < LoginUser > userList , String lawsContact ) {
if ( com . jero . modules . system . util . StringUtils . isNotBlank ( lawsContact ) ) {
if ( com . jero . modules . system . util . StringUtils . isNotBlank ( lawsContact ) ) {
List < LoginUser > collect = userList . stream ( ) . filter ( e - > lawsContact . contains ( e . getId ( ) ) ) . collect ( Collectors . toList ( ) ) ;
StringBuilder sb = new StringBuilder ( ) ;
for ( String s : lawsContact . split ( " , " ) ) {
List < LoginUser > loginUserList = collect . stream ( ) . filter ( e - > e . getId ( ) . equals ( s ) ) . collect ( Collectors . toList ( ) ) ;
if ( loginUserList . size ( ) ! = 0 ) {
sb . append ( loginUserList . get ( 0 ) . getRealname ( ) + " , " ) ;
if ( loginUserList . size ( ) ! = 0 ) {
sb . append ( loginUserList . get ( 0 ) . getRealname ( ) + " , " ) ;
}
}
if ( com . jero . modules . system . util . StringUtils . isNotBlank ( sb ) ) {
if ( com . jero . modules . system . util . StringUtils . isNotBlank ( sb ) ) {
String substring = sb . substring ( 0 , sb . length ( ) - 1 ) ;
return substring ;
}
@@ -1128,12 +1154,13 @@ public class WordUtil {
/**
* 设置单元格边距
*
* @param cell
*/
public static void cellPadding ( XWPFTableCell cell , String text ) {
public static void cellPadding ( XWPFTableCell cell , String text ) {
//1. 设置单元格页边距
CTTc ctTc = cell . getCTTc ( ) ;
CTTcPr cttcpr = ctTc . isSetTcPr ( ) ? ctTc . getTcPr ( ) : ctTc . addNewTcPr ( ) ;
CTTcPr cttcpr = ctTc . isSetTcPr ( ) ? ctTc . getTcPr ( ) : ctTc . addNewTcPr ( ) ;
CTTcMar ctTcMar = cttcpr . isSetTcMar ( ) ? cttcpr . getTcMar ( ) : cttcpr . addNewTcMar ( ) ;
( ctTcMar . isSetLeft ( ) ? ctTcMar . getLeft ( ) : ctTcMar . addNewLeft ( ) ) . setW ( BigInteger . valueOf ( 119 ) ) ; //左边距
( ctTcMar . isSetTop ( ) ? ctTcMar . getTop ( ) : ctTcMar . addNewTop ( ) ) . setW ( BigInteger . valueOf ( 63 ) ) ; //上边距
@@ -1150,15 +1177,15 @@ public class WordUtil {
//XWPFRun 设置格式
XWPFRun run = par . createRun ( ) ;
//单元格内容换行
if ( StringUtils . isNotEmpty ( text ) & & text . contains ( " \ n " ) ) {
if ( StringUtils . isNotEmpty ( text ) & & text . contains ( " \ n " ) ) {
String [ ] split = text . split ( " \ n " ) ;
for ( int i = 0 ; i < split . length ; i + + ) {
run . setText ( split [ i ] ) ;
if ( i < split . length - 1 ) {
if ( i < split . length - 1 ) {
run . addBreak ( ) ;
}
}
} else {
} else {
run . setText ( text ) ;
}
//设置字体样式,大小
@@ -1168,11 +1195,11 @@ public class WordUtil {
}
//适用范围,状态,用法三个字段单独处理
public static void threeSet ( XWPFTableCell cell , String text , String fieldName , List < SysDictItem > sysDictItems , String code ) {
public static void threeSet ( XWPFTableCell cell , String text , String fieldName , List < SysDictItem > sysDictItems , String code ) {
List < SysDictItem > sysDictItemList = sysDictItems . stream ( ) . filter ( e - > code . equals ( e . getDictCode ( ) ) ) . collect ( Collectors . toList ( ) ) ;
//1. 设置单元格页边距
CTTc ctTc = cell . getCTTc ( ) ;
CTTcPr cttcpr = ctTc . isSetTcPr ( ) ? ctTc . getTcPr ( ) : ctTc . addNewTcPr ( ) ;
CTTcPr cttcpr = ctTc . isSetTcPr ( ) ? ctTc . getTcPr ( ) : ctTc . addNewTcPr ( ) ;
CTTcMar ctTcMar = cttcpr . isSetTcMar ( ) ? cttcpr . getTcMar ( ) : cttcpr . addNewTcMar ( ) ;
( ctTcMar . isSetLeft ( ) ? ctTcMar . getLeft ( ) : ctTcMar . addNewLeft ( ) ) . setW ( BigInteger . valueOf ( 119 ) ) ; //左边距
( ctTcMar . isSetTop ( ) ? ctTcMar . getTop ( ) : ctTcMar . addNewTop ( ) ) . setW ( BigInteger . valueOf ( 63 ) ) ; //上边距
@@ -1188,33 +1215,33 @@ public class WordUtil {
//XWPFRun 设置格式
XWPFRun run = par . createRun ( ) ;
//单元格内容换行 □ ■
if ( StringUtils . isNotEmpty ( text ) ) {
if ( StringUtils . isNotEmpty ( text ) ) {
StringBuilder sb = new StringBuilder ( ) ;
if ( " 适用范围 " . equals ( fieldName ) ) {
if ( " 适用范围 " . equals ( fieldName ) ) {
String itemText = " M,N,企业,整车,系统/零部件,新车型,在产车型 " ;
setBlank ( text , run , sb , itemText ) ;
}
if ( " Scope " . equals ( fieldName ) ) {
if ( " Scope " . equals ( fieldName ) ) {
// M,N,Enterprise,Vehicle,System/Parts,New Car Model,Models In Production
// M,N,Enterprise,Vehicle,System/Part ,New Type ,New Vehicle
String itemText = " M,N,Enterprise,Vehicle,System/Parts,New Car Model,Models In Production " ;
setBlank ( text , run , sb , itemText ) ;
}
if ( " 状态 " . equals ( fieldName ) ) {
if ( " 状态 " . equals ( fieldName ) ) {
String itemText = " 草稿,公示稿,发布稿 " ;
setBlank ( text , run , sb , itemText ) ;
}
if ( " Status " . equals ( fieldName ) ) {
if ( " Status " . equals ( fieldName ) ) {
// Draft,Public Notice,Release
String itemText = " Draft,Publicity,Final " ;
setBlank ( text , run , sb , itemText ) ;
}
if ( " 用法 " . equals ( fieldName ) ) {
if ( " 用法 " . equals ( fieldName ) ) {
String itemText = " 强制,推荐,安装需符合 " ;
setBlank ( text , run , sb , itemText ) ;
}
if ( " Usage " . equals ( fieldName ) ) {
String itemText = " Mandatory,Voluntary,Mandatory if fitted " ;
if ( " Usage " . equals ( fieldName ) ) {
String itemText = " Mandatory,Voluntary,if fitted " ;
setBlank ( text , run , sb , itemText ) ;
}
}
@@ -1227,67 +1254,67 @@ public class WordUtil {
private static void setBlank ( String text , XWPFRun run , StringBuilder sb , String itemText ) {
//用法的三个复选框 在后端get到的英文和导出的word对应不上,也就是和itemText中给定的内容对应不上
if ( text . equals ( " constraint " ) ) {
if ( text . equals ( " constraint " ) ) {
text = " Mandatory " ;
}
if ( text . equals ( " recommend " ) ) {
if ( text . equals ( " recommend " ) ) {
text = " Voluntary " ;
}
if ( text . equals ( " installation is compliant " ) ) {
text = " Mandatory if fitted" ;
if ( text . equals ( " installation is compliant " ) ) {
text = " if fitted " ;
}
if ( text . equals ( " Public Notice " ) ) {
if ( text . equals ( " Public Notice " ) ) {
text = " Publicity " ;
}
if ( text . equals ( " Release " ) ) {
if ( text . equals ( " Release " ) ) {
text = " Final " ;
}
for ( String value : itemText . split ( " , " ) ) {
String blank = getBlank ( value ) ;
//contains()方法 当选中的是Mandatory if fitted时,Mandatory也包含在其中结果会是true,也会被选中
if ( text . equals ( " Mandatory if fitted" ) & & value . equals ( " Mandatory if fitted " ) ) {
sb . append ( " ■ " + value + blank ) ;
break ;
}
if ( text . contains ( value ) ) {
//将错误的英文转为正确的
if ( text . contains ( value ) ) {
if ( text . equals ( " if fitted " ) & & value . equals ( " Mandatory " ) ) {
sb . append ( " □ " + value + blank ) ;
} else {
//将错误的英文转为正确的
String value1 = scopeConvert ( value ) ;
sb . append ( " ■ " + value1 + blank ) ;
}
} else {
String value1 = scopeConvert ( value ) ;
sb . append ( " ■ " + value1 + blank ) ;
} else {
String value1 = scopeConvert ( value ) ;
sb . append ( " □ " + value1 + blank ) ;
sb . append ( " □ " + value1 + blank ) ;
}
}
String [ ] split = sb . toString ( ) . split ( " \ r \ n " ) ;
for ( int i = 0 ; i < split . length ; i + + ) {
run . setText ( split [ i ] ) ;
if ( i < split . length - 1 ) {
if ( i < split . length - 1 ) {
run . addBreak ( ) ;
}
}
}
private static String scopeConvert ( String text ) {
private static String scopeConvert ( String text ) {
if ( text . equals ( " System/Parts " ) ) {
if ( text . equals ( " System/Parts " ) ) {
text = " System/Part " ;
return text ;
}
if ( text . equals ( " New Car Model " ) ) {
if ( text . equals ( " New Car Model " ) ) {
text = " New Type " ;
return text ;
}
if ( text . equals ( " Models In Production " ) ) {
if ( text . equals ( " Models In Production " ) ) {
text = " New Vehicle " ;
return text ;
}
return text ;
}
public static String getBlank ( String value ) {
public static String getBlank ( String value ) {
String blank = " " ;
switch ( value ) {
case " M " :
@@ -1359,7 +1386,7 @@ public class WordUtil {
case " Voluntary " :
blank = " \ r \ n " ;
break ;
case " Mandatory if fitted" :
case " if fitted " :
blank = " " ;
break ;
default :
@@ -1370,13 +1397,14 @@ public class WordUtil {
/**
* 设置页边距,字体样式,超链接
*
* @param cell
* @param text
*/
public static void cellLink ( XWPFTableCell cell , String text ) {
public static void cellLink ( XWPFTableCell cell , String text ) {
//1. 单元格页边距
CTTc ctTc = cell . getCTTc ( ) ;
CTTcPr cttcpr = ctTc . isSetTcPr ( ) ? ctTc . getTcPr ( ) : ctTc . addNewTcPr ( ) ;
CTTcPr cttcpr = ctTc . isSetTcPr ( ) ? ctTc . getTcPr ( ) : ctTc . addNewTcPr ( ) ;
CTTcMar ctTcMar = cttcpr . isSetTcMar ( ) ? cttcpr . getTcMar ( ) : cttcpr . addNewTcMar ( ) ;
( ctTcMar . isSetLeft ( ) ? ctTcMar . getLeft ( ) : ctTcMar . addNewLeft ( ) ) . setW ( BigInteger . valueOf ( 119 ) ) ; //左边距
( ctTcMar . isSetTop ( ) ? ctTcMar . getTop ( ) : ctTcMar . addNewTop ( ) ) . setW ( BigInteger . valueOf ( 63 ) ) ; //上边距
@@ -1427,11 +1455,9 @@ public class WordUtil {
fonts . setHAnsi ( " Blue Sky Noto Regular " ) ;
ctr . setTArray ( new CTText [ ] { ctText } ) ;
ctr . setTArray ( new CTText [ ] { ctText } ) ;
// Insert the linked text into the link
cLink . setRArray ( new CTR [ ] { ctr } ) ;
cLink . setRArray ( new CTR [ ] { ctr } ) ;
}
}