diff --git a/com.actionsoft.apps.coe.pal/lib/com.actionsoft.apps.coe.pal.jar b/com.actionsoft.apps.coe.pal/lib/com.actionsoft.apps.coe.pal.jar index f1641f31..f105e964 100644 Binary files a/com.actionsoft.apps.coe.pal/lib/com.actionsoft.apps.coe.pal.jar and b/com.actionsoft.apps.coe.pal/lib/com.actionsoft.apps.coe.pal.jar differ diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/output/util/OutputWordUtil.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/output/util/OutputWordUtil.java index 753eeb8d..b7132bd6 100755 --- a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/output/util/OutputWordUtil.java +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/output/util/OutputWordUtil.java @@ -517,9 +517,14 @@ public class OutputWordUtil { Section firstsection = document.getSections().get(1); Table table1 = firstsection.getTables().get(0); + + table1.setPreferredWidth(new PreferredWidth(WidthType.Twip, (short) 8335f)); + //遍历表格单元格 for (int i = 0;i< table1.getRows().getCount();i++) { TableRow rows = table1.getRows().get(i); + + for (int j = 0; j< rows.getCells().getCount(); j++){ for (int z= 0; z < rows.getCells().get(j).getParagraphs().getCount();z++){ Paragraph p = rows.getCells().get(j).getParagraphs().get(z); @@ -535,8 +540,10 @@ public class OutputWordUtil { } } + } + JSONArray versionHistoryTable = getVersionHistoryTable(repositoryModel); int index = 0; if (versionHistoryTable.getJSONObject(0).size() > 0) { @@ -559,8 +566,9 @@ public class OutputWordUtil { paragraph2.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式 + //定义表格数据 - String[] header = {"版本", "拟制/修订单位","拟制/修订人","拟制/修订日期","审核人","复核人","审批人","修订内容及理由"}; + String[] header = {"版本", "发布部门","拟制人","拟制日期","审核人","复核人","审批人","修订内容及理由"}; String[][] strArray2 = new String[versionHistoryTable.size()][]; List list = new LinkedList<>(); for (int i = 0; i < versionHistoryTable.size(); i++) { @@ -592,6 +600,16 @@ public class OutputWordUtil { TableRow row = table.getRows().get(0); row.isHeader(true); row.setHeightType(TableRowHeightType.Exactly); + + float[] columnWidths = {10f,15f,12f,15f,12f,12f,12f,25f}; + + // 设置列宽 + for (int i = 0; i < columnWidths.length; i++) { + row.getCells().get(i).setWidth(columnWidths[i]); + row.getCells().get(i).setCellWidthType(CellWidthType.Percentage); + } + + for (int i = 0; i < header.length; i++) { row.getCells().get(i).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle); Paragraph p = row.getCells().get(i).addParagraph(); @@ -603,27 +621,6 @@ public class OutputWordUtil { txtRange.getCharacterFormat().setFontName("宋体"); txtRange.getCharacterFormat().setFontSize(10.5f); - //设置固定列宽 - if(i==0){ - row.getCells().get(0).setWidth(45); - }else if(i==1){ - row.getCells().get(1).setWidth(45); - }else if(i==2){ - row.getCells().get(2).setWidth(45); - }else if(i==3){ - row.getCells().get(3).setWidth(50); - }else if(i==4){ - row.getCells().get(4).setWidth(50); - }else if(i==5){ - row.getCells().get(5).setWidth(50); - }else if(i==6){ - row.getCells().get(6).setWidth(50); - }else if(i==7){ - row.getCells().get(7).setWidth(90); - } - - - } @@ -646,23 +643,14 @@ public class OutputWordUtil { text.getCharacterFormat().setFontName("宋体"); text.getCharacterFormat().setFontSize(10.5f); - //设置固定列宽 - if(c==0){ - dataRow.getCells().get(0).setWidth(35); - }else if(c==1){ - dataRow.getCells().get(1).setWidth(45); - }else if(c==2){ - dataRow.getCells().get(2).setWidth(45); - }else if(c==3){ - dataRow.getCells().get(3).setWidth(50); - }else if(c==4){ - dataRow.getCells().get(4).setWidth(50); - }else if(c==5){ - dataRow.getCells().get(5).setWidth(50); - }else if(c==6){ - dataRow.getCells().get(6).setWidth(50); - }else if(c==7){ - dataRow.getCells().get(7).setWidth(90); + + + + + // 设置列宽 + for (int i = 0; i < columnWidths.length; i++) { + row.getCells().get(i).setWidth(columnWidths[i]); + row.getCells().get(i).setCellWidthType(CellWidthType.Percentage); } @@ -908,8 +896,9 @@ public class OutputWordUtil { //paragraph.appendBreak(BreakType.Page_Break); - //关键控制点风险矩阵 开始 - PALRepositoryPropertyModel riskMatrixInfo = PALRepositoryPropertyCache.getPropertyByPropertyId(repositoryModel.getId(), "riskMatrixInfo"); + // 开始 + /*********************************************************关键控制点风险矩阵 begin**********************************************************************************/ + /* PALRepositoryPropertyModel riskMatrixInfo = PALRepositoryPropertyCache.getPropertyByPropertyId(repositoryModel.getId(), "riskMatrixInfo"); if(null!=riskMatrixInfo){ JSONObject jsonObject = JSONObject.parseObject(riskMatrixInfo.getPropertyValue()); if(null != jsonObject){ @@ -917,15 +906,20 @@ public class OutputWordUtil { //看看tableInfo是什么内容,如果没有内容,也不用生成表格 System.out.println(">>>>>>>>>tableInfo.toString() = " + tableInfo.toString()); if(tableInfo.size()>1){ + + CharacterFormat format2 = new CharacterFormat(); + //创建字体格式 + format2.setFontName("宋体"); //添加段落,设置一级序列 - Paragraph paragraph_risk = section.addParagraph(); - ParagraphFormat paragraphFormat_risk = paragraph_risk.getFormat(); - paragraphFormat_risk.setHorizontalAlignment(Left); - TextRange tr = paragraph_risk.appendText("关键控制点风险矩阵"); - tr.getCharacterFormat().setBold(true); - tr.getCharacterFormat().setFontName("宋体"); - tr.getCharacterFormat().setFontSize(12f); - paragraph_risk.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式 + Paragraph paragraph2 = section.addParagraph(); + ParagraphFormat paragraphFormat2 = paragraph2.getFormat(); + paragraphFormat2.setHorizontalAlignment(Left); + TextRange tr2 = paragraph2.appendText("关键控制点风险矩阵"); + tr2.getCharacterFormat().setBold(true); + tr2.getCharacterFormat().setFontName("宋体"); + tr2.getCharacterFormat().setFontSize(12f); + paragraph2.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式 + //定义表格数据 @@ -934,333 +928,210 @@ public class OutputWordUtil { Table table = section.addTable(true); table.resetCells(tableInfo.size(),header.length); //table.getTableFormat().isAutoResized(true); - table.autoFit(AutoFitBehaviorType.Fixed_Column_Widths); + table.autoFit(AutoFitBehaviorType.Auto_Fit_To_Window); TableRow row = table.getRows().get(0); row.isHeader(true); - row.setHeight(20); - row.setHeightType(TableRowHeightType.Exactly); + row.setHeightType(TableRowHeightType.Auto); for (int i = 0; i < header.length; i++) { row.getCells().get(i).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle); Paragraph p = row.getCells().get(i).addParagraph(); - p.getFormat().setHorizontalAlignment(HorizontalAlignment.Center); + p.getFormat().setHorizontalAlignment(Center); TextRange txtRange = p.appendText(header[i]); txtRange.getCharacterFormat().setBold(true); txtRange.getCharacterFormat().setFontName("宋体"); txtRange.getCharacterFormat().setFontSize(10.5f); - - //设置固定列宽 - if(i==0){ - row.getCells().get(0).setWidth(10); - }else if(i==1){ - row.getCells().get(1).setWidth(10); - }else if(i==2){ - row.getCells().get(2).setWidth(10); - }else if(i==3){ - row.getCells().get(3).setWidth(10); - } } + + //添加数据到表中 for (int i = 1; i < tableInfo.size(); i++) { JSONObject cellInfo = tableInfo.getJSONObject(i); TableRow dataRow = table.getRows().get(i); dataRow.setHeight(25); - dataRow.setHeightType(TableRowHeightType.Auto); - dataRow.getRowFormat().setBackColor(Color.white); + dataRow.setHeightType(TableRowHeightType.Exactly); int flagNum = 0; for (String cellKey : cellInfo.keySet()) { if(cellKey.equals("id")){ continue; } dataRow.getCells().get(flagNum).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle); - //设置固定列宽 - //dataRow.getCells().get(0).setWidth(50); - //dataRow.getCells().get(1).setWidth(150); - //dataRow.getCells().get(c).addParagraph().appendText(data[r][c]); + + TableCell cell = dataRow.getCells().get(flagNum); + + + // 清除单元格原有段落(重要!) + cell.getParagraphs().clear(); + + Paragraph p = cell.addParagraph(); + + + // 第一列居中,第二列居左 + if (flagNum == 0) { + p.getFormat().setHorizontalAlignment(HorizontalAlignment.Center); + } else { + p.getFormat().setHorizontalAlignment(HorizontalAlignment.Left); + + } TextRange text =dataRow.getCells().get(flagNum).addParagraph().appendText(cellInfo.getString(cellKey)); text.getCharacterFormat().setFontName("宋体"); text.getCharacterFormat().setFontSize(10.5f); - dataRow.getRowFormat().setHorizontalAlignment(RowAlignment.Center); - dataRow.getCells().get(flagNum).getCellFormat(); flagNum++; + } - //设置固定列宽 - if(i==0){ - row.getCells().get(0).setWidth(10); - }else if(i==1){ - row.getCells().get(1).setWidth(10); - }else if(i==2){ - row.getCells().get(2).setWidth(10); - }else if(i==3){ - row.getCells().get(3).setWidth(10); - } + } + + Paragraph paragraph_blank = section.addParagraph(); } } - } - //关键控制点风险矩阵 结束 - - //相关文件 R_relevant_flies + }*/ - /*JSONArray relevant_flies = new JSONArray(); //组织职责Table - List relationList2 = DesignerShapeRelationCache.getListByAttrId(repositoryModel.getId(), "", "related_files"); - relationList2.sort(Comparator.comparing(DesignerShapeRelationModel::getShapeText)); - int count = 0; - if (relationList2.size() > 0) { - for (DesignerShapeRelationModel relation : relationList2) { - String relationFileId = relation.getRelationFileId();// 支持或相关文件的ID - String name = null; - List models = PALRepositoryCache.getByVersionId(relationFileId); - if (models != null && models.size() > 0) { - count++; - for(PALRepositoryModel oneModel:models){ - if(oneModel.isUse()==true){ - name=oneModel.getName(); + + JSONArray riskMatrix = new JSONArray(); //组织职责Table + PALRepositoryPropertyModel riskMatrixInfoData = PALRepositoryPropertyCache.getPropertyByPropertyId(repositoryModel.getId(), "riskMatrixInfo"); + + + if(null!=riskMatrixInfoData) { + JSONObject jsonObject = JSONObject.parseObject(riskMatrixInfoData.getPropertyValue()); + if (null != jsonObject) { + JSONArray tableInfo = jsonObject.getJSONArray("table"); + //看看tableInfo是什么内容,如果没有内容,也不用生成表格 + System.out.println(">>>>>>>>>tableInfo.toString() = " + tableInfo.toString()); + if (tableInfo.size() > 1) { + + int index = 0; + + //添加数据到表中 + for (int i = 1; i < tableInfo.size(); i++) { + JSONObject cellInfo = tableInfo.getJSONObject(i); + JSONObject tmp = new JSONObject(); + tmp.put("firstColumn", tableInfo.getJSONObject(i).getString("firstColumn")); + tmp.put("secondColumn", tableInfo.getJSONObject(i).getString("secondColumn")); + tmp.put("threeColumn", tableInfo.getJSONObject(i).getString("threeColumn")); + tmp.put("fourColumn", tableInfo.getJSONObject(i).getString("fourColumn")); + riskMatrix.add(tmp); + } + CharacterFormat format2 = new CharacterFormat(); + //创建字体格式 + format2.setFontName("宋体"); + //添加段落,设置一级序列 + Paragraph paragraph2 = section.addParagraph(); + ParagraphFormat paragraphFormat2 = paragraph2.getFormat(); + paragraphFormat2.setHorizontalAlignment(Left); + TextRange tr2 = paragraph2.appendText("关键控制点风险矩阵"); + tr2.getCharacterFormat().setBold(true); + tr2.getCharacterFormat().setFontName("宋体"); + tr2.getCharacterFormat().setFontSize(12f); + paragraph2.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式 + + + //定义表格数据 + String[] header = {"关键控制点", "控制描述","对应风险描述","角色/岗位"}; + String[][] strArray2 = new String[riskMatrix.size()][]; + List list = new LinkedList<>(); + for (int i = 0; i < riskMatrix.size(); i++) { + JSONObject jsonObject1 = riskMatrix.getJSONObject(i); + String[] strArray = new String[4]; + strArray[0] = jsonObject1.getString("firstColumn").toString(); + strArray[1] = jsonObject1.getString("secondColumn").toString(); + strArray[2] = jsonObject1.getString("threeColumn").toString(); + strArray[3] = jsonObject1.getString("fourColumn").toString(); + list.add(strArray); + strArray2[i] = strArray; + } + + String[][] data = strArray2; + + //添加表格 + Table table = section.addTable(true); + table.resetCells(data.length + 1, header.length); + + table.autoFit(AutoFitBehaviorType.Auto_Fit_To_Window); + + + TableRow row = table.getRows().get(0); + row.isHeader(true); + //row.setHeight(20); + row.setHeightType(TableRowHeightType.Auto); + for (int i = 0; i < header.length; i++) { + row.getCells().get(i).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle); + Paragraph p = row.getCells().get(i).addParagraph(); + p.getFormat().setHorizontalAlignment(Center); + TextRange txtRange = p.appendText(header[i]); + txtRange.getCharacterFormat().setBold(true); + txtRange.getCharacterFormat().setFontName("宋体"); + txtRange.getCharacterFormat().setFontSize(10.5f); + } + + + float[] columnWidths = {20f, 30f,30f,20f}; // 比例总和为100% + + // 设置列宽 + for (int i = 0; i < columnWidths.length; i++) { + row.getCells().get(i).setWidth(columnWidths[i]); + } + + //将数据添加到其余行 + for (int r = 0; r < data.length; r++) { + TableRow dataRow = table.getRows().get(r + 1); + //dataRow.setHeight(25); + dataRow.setHeightType(TableRowHeightType.Auto); + dataRow.getRowFormat().setBackColor(Color.white); + for (int c = 0; c < data[r].length; c++) { + + TableCell cell = dataRow.getCells().get(c); + + dataRow.getCells().get(c).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle); + + // 清除单元格原有段落(重要!) + cell.getParagraphs().clear(); + + Paragraph p = cell.addParagraph(); + + + // 第一列居中,第二列居左 + if (c == 0) { + p.getFormat().setHorizontalAlignment(HorizontalAlignment.Center); + } else { + p.getFormat().setHorizontalAlignment(HorizontalAlignment.Left); + + } + TextRange text = p.appendText(data[r][c]); + text.getCharacterFormat().setFontName("宋体"); + text.getCharacterFormat().setFontSize(10.5f); + + // 设置列宽 + for (int i = 0; i < columnWidths.length; i++) { + dataRow.getCells().get(i).setWidth(columnWidths[i]); + dataRow.getCells().get(i).setCellWidthType(CellWidthType.Percentage); + } } } - //String name = model.getName(); - JSONObject tmp = new JSONObject(); - tmp.put("name", name); - tmp.put("desc", count); - relevant_flies.add(tmp); - - } - - CharacterFormat format = new CharacterFormat(); - //创建字体格式 - format.setFontName("宋体"); - //添加段落,设置一级序列 - Paragraph paragraph1 = section.addParagraph(); - - ParagraphFormat paragraphFormat1 = paragraph1.getFormat(); - paragraphFormat1.setHorizontalAlignment(Left); - - TextRange tr = paragraph1.appendText("相关文件"); - tr.getCharacterFormat().setBold(true); - tr.getCharacterFormat().setFontName("宋体"); - tr.getCharacterFormat().setFontSize(12f); - //tr.applyCharacterFormat(format); //应用字体格式 - paragraph1.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式 - //定义表格数据 - String[] header = {"序号", "文件名称"}; - - String[][] strArray2 = new String[relevant_flies.size()][]; - List list = new LinkedList<>(); - for (int i = 0; i < relevant_flies.size(); i++) { - JSONObject jsonObject = relevant_flies.getJSONObject(i); - String[] strArray = new String[2]; - strArray[0] = jsonObject.getString("desc").toString(); - strArray[1] = jsonObject.getString("name").toString(); - list.add(strArray); - strArray2[i] = strArray; - } - - String[][] data = strArray2; - - //添加表格 - Table table = section.addTable(true); - table.resetCells(data.length + 1, header.length); - table.getTableFormat().isAutoResized(true); - - table.autoFit(AutoFitBehaviorType.Auto_Fit_To_Window); - - - TableRow row = table.getRows().get(0); - row.isHeader(true); - row.setHeight(20); - row.setHeightType(TableRowHeightType.Exactly); - for (int i = 0; i < header.length; i++) { - row.getCells().get(i).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle); - //设置固定列宽 - //row.getCells().get(0).setWidth(50); - //row.getCells().get(1).setWidth(150); - Paragraph p = row.getCells().get(i).addParagraph(); - //p.getFormat().setHorizontalAlignment(Center); - - p.getFormat().setHorizontalAlignment(HorizontalAlignment.Center); - TextRange txtRange = p.appendText(header[i]); - txtRange.getCharacterFormat().setBold(true); - txtRange.getCharacterFormat().setFontName("宋体"); - txtRange.getCharacterFormat().setFontSize(10.5f); - } - - - - - - - - - //将数据添加到其余行 - for (int r = 0; r < data.length; r++) { - TableRow dataRow = table.getRows().get(r + 1); - dataRow.setHeight(25); - dataRow.setHeightType(TableRowHeightType.Exactly); - dataRow.getRowFormat().setBackColor(Color.white); - for (int c = 0; c < data[r].length; c++) { - dataRow.getCells().get(c).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle); - //设置固定列宽 - //dataRow.getCells().get(0).setWidth(50); - //dataRow.getCells().get(1).setWidth(150); - //dataRow.getCells().get(c).addParagraph().appendText(data[r][c]); - - TextRange text =dataRow.getCells().get(c).addParagraph().appendText(data[r][c]); - text.getCharacterFormat().setFontName("宋体"); - text.getCharacterFormat().setFontSize(10.5f); - - //dataRow.getRowFormat().setHorizontalAlignment(); - //tableRow.setGravity(Gravity.CENTER); - dataRow.getRowFormat().setHorizontalAlignment(RowAlignment.Center); - - dataRow.getCells().get(c).getCellFormat(); - } - } - - - - Paragraph paragraph_blank = section.addParagraph(); - - }*/ - int extercount = 0; - //外部相关文件 - JSONArray ExternalCorrelationFileArray = new JSONArray(); //外部相关文件Table - String sqlOut = "select PROPERTYVALUE from APP_ACT_COE_PAL_PROP where PLID = '"+repositoryModel.getId()+"' and PROPERTYID = 'Out_related_files'"; - String outRelatFileJson = DBSql.getString(sqlOut); - if(UtilString.isNotEmpty(outRelatFileJson)) { - if(outRelatFileJson.contains(",")) { - String[] split = outRelatFileJson.split(","); - for (String str : split) { - extercount++; - JSONObject tmp = new JSONObject(); - tmp.put("name", str+"【外部】"); - tmp.put("desc", extercount); - ExternalCorrelationFileArray.add(tmp); - } - }else if(outRelatFileJson.contains(",")) { - String[] split = outRelatFileJson.split(","); - for (String str : split) { - extercount++; - JSONObject tmp = new JSONObject(); - tmp.put("name", str+"【外部】"); - tmp.put("desc", extercount); - ExternalCorrelationFileArray.add(tmp); - } - }else { - extercount++; - JSONObject tmp = new JSONObject(); - tmp.put("name", outRelatFileJson+"【外部】"); - tmp.put("desc", extercount); - ExternalCorrelationFileArray.add(tmp); - } - - - - CharacterFormat format = new CharacterFormat(); - //创建字体格式 - format.setFontName("宋体"); - //添加段落,设置一级序列 - Paragraph paragraph1 = section.addParagraph(); - - ParagraphFormat paragraphFormat1 = paragraph1.getFormat(); - paragraphFormat1.setHorizontalAlignment(Left); - - TextRange tr = paragraph1.appendText("外部相关文件"); - tr.getCharacterFormat().setBold(true); - tr.getCharacterFormat().setFontName("宋体"); - tr.getCharacterFormat().setFontSize(12f); - //tr.applyCharacterFormat(format); //应用字体格式 - paragraph1.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式 - - - //定义表格数据 - String[] header = {"序号", "文件名称"}; - - String[][] strArray2 = new String[ExternalCorrelationFileArray.size()][]; - List list = new LinkedList<>(); - for (int i = 0; i < ExternalCorrelationFileArray.size(); i++) { - JSONObject jsonObject = ExternalCorrelationFileArray.getJSONObject(i); - String[] strArray = new String[2]; - strArray[0] = jsonObject.getString("desc").toString(); - strArray[1] = jsonObject.getString("name").toString(); - list.add(strArray); - strArray2[i] = strArray; - } - - String[][] data = strArray2; - - //添加表格 - Table table = section.addTable(true); - table.resetCells(data.length + 1, header.length); - table.autoFit(AutoFitBehaviorType.Auto_Fit_To_Window); - TableRow row = table.getRows().get(0); - row.isHeader(true); - row.setHeight(20); - row.setHeightType(TableRowHeightType.Exactly); - - for (int i = 0; i < header.length; i++) { - row.getCells().get(i).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle); - //设置固定列宽 - //row.getCells().get(0).setWidth(150); - //row.getCells().get(1).setWidth(500); - - - Paragraph p = row.getCells().get(i).addParagraph(); - //p.getFormat().setHorizontalAlignment(Center); - p.getFormat().setHorizontalAlignment(HorizontalAlignment.Center); - - TextRange txtRange = p.appendText(header[i]); - txtRange.getCharacterFormat().setBold(true); - txtRange.getCharacterFormat().setFontName("宋体"); - txtRange.getCharacterFormat().setFontSize(10.5f); - - } - - //将数据添加到其余行 - for (int r = 0; r < data.length; r++) { - TableRow dataRow = table.getRows().get(r + 1); - dataRow.setHeight(25); - dataRow.setHeightType(TableRowHeightType.Exactly); - for (int c = 0; c < data[r].length; c++) { - dataRow.getCells().get(c).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle); - //设置固定列宽 - //dataRow.getCells().get(0).setWidth(150); - //dataRow.getCells().get(1).setWidth(500); - //dataRow.getCells().get(c).addParagraph().appendText(data[r][c]); - TextRange text =dataRow.getCells().get(c).addParagraph().appendText(data[r][c]); - - dataRow.getRowFormat().setHorizontalAlignment(RowAlignment.Center); - text.getCharacterFormat().setFontName("宋体"); - text.getCharacterFormat().setFontSize(10.5f); - - } - } - - //遍历表格单元格 - for (int i = 0;i< table.getRows().getCount();i++) { - TableRow rows = table.getRows().get(i); - for (int j = 0; j< rows.getCells().getCount(); j++){ - for (int z= 0; z < rows.getCells().get(j).getParagraphs().getCount();z++){ - Paragraph p = rows.getCells().get(j).getParagraphs().get(z); - if(j==0&& z==0){ - p.getFormat().setHorizontalAlignment(HorizontalAlignment.Center); - } + Paragraph paragraph_blank = section.addParagraph(); } + + + } } - Paragraph paragraph_blank = section.addParagraph(); - } - //支持文件 + + /*********************************************************关键控制点风险矩阵 end******************************************************************/ + + + + /**********************************************相关/支持文件表格绘制 begin**********************************************************************/ JSONArray related_support_files = new JSONArray(); //组织职责Table List relationList = DesignerShapeRelationCache.getListByAttrId(repositoryModel.getId(), "", "related_support_files"); @@ -1335,39 +1206,220 @@ public class OutputWordUtil { txtRange.getCharacterFormat().setFontSize(10.5f); } + float[] columnWidths = {10f, 90f}; // 比例总和为100% + + // 设置列宽 + for (int i = 0; i < columnWidths.length; i++) { + row.getCells().get(i).setWidth(columnWidths[i]); + row.getCells().get(i).setCellWidthType(CellWidthType.Percentage); + + } + + //将数据添加到其余行 for (int r = 0; r < data.length; r++) { TableRow dataRow = table.getRows().get(r + 1); //dataRow.setHeight(25); - dataRow.setHeightType(TableRowHeightType.Auto); + //dataRow.setHeightType(TableRowHeightType.Auto); dataRow.getRowFormat().setBackColor(Color.white); for (int c = 0; c < data[r].length; c++) { + TableCell cell = dataRow.getCells().get(c); + dataRow.getCells().get(c).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle); - //设置固定列宽 - TextRange text =dataRow.getCells().get(c).addParagraph().appendText(data[r][c]); + + // 清除单元格原有段落(重要!) + cell.getParagraphs().clear(); + + Paragraph p = cell.addParagraph(); + + + // 第一列居中,第二列居左 + if (c == 0) { + p.getFormat().setHorizontalAlignment(HorizontalAlignment.Center); + } else { + p.getFormat().setHorizontalAlignment(HorizontalAlignment.Left); + + } + TextRange text = p.appendText(data[r][c]); text.getCharacterFormat().setFontName("宋体"); text.getCharacterFormat().setFontSize(10.5f); - } - } - //遍历表格单元格 - for (int i = 0;i< table.getRows().getCount();i++) { - TableRow rows = table.getRows().get(i); - for (int j = 0; j< rows.getCells().getCount(); j++){ - for (int z= 0; z < rows.getCells().get(j).getParagraphs().getCount();z++){ - Paragraph p = rows.getCells().get(j).getParagraphs().get(z); - if(j==0&& z==0){ - p.getFormat().setHorizontalAlignment(HorizontalAlignment.Center); - } + // 设置列宽 + for (int i = 0; i < columnWidths.length; i++) { + dataRow.getCells().get(i).setWidth(columnWidths[i]); + dataRow.getCells().get(i).setCellWidthType(CellWidthType.Percentage); } } } + + Paragraph paragraph_blank = section.addParagraph(); } + /**********************************************相关/支持文件表格绘制 end*********************************************************************/ + + + + + /**********************************************外部相关文件表格绘制 begin*********************************************************************/ + + int extercount = 0; + //外部相关文件 + JSONArray ExternalCorrelationFileArray = new JSONArray(); //外部相关文件Table + String sqlOut = "select PROPERTYVALUE from APP_ACT_COE_PAL_PROP where PLID = '"+repositoryModel.getId()+"' and PROPERTYID = 'Out_related_files'"; + String outRelatFileJson = DBSql.getString(sqlOut); + if(UtilString.isNotEmpty(outRelatFileJson)) { + if(outRelatFileJson.contains(",")) { + String[] split = outRelatFileJson.split(","); + for (String str : split) { + extercount++; + JSONObject tmp = new JSONObject(); + tmp.put("name", str+"【外部】"); + tmp.put("desc", extercount); + ExternalCorrelationFileArray.add(tmp); + } + }else if(outRelatFileJson.contains(",")) { + String[] split = outRelatFileJson.split(","); + for (String str : split) { + extercount++; + JSONObject tmp = new JSONObject(); + tmp.put("name", str+"【外部】"); + tmp.put("desc", extercount); + ExternalCorrelationFileArray.add(tmp); + } + }else { + extercount++; + JSONObject tmp = new JSONObject(); + tmp.put("name", outRelatFileJson+"【外部】"); + tmp.put("desc", extercount); + ExternalCorrelationFileArray.add(tmp); + } + + + + CharacterFormat format = new CharacterFormat(); + //创建字体格式 + format.setFontName("宋体"); + //添加段落,设置一级序列 + Paragraph paragraph1 = section.addParagraph(); + + ParagraphFormat paragraphFormat1 = paragraph1.getFormat(); + paragraphFormat1.setHorizontalAlignment(Left); + + TextRange tr = paragraph1.appendText("外部相关文件"); + tr.getCharacterFormat().setBold(true); + tr.getCharacterFormat().setFontName("宋体"); + tr.getCharacterFormat().setFontSize(12f); + //tr.applyCharacterFormat(format); //应用字体格式 + paragraph1.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式 + + + + + + //定义表格数据 + String[] header = {"序号", "文件名称"}; + + String[][] strArray2 = new String[ExternalCorrelationFileArray.size()][]; + List list = new LinkedList<>(); + for (int i = 0; i < ExternalCorrelationFileArray.size(); i++) { + JSONObject jsonObject = ExternalCorrelationFileArray.getJSONObject(i); + String[] strArray = new String[2]; + strArray[0] = jsonObject.getString("desc").toString(); + strArray[1] = jsonObject.getString("name").toString(); + list.add(strArray); + strArray2[i] = strArray; + } + + String[][] data = strArray2; + + //添加表格 + Table table = section.addTable(true); + table.resetCells(data.length + 1, header.length); + table.autoFit(AutoFitBehaviorType.Auto_Fit_To_Window); + TableRow row = table.getRows().get(0); + row.isHeader(true); + row.setHeight(20); + row.setHeightType(TableRowHeightType.Exactly); + + + + for (int i = 0; i < header.length; i++) { + + TableCell cell = row.getCells().get(i); + + row.getCells().get(i).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle); + + // 清除单元格原有段落(重要!) + cell.getParagraphs().clear(); + + Paragraph p = row.getCells().get(i).addParagraph(); + p.getFormat().setHorizontalAlignment(HorizontalAlignment.Center); + + TextRange txtRange = p.appendText(header[i]); + txtRange.getCharacterFormat().setBold(true); + txtRange.getCharacterFormat().setFontName("宋体"); + txtRange.getCharacterFormat().setFontSize(10.5f); + + } + + + float[] columnWidths = {10f, 90f}; // 比例总和为100% + + + //将数据添加到其余行 + for (int r = 0; r < data.length; r++) { + TableRow dataRow = table.getRows().get(r + 1); + dataRow.setHeight(25); + dataRow.setHeightType(TableRowHeightType.Exactly); + for (int c = 0; c < data[r].length; c++) { + TableCell cell = dataRow.getCells().get(c); + + dataRow.getCells().get(c).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle); + + // 清除单元格原有段落(重要!) + cell.getParagraphs().clear(); + + Paragraph p = cell.addParagraph(); + + + // 第一列居中,第二列居左 + if (c == 0) { + p.getFormat().setHorizontalAlignment(HorizontalAlignment.Center); + } else { + p.getFormat().setHorizontalAlignment(HorizontalAlignment.Left); + + } + TextRange text = p.appendText(data[r][c]); + text.getCharacterFormat().setFontName("宋体"); + text.getCharacterFormat().setFontSize(10.5f); + + // 设置列宽 + for (int i = 0; i < columnWidths.length; i++) { + row.getCells().get(i).setWidth(columnWidths[i]); + row.getCells().get(i).setCellWidthType(CellWidthType.Percentage); + + } + } + } + + + + + + + + Paragraph paragraph_blank = section.addParagraph(); + } + + /**********************************************外部相关文件表格绘制 end*********************************************************************/ + + + + //查询模型文件属性上传附件信息 List search2 = upFileDao.searchByRepositoryId(repositoryModel.getId(), "f");