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 b8d9b912..3ea20ba3 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 @@ -790,93 +790,89 @@ public class OutputWordUtil { JSONObject jsonObject = JSONObject.parseObject(riskMatrixInfo.getPropertyValue()); if(null != jsonObject){ JSONArray tableInfo = jsonObject.getJSONArray("table"); - //添加段落,设置一级序列 - 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样式 + //看看tableInfo是什么内容,如果没有内容,也不用生成表格 + System.out.println(">>>>>>>>>tableInfo.toString() = " + tableInfo.toString()); + if(!tableInfo.isEmpty()){ + //添加段落,设置一级序列 + 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样式 - //定义表格数据 - String[] header = {"关键控制点", "控制描述","对应风险控制","角色/岗位"}; - //添加表格的表头 - Table table = section.addTable(true); - table.resetCells(tableInfo.size(),header.length); - //table.getTableFormat().isAutoResized(true); - table.autoFit(AutoFitBehaviorType.Fixed_Column_Widths); - 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); - 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); + //定义表格数据 + String[] header = {"关键控制点", "控制描述","对应风险控制","角色/岗位"}; + //添加表格的表头 + Table table = section.addTable(true); + table.resetCells(tableInfo.size(),header.length); + //table.getTableFormat().isAutoResized(true); + table.autoFit(AutoFitBehaviorType.Fixed_Column_Widths); + 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); + 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); - //设置固定列宽 - 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); - - - 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]); - - 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); + } } + //添加数据到表中 + 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); + 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]); - //设置固定列宽 - 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); + 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(); } - Paragraph paragraph_blank = section.addParagraph(); } } //关键控制点风险矩阵 结束