表格序号列居中显示处理
This commit is contained in:
parent
4ab535856f
commit
f861e49423
Binary file not shown.
@ -188,7 +188,7 @@ public class OutputWordUtil {
|
||||
* @param tempName
|
||||
* @param docName
|
||||
*/
|
||||
public static void createDoc2(JSONObject dataMap, String tempPath, String tempName, String docName) {
|
||||
public static void createDoc2(JSONObject dataMap, String tempPath, String tempName, String docName,String repositoryId) throws FileNotFoundException {
|
||||
Configuration configuration = new Configuration();
|
||||
configuration.setDefaultEncoding("UTF-8");
|
||||
|
||||
@ -205,6 +205,11 @@ public class OutputWordUtil {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 输出文档路径及名称
|
||||
File outFile = new File(docName);
|
||||
Writer out = null;
|
||||
@ -225,6 +230,138 @@ public class OutputWordUtil {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
System.out.println("repositoryId==============="+repositoryId);
|
||||
|
||||
/*****************************************************************************/
|
||||
System.out.println("outFile.getPath()================"+outFile.getPath());
|
||||
Document doc = new Document(outFile.getPath());
|
||||
|
||||
Section section = doc.getLastSection();
|
||||
UpFileDao upFileDao = new UpFileDao();
|
||||
UserContext userContext = DispatcherRequest.getUserContext();
|
||||
PALRepositoryModel repositoryModel = PALRepositoryQueryAPIManager.getInstance().queryPalRepositoryModelByPalId(repositoryId);
|
||||
DCContext dcContextModel = null;
|
||||
List<UpfileModel> search = upFileDao.searchByRepositoryId(repositoryModel.getId(), "f");
|
||||
|
||||
|
||||
|
||||
//读取模型附件插入手册中文档对象
|
||||
if (search != null && search.size() > 0) {
|
||||
|
||||
//附件如果为空,不插入附件标题
|
||||
CharacterFormat format4 = new CharacterFormat();
|
||||
//创建字体格式
|
||||
format4.setFontName("宋体");
|
||||
//添加段落
|
||||
Paragraph paragraph4 = section.addParagraph();
|
||||
|
||||
ParagraphFormat paragraphFormat4 = paragraph4.getFormat();
|
||||
paragraphFormat4.setHorizontalAlignment(Left);
|
||||
|
||||
TextRange tr4 = paragraph4.appendText("附件");
|
||||
|
||||
|
||||
tr4.getCharacterFormat().setBold(true);
|
||||
tr4.getCharacterFormat().setFontName("宋体");
|
||||
tr4.getCharacterFormat().setFontSize(12);
|
||||
paragraph4.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式
|
||||
|
||||
|
||||
long b1 = System.currentTimeMillis();
|
||||
|
||||
for (UpfileModel upfileModel : search) {
|
||||
DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE);
|
||||
if (dcProfile != null) {
|
||||
|
||||
// 处理DocCenter
|
||||
dcContextModel = new DCContext(userContext, dcProfile, CoEConstant.APP_ID, "file", upfileModel.getPl_uuid(), upfileModel.getFileName());
|
||||
//添加段落
|
||||
Paragraph paragraph5 = section.addParagraph();
|
||||
//加载一个图片,它将作为外部文件的符号显示在Word文档中
|
||||
//获取最后一个.的位置
|
||||
int lastIndexOf = dcContextModel.getFileName().lastIndexOf(".");
|
||||
//获取文件的后缀名 .jpg
|
||||
String suffix = dcContextModel.getFileName().substring(lastIndexOf);
|
||||
|
||||
DocPicture pdfIcon = new DocPicture(doc);
|
||||
|
||||
InputStream stream1 = new FileInputStream(dcContextModel.getFilePath());
|
||||
DocPicture pic1 = new DocPicture(doc);
|
||||
|
||||
if (suffix.equals(".doc") || suffix.equals(".docx")) {
|
||||
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/word.png");
|
||||
paragraph5.appendText(dcContextModel.getFileName()+" ");
|
||||
if (suffix.equals(".doc")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "doc");
|
||||
} else if (suffix.equals(".docx")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "docx");
|
||||
}
|
||||
} else if (suffix.equals(".pdf")) {
|
||||
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/pdf.png");
|
||||
paragraph5.appendText(dcContextModel.getFileName()+" ");
|
||||
paragraph5.appendOleObject(stream1, pic1, "pdf");
|
||||
} else if (suffix.equals(".xls") || suffix.equals(".xlsx")) {
|
||||
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/xls.png");
|
||||
paragraph5.appendText(dcContextModel.getFileName()+" ");
|
||||
if (suffix.equals(".xls")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "xls");
|
||||
} else if (suffix.equals(".xlsx")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "xlsx");
|
||||
}
|
||||
} else if (suffix.equals(".png") || suffix.equals(".jgp")) {
|
||||
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/png.png");
|
||||
paragraph5.appendText(dcContextModel.getFileName()+" ");
|
||||
if (suffix.equals(".png")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "png");
|
||||
} else if (suffix.equals(".jpg")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "jpg");
|
||||
}
|
||||
} else if (suffix.equals(".zip") || suffix.equals(".rar")) {
|
||||
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/zip.png");
|
||||
paragraph5.appendText(dcContextModel.getFileName()+" ");
|
||||
if (suffix.equals(".zip")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "zip");
|
||||
} else if (suffix.equals(".rar")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "rar");
|
||||
}
|
||||
} else if (suffix.equals(".mp3") || suffix.equals(".mp4")) {
|
||||
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/mp3.png");
|
||||
paragraph5.appendText(dcContextModel.getFileName()+" ");
|
||||
if (suffix.equals(".mp3")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "mp3");
|
||||
} else if (suffix.equals(".mp4")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "mp4");
|
||||
}
|
||||
} else if (suffix.equals(".ppt") || suffix.equals(".pptx")) {
|
||||
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/ppt.png");
|
||||
paragraph5.appendText(dcContextModel.getFileName()+" ");
|
||||
if (suffix.equals(".ppt")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "ppt");
|
||||
} else if (suffix.equals(".pptx")) {
|
||||
paragraph5.appendOleObject(stream1, pic1, "pptx");
|
||||
}
|
||||
} else if (suffix.equals(".txt")) {
|
||||
pic1.loadImage("../doccenter/com.awspaas.user.apps.coe.pal.output.zd/filepic/txt.png");
|
||||
paragraph5.appendText(dcContextModel.getFileName()+" ");
|
||||
paragraph5.appendOleObject(stream1, pic1, "txt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
try {
|
||||
doc.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// 关闭文档对象
|
||||
doc.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -286,9 +423,7 @@ public class OutputWordUtil {
|
||||
result.put("content", "");
|
||||
|
||||
PALRepositoryModel repositoryModel = PALRepositoryQueryAPIManager.getInstance().queryPalRepositoryModelByPalId(repositoryId);
|
||||
if (repositoryModel == null) {
|
||||
|
||||
}
|
||||
String content = "";
|
||||
StringBuilder listStr = new StringBuilder();
|
||||
// 读取附件
|
||||
@ -1109,11 +1244,28 @@ public class OutputWordUtil {
|
||||
//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();
|
||||
}
|
||||
|
||||
@ -1200,16 +1352,29 @@ public class OutputWordUtil {
|
||||
dataRow.setHeightType(TableRowHeightType.Auto);
|
||||
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(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]);
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user