|
@@ -1,7 +1,12 @@
|
|
package cn.cslg.wdc.service;
|
|
package cn.cslg.wdc.service;
|
|
|
|
|
|
import cn.cslg.wdc.common.core.auth.Response;
|
|
import cn.cslg.wdc.common.core.auth.Response;
|
|
|
|
+import cn.cslg.wdc.common.utils.ExcelUtils;
|
|
|
|
+import cn.cslg.wdc.common.utils.FileUtils;
|
|
|
|
+import cn.cslg.wdc.dto.CompareDetailWordDTO;
|
|
|
|
+import cn.cslg.wdc.dto.CompareWordDTO;
|
|
import cn.cslg.wdc.dto.DiscrepancyIdDTO;
|
|
import cn.cslg.wdc.dto.DiscrepancyIdDTO;
|
|
|
|
+import cn.cslg.wdc.dto.common.SectionDiffCommandVisitor;
|
|
import cn.cslg.wdc.entity.AssoCaseFile;
|
|
import cn.cslg.wdc.entity.AssoCaseFile;
|
|
import cn.cslg.wdc.entity.CaseFile;
|
|
import cn.cslg.wdc.entity.CaseFile;
|
|
import cn.cslg.wdc.entity.Discrepancy;
|
|
import cn.cslg.wdc.entity.Discrepancy;
|
|
@@ -15,11 +20,36 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.commons.io.output.ByteArrayOutputStream;
|
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.apache.commons.text.diff.EditScript;
|
|
|
|
+import org.apache.commons.text.diff.StringsComparator;
|
|
|
|
+import org.apache.poi.hssf.usermodel.*;
|
|
|
|
+import org.apache.poi.hssf.util.HSSFColor;
|
|
|
|
+import org.apache.poi.ss.usermodel.FillPatternType;
|
|
|
|
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
|
|
|
+import org.apache.poi.ss.usermodel.VerticalAlignment;
|
|
|
|
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
|
|
+import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
|
|
|
+import org.jsoup.Jsoup;
|
|
|
|
+import org.jsoup.nodes.Document;
|
|
|
|
+import org.jsoup.nodes.Element;
|
|
|
|
+import org.jsoup.nodes.Node;
|
|
|
|
+import org.jsoup.select.Elements;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileInputStream;
|
|
|
|
+import java.io.FileNotFoundException;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.math.RoundingMode;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@@ -64,4 +94,553 @@ public class DiscrepancyService extends ServiceImpl<DiscrepancyMapper, Discrepan
|
|
infoVO.setDiscrepancyDetails(discrepancyDetails);
|
|
infoVO.setDiscrepancyDetails(discrepancyDetails);
|
|
return Response.success(infoVO);
|
|
return Response.success(infoVO);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public void compare(String fileName, String fileName1, String fileName2, String fileName3, String fileName4) throws Exception {
|
|
|
|
+ CompareWordDTO compareWordDTO = new CompareWordDTO();
|
|
|
|
+ List<String> list = this.getWordContent(fileName);
|
|
|
|
+ List<String> list1 = this.getWordContent(fileName1);
|
|
|
|
+ List<String> list2 = this.getWordContent(fileName2);
|
|
|
|
+ List<String> list3 = this.getWordContent(fileName3);
|
|
|
|
+ List<String> list4 = this.getWordContent(fileName4);
|
|
|
|
+
|
|
|
|
+ List<String> collect = list.stream().distinct().collect(Collectors.toList());
|
|
|
|
+ List<String> collect1 = list1.stream().distinct().collect(Collectors.toList());
|
|
|
|
+ List<String> collect2 = list2.stream().distinct().collect(Collectors.toList());
|
|
|
|
+ List<String> collect3 = list3.stream().distinct().collect(Collectors.toList());
|
|
|
|
+ List<String> collect4 = list4.stream().distinct().collect(Collectors.toList());
|
|
|
|
+ System.out.println("First Text:" + StringUtils.join(collect, "").length());
|
|
|
|
+
|
|
|
|
+ List<CompareDetailWordDTO> wordDTOS = new ArrayList<>();
|
|
|
|
+ collect.forEach(i -> {
|
|
|
|
+ CompareDetailWordDTO dto = new CompareDetailWordDTO();
|
|
|
|
+ List<String> strings = new ArrayList<>();
|
|
|
|
+ strings.add(fileName.substring(36));
|
|
|
|
+ dto.setFileName(strings);
|
|
|
|
+ dto.setParagraphText(i);
|
|
|
|
+ dto.setParagraphNum(i.length());
|
|
|
|
+ wordDTOS.add(dto);
|
|
|
|
+ });
|
|
|
|
+ compareWordDTO.setList(wordDTOS);
|
|
|
|
+ compareWordDTO.setNumber(StringUtils.join(collect, "").length());
|
|
|
|
+// List<CompareDetailWordDTO> wordDTOS1 = new ArrayList<>();
|
|
|
|
+// collect1.removeAll(collect);
|
|
|
|
+ System.out.println("Second Text:" + StringUtils.join(collect1, "").length());
|
|
|
|
+ collect1.forEach(i -> {
|
|
|
|
+ if (collect.contains(i)) {
|
|
|
|
+ CompareDetailWordDTO wordDTO = wordDTOS.stream().filter(j -> j.getParagraphText().equals(i)).findFirst().orElse(null);
|
|
|
|
+ if (ObjectUtils.isNotEmpty(wordDTO)) {
|
|
|
|
+ List<String> strings = wordDTO.getFileName();
|
|
|
|
+ strings.add(fileName1.substring(36));
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ CompareDetailWordDTO dto = new CompareDetailWordDTO();
|
|
|
|
+ List<String> strings = new ArrayList<>();
|
|
|
|
+ strings.add(fileName1.substring(36));
|
|
|
|
+ dto.setFileName(strings);
|
|
|
|
+ dto.setParagraphText(i);
|
|
|
|
+ dto.setParagraphNum(i.length());
|
|
|
|
+ wordDTOS.add(dto);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+// compareWordDTO.setList1(wordDTOS1);
|
|
|
|
+ compareWordDTO.setNumber1(StringUtils.join(collect1, "").length());
|
|
|
|
+// List<CompareDetailWordDTO> wordDTOS2 = new ArrayList<>();
|
|
|
|
+// collect2.removeAll(collect);
|
|
|
|
+// collect2.removeAll(collect1);
|
|
|
|
+ collect2.forEach(i -> {
|
|
|
|
+ if (collect.contains(i) || collect1.contains(i)) {
|
|
|
|
+ CompareDetailWordDTO wordDTO = wordDTOS.stream().filter(j -> j.getParagraphText().equals(i)).findFirst().orElse(null);
|
|
|
|
+ if (ObjectUtils.isNotEmpty(wordDTO)) {
|
|
|
|
+ List<String> strings = wordDTO.getFileName();
|
|
|
|
+ strings.add(fileName2.substring(36));
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ CompareDetailWordDTO dto = new CompareDetailWordDTO();
|
|
|
|
+ List<String> strings = new ArrayList<>();
|
|
|
|
+ strings.add(fileName2.substring(36));
|
|
|
|
+ dto.setFileName(strings);
|
|
|
|
+ dto.setParagraphText(i);
|
|
|
|
+ dto.setParagraphNum(i.length());
|
|
|
|
+ wordDTOS.add(dto);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+// compareWordDTO.setList2(wordDTOS2);
|
|
|
|
+ compareWordDTO.setNumber2(StringUtils.join(collect2, "").length());
|
|
|
|
+// List<CompareDetailWordDTO> wordDTOS3 = new ArrayList<>();
|
|
|
|
+// collect3.removeAll(collect);
|
|
|
|
+// collect3.removeAll(collect1);
|
|
|
|
+// collect3.removeAll(collect2);
|
|
|
|
+ collect3.forEach(i -> {
|
|
|
|
+ if (collect.contains(i) || collect1.contains(i) || collect2.contains(i)) {
|
|
|
|
+ CompareDetailWordDTO wordDTO = wordDTOS.stream().filter(j -> j.getParagraphText().equals(i)).findFirst().orElse(null);
|
|
|
|
+ if (ObjectUtils.isNotEmpty(wordDTO)) {
|
|
|
|
+ List<String> strings = wordDTO.getFileName();
|
|
|
|
+ strings.add(fileName3.substring(36));
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ CompareDetailWordDTO dto = new CompareDetailWordDTO();
|
|
|
|
+ List<String> strings = new ArrayList<>();
|
|
|
|
+ strings.add(fileName3.substring(36));
|
|
|
|
+ dto.setFileName(strings);
|
|
|
|
+ dto.setParagraphText(i);
|
|
|
|
+ dto.setParagraphNum(i.length());
|
|
|
|
+ wordDTOS.add(dto);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+// compareWordDTO.setList3(wordDTOS3);
|
|
|
|
+ compareWordDTO.setNumber3(StringUtils.join(collect3, "").length());
|
|
|
|
+// List<CompareDetailWordDTO> wordDTOS4 = new ArrayList<>();
|
|
|
|
+// collect4.removeAll(collect);
|
|
|
|
+// collect4.removeAll(collect1);
|
|
|
|
+// collect4.removeAll(collect2);
|
|
|
|
+// collect4.removeAll(collect3);
|
|
|
|
+ collect4.forEach(i -> {
|
|
|
|
+ if (collect.contains(i) || collect1.contains(i) || collect2.contains(i) || collect3.contains(i)) {
|
|
|
|
+ CompareDetailWordDTO wordDTO = wordDTOS.stream().filter(j -> j.getParagraphText().equals(i)).findFirst().orElse(null);
|
|
|
|
+ if (ObjectUtils.isNotEmpty(wordDTO)) {
|
|
|
|
+ List<String> strings = wordDTO.getFileName();
|
|
|
|
+ strings.add(fileName4.substring(36));
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ CompareDetailWordDTO dto = new CompareDetailWordDTO();
|
|
|
|
+ List<String> strings = new ArrayList<>();
|
|
|
|
+ strings.add(fileName4.substring(36));
|
|
|
|
+ dto.setFileName(strings);
|
|
|
|
+ dto.setParagraphText(i);
|
|
|
|
+ dto.setParagraphNum(i.length());
|
|
|
|
+ wordDTOS.add(dto);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+// compareWordDTO.setList4(wordDTOS4);
|
|
|
|
+ compareWordDTO.setNumber4(StringUtils.join(collect4, "").length());
|
|
|
|
+ int sum = this.getNumber(collect) + this.getNumber(collect1)
|
|
|
|
+ + this.getNumber(collect2) + this.getNumber(collect3) + this.getNumber(collect4);
|
|
|
|
+ compareWordDTO.setList(wordDTOS);
|
|
|
|
+ compareWordDTO.setTotal(sum);
|
|
|
|
+ System.out.println("Total Text:" + sum);
|
|
|
|
+ this.loadExport5(compareWordDTO);
|
|
|
|
+
|
|
|
|
+// System.out.println(compareWordDTO);
|
|
|
|
+// this.loadExport(compareWordDTO,"第一篇翻译汇总");
|
|
|
|
+// this.loadExport1(compareWordDTO,"第二篇翻译汇总");
|
|
|
|
+// this.loadExport2(compareWordDTO,"第三篇翻译汇总");
|
|
|
|
+// this.loadExport3(compareWordDTO,"第四篇翻译汇总");
|
|
|
|
+// this.loadExport4(compareWordDTO,"第五篇翻译汇总");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<String> getWordContent(String fileName) throws IOException {
|
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
|
+ XWPFDocument document = new XWPFDocument(new FileInputStream(fileName));
|
|
|
|
+ List<XWPFParagraph> paragraphs = document.getParagraphs();
|
|
|
|
+ for (XWPFParagraph paragraph : paragraphs) {
|
|
|
|
+ final String s = paragraph.getText().trim();
|
|
|
|
+ if (StringUtils.isNotEmpty(s)) {
|
|
|
|
+ list.add(s);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Integer getNumber(List<String> list) {
|
|
|
|
+ int sum = 0;
|
|
|
|
+ for (String s : list) {
|
|
|
|
+ int length = s.length();
|
|
|
|
+ sum += length;
|
|
|
|
+ }
|
|
|
|
+ return sum;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void loadExport5(CompareWordDTO vo) throws Exception {
|
|
|
|
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
|
|
|
+ List<String> headers = Arrays.asList("文件内容", "翻译总数", "第一篇翻译数量","第二篇翻译数量","第三篇翻译数量","第四篇翻译数量","第五篇翻译数量",
|
|
|
|
+ "段落数量","出现过的文档");
|
|
|
|
+ HSSFWorkbook hssfWorkbook = new HSSFWorkbook();//新建工作簿
|
|
|
|
+ HSSFSheet sheet = hssfWorkbook.createSheet();//新建sheet页
|
|
|
|
+ sheet.setDefaultColumnWidth(30);
|
|
|
|
+ HSSFRow headerRow = sheet.createRow(0);//新建标头行
|
|
|
|
+ headerRow.setHeight((short) 500);
|
|
|
|
+ HSSFCellStyle headerCellStyle = hssfWorkbook.createCellStyle();//新建标头行格式
|
|
|
|
+ HSSFCellStyle commonCellStyle = hssfWorkbook.createCellStyle();//新建普通行格式
|
|
|
|
+ for (int i = 0; i < headers.size(); i++) {//遍历设置标头
|
|
|
|
+ HSSFCell cell = headerRow.createCell(i);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(headerCellStyle);
|
|
|
|
+ headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
+ headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
|
+ headerCellStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.SKY_BLUE.getIndex());
|
|
|
|
+ headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
|
+ headerCellStyle.setWrapText(true);
|
|
|
|
+ cell.setCellStyle(headerCellStyle);
|
|
|
|
+ cell.setCellValue(headers.get(i));
|
|
|
|
+ }
|
|
|
|
+ List<CompareDetailWordDTO> list = vo.getList();
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
+ CompareDetailWordDTO wordDTO = list.get(i);
|
|
|
|
+ HSSFRow row = sheet.createRow(i + 1);//新建一普通行
|
|
|
|
+ row.setHeight((short) 1000);
|
|
|
|
+
|
|
|
|
+ HSSFCell cell = row.createCell(0);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell.setCellStyle(commonCellStyle);
|
|
|
|
+ cell.setCellValue(wordDTO.getParagraphText());
|
|
|
|
+ HSSFCell cell1 = row.createCell(1);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell1.setCellStyle(commonCellStyle);
|
|
|
|
+ cell1.setCellValue(vo.getTotal());
|
|
|
|
+ HSSFCell cell2 = row.createCell(2);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell2.setCellStyle(commonCellStyle);
|
|
|
|
+ cell2.setCellValue(vo.getNumber());
|
|
|
|
+ HSSFCell cell3 = row.createCell(3);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell3.setCellStyle(commonCellStyle);
|
|
|
|
+ cell3.setCellValue(vo.getNumber1());
|
|
|
|
+ HSSFCell cell4 = row.createCell(4);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell4.setCellStyle(commonCellStyle);
|
|
|
|
+ cell4.setCellValue(vo.getNumber2());
|
|
|
|
+ HSSFCell cell5 = row.createCell(5);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell5.setCellStyle(commonCellStyle);
|
|
|
|
+ cell5.setCellValue(vo.getNumber3());
|
|
|
|
+ HSSFCell cell6 = row.createCell(6);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell6.setCellStyle(commonCellStyle);
|
|
|
|
+ cell6.setCellValue(vo.getNumber4());
|
|
|
|
+ HSSFCell cell7 = row.createCell(7);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell7.setCellStyle(commonCellStyle);
|
|
|
|
+ cell7.setCellValue(wordDTO.getParagraphNum());
|
|
|
|
+ HSSFCell cell8 = row.createCell(8);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell8.setCellStyle(commonCellStyle);
|
|
|
|
+ cell8.setCellValue(StringUtils.join(wordDTO.getFileName(), "\n"));
|
|
|
|
+ }
|
|
|
|
+ hssfWorkbook.write(out);
|
|
|
|
+ byte[] bytes = out.toByteArray();
|
|
|
|
+ FileUtils.getFileByBytes(bytes, "翻译汇总文档", ".xlsx");
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
+ throw new FileNotFoundException();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void loadExport(CompareWordDTO vo, String name) throws Exception {
|
|
|
|
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
|
|
|
+ List<String> headers = Arrays.asList("翻译总数", "翻译数量", "文件名称", "文件内容");
|
|
|
|
+ HSSFWorkbook hssfWorkbook = new HSSFWorkbook();//新建工作簿
|
|
|
|
+ HSSFSheet sheet = hssfWorkbook.createSheet();//新建sheet页
|
|
|
|
+ sheet.setDefaultColumnWidth(30);
|
|
|
|
+ HSSFRow headerRow = sheet.createRow(0);//新建标头行
|
|
|
|
+ headerRow.setHeight((short) 500);
|
|
|
|
+ HSSFCellStyle headerCellStyle = hssfWorkbook.createCellStyle();//新建标头行格式
|
|
|
|
+ HSSFCellStyle commonCellStyle = hssfWorkbook.createCellStyle();//新建普通行格式
|
|
|
|
+ for (int i = 0; i < headers.size(); i++) {//遍历设置标头
|
|
|
|
+ HSSFCell cell = headerRow.createCell(i);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(headerCellStyle);
|
|
|
|
+ headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
+ headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
|
+ headerCellStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.SKY_BLUE.getIndex());
|
|
|
|
+ headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
|
+ headerCellStyle.setWrapText(true);
|
|
|
|
+ cell.setCellStyle(headerCellStyle);
|
|
|
|
+ cell.setCellValue(headers.get(i));
|
|
|
|
+ }
|
|
|
|
+ List<String> list = vo.getList().stream().map(CompareDetailWordDTO::getParagraphText).collect(Collectors.toList());
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
+ String content = list.get(i);
|
|
|
|
+ HSSFRow row = sheet.createRow(i + 1);//新建一普通行
|
|
|
|
+ row.setHeight((short) 1000);
|
|
|
|
+ HSSFCell cell = row.createCell(0);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell.setCellStyle(commonCellStyle);
|
|
|
|
+ cell.setCellValue(vo.getTotal());
|
|
|
|
+ HSSFCell cell1 = row.createCell(1);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell1.setCellStyle(commonCellStyle);
|
|
|
|
+ cell1.setCellValue(vo.getNumber());
|
|
|
|
+ HSSFCell cell2 = row.createCell(2);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell2.setCellStyle(commonCellStyle);
|
|
|
|
+ cell2.setCellValue(vo.getNumber1());
|
|
|
|
+ HSSFCell cell3 = row.createCell(3);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell3.setCellStyle(commonCellStyle);
|
|
|
|
+ cell3.setCellValue(content);
|
|
|
|
+ }
|
|
|
|
+ hssfWorkbook.write(out);
|
|
|
|
+ byte[] bytes = out.toByteArray();
|
|
|
|
+ FileUtils.getFileByBytes(bytes, name, ".xlsx");
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
+ throw new FileNotFoundException();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ public void loadExport1(CompareWordDTO vo, String name) throws Exception {
|
|
|
|
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
|
|
|
+ List<String> headers = Arrays.asList("翻译总数", "翻译数量", "文件名称", "文件内容");
|
|
|
|
+ HSSFWorkbook hssfWorkbook = new HSSFWorkbook();//新建工作簿
|
|
|
|
+ HSSFSheet sheet = hssfWorkbook.createSheet();//新建sheet页
|
|
|
|
+ sheet.setDefaultColumnWidth(30);
|
|
|
|
+ HSSFRow headerRow = sheet.createRow(0);//新建标头行
|
|
|
|
+ headerRow.setHeight((short) 500);
|
|
|
|
+ HSSFCellStyle headerCellStyle = hssfWorkbook.createCellStyle();//新建标头行格式
|
|
|
|
+ HSSFCellStyle commonCellStyle = hssfWorkbook.createCellStyle();//新建普通行格式
|
|
|
|
+ for (int i = 0; i < headers.size(); i++) {//遍历设置标头
|
|
|
|
+ HSSFCell cell = headerRow.createCell(i);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(headerCellStyle);
|
|
|
|
+ headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
+ headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
|
+ headerCellStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.SKY_BLUE.getIndex());
|
|
|
|
+ headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
|
+ headerCellStyle.setWrapText(true);
|
|
|
|
+ cell.setCellStyle(headerCellStyle);
|
|
|
|
+ cell.setCellValue(headers.get(i));
|
|
|
|
+ }
|
|
|
|
+ List<String> list = vo.getList1().stream().map(CompareDetailWordDTO::getParagraphText).collect(Collectors.toList());
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
+ String content = list.get(i);
|
|
|
|
+ HSSFRow row = sheet.createRow(i + 1);//新建一普通行
|
|
|
|
+ row.setHeight((short) 1000);
|
|
|
|
+ HSSFCell cell = row.createCell(0);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell.setCellStyle(commonCellStyle);
|
|
|
|
+ cell.setCellValue(vo.getTotal());
|
|
|
|
+ HSSFCell cell1 = row.createCell(1);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell1.setCellStyle(commonCellStyle);
|
|
|
|
+ cell1.setCellValue(vo.getNumber1());
|
|
|
|
+ HSSFCell cell2 = row.createCell(2);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell2.setCellStyle(commonCellStyle);
|
|
|
|
+ cell2.setCellValue(vo.getNumber1());
|
|
|
|
+ HSSFCell cell3 = row.createCell(3);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell3.setCellStyle(commonCellStyle);
|
|
|
|
+ cell3.setCellValue(content);
|
|
|
|
+ }
|
|
|
|
+ hssfWorkbook.write(out);
|
|
|
|
+ byte[] bytes = out.toByteArray();
|
|
|
|
+ FileUtils.getFileByBytes(bytes, name, ".xlsx");
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
+ throw new FileNotFoundException();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ public void loadExport2(CompareWordDTO vo, String name) throws Exception {
|
|
|
|
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
|
|
|
+ List<String> headers = Arrays.asList("翻译总数", "翻译数量", "文件名称", "文件内容");
|
|
|
|
+ HSSFWorkbook hssfWorkbook = new HSSFWorkbook();//新建工作簿
|
|
|
|
+ HSSFSheet sheet = hssfWorkbook.createSheet();//新建sheet页
|
|
|
|
+ sheet.setDefaultColumnWidth(30);
|
|
|
|
+ HSSFRow headerRow = sheet.createRow(0);//新建标头行
|
|
|
|
+ headerRow.setHeight((short) 500);
|
|
|
|
+ HSSFCellStyle headerCellStyle = hssfWorkbook.createCellStyle();//新建标头行格式
|
|
|
|
+ HSSFCellStyle commonCellStyle = hssfWorkbook.createCellStyle();//新建普通行格式
|
|
|
|
+ for (int i = 0; i < headers.size(); i++) {//遍历设置标头
|
|
|
|
+ HSSFCell cell = headerRow.createCell(i);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(headerCellStyle);
|
|
|
|
+ headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
+ headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
|
+ headerCellStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.SKY_BLUE.getIndex());
|
|
|
|
+ headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
|
+ headerCellStyle.setWrapText(true);
|
|
|
|
+ cell.setCellStyle(headerCellStyle);
|
|
|
|
+ cell.setCellValue(headers.get(i));
|
|
|
|
+ }
|
|
|
|
+ List<String> list = vo.getList2().stream().map(CompareDetailWordDTO::getParagraphText).collect(Collectors.toList());
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
+ String content = list.get(i);
|
|
|
|
+ HSSFRow row = sheet.createRow(i + 1);//新建一普通行
|
|
|
|
+ row.setHeight((short) 1000);
|
|
|
|
+ HSSFCell cell = row.createCell(0);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell.setCellStyle(commonCellStyle);
|
|
|
|
+ cell.setCellValue(vo.getTotal());
|
|
|
|
+ HSSFCell cell1 = row.createCell(1);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell1.setCellStyle(commonCellStyle);
|
|
|
|
+ cell1.setCellValue(vo.getNumber2());
|
|
|
|
+ HSSFCell cell2 = row.createCell(2);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell2.setCellStyle(commonCellStyle);
|
|
|
|
+ cell2.setCellValue(vo.getNumber1());
|
|
|
|
+ HSSFCell cell3 = row.createCell(3);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell3.setCellStyle(commonCellStyle);
|
|
|
|
+ cell3.setCellValue(content);
|
|
|
|
+ }
|
|
|
|
+ hssfWorkbook.write(out);
|
|
|
|
+ byte[] bytes = out.toByteArray();
|
|
|
|
+ FileUtils.getFileByBytes(bytes, name, ".xlsx");
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
+ throw new FileNotFoundException();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ public void loadExport3(CompareWordDTO vo, String name) throws Exception {
|
|
|
|
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
|
|
|
+ List<String> headers = Arrays.asList("翻译总数", "翻译数量", "文件名称", "文件内容");
|
|
|
|
+ HSSFWorkbook hssfWorkbook = new HSSFWorkbook();//新建工作簿
|
|
|
|
+ HSSFSheet sheet = hssfWorkbook.createSheet();//新建sheet页
|
|
|
|
+ sheet.setDefaultColumnWidth(30);
|
|
|
|
+ HSSFRow headerRow = sheet.createRow(0);//新建标头行
|
|
|
|
+ headerRow.setHeight((short) 500);
|
|
|
|
+ HSSFCellStyle headerCellStyle = hssfWorkbook.createCellStyle();//新建标头行格式
|
|
|
|
+ HSSFCellStyle commonCellStyle = hssfWorkbook.createCellStyle();//新建普通行格式
|
|
|
|
+ for (int i = 0; i < headers.size(); i++) {//遍历设置标头
|
|
|
|
+ HSSFCell cell = headerRow.createCell(i);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(headerCellStyle);
|
|
|
|
+ headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
+ headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
|
+ headerCellStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.SKY_BLUE.getIndex());
|
|
|
|
+ headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
|
+ headerCellStyle.setWrapText(true);
|
|
|
|
+ cell.setCellStyle(headerCellStyle);
|
|
|
|
+ cell.setCellValue(headers.get(i));
|
|
|
|
+ }
|
|
|
|
+ List<String> list = vo.getList3().stream().map(CompareDetailWordDTO::getParagraphText).collect(Collectors.toList());
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
+ String content = list.get(i);
|
|
|
|
+ HSSFRow row = sheet.createRow(i + 1);//新建一普通行
|
|
|
|
+ row.setHeight((short) 1000);
|
|
|
|
+ HSSFCell cell = row.createCell(0);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell.setCellStyle(commonCellStyle);
|
|
|
|
+ cell.setCellValue(vo.getTotal());
|
|
|
|
+ HSSFCell cell1 = row.createCell(1);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell1.setCellStyle(commonCellStyle);
|
|
|
|
+ cell1.setCellValue(vo.getNumber3());
|
|
|
|
+ HSSFCell cell2 = row.createCell(2);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell2.setCellStyle(commonCellStyle);
|
|
|
|
+ cell2.setCellValue(vo.getNumber1());
|
|
|
|
+ HSSFCell cell3 = row.createCell(3);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell3.setCellStyle(commonCellStyle);
|
|
|
|
+ cell3.setCellValue(content);
|
|
|
|
+ }
|
|
|
|
+ hssfWorkbook.write(out);
|
|
|
|
+ byte[] bytes = out.toByteArray();
|
|
|
|
+ FileUtils.getFileByBytes(bytes, name, ".xlsx");
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
+ throw new FileNotFoundException();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ public void loadExport4(CompareWordDTO vo, String name) throws Exception {
|
|
|
|
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
|
|
|
+ List<String> headers = Arrays.asList("翻译总数", "翻译数量", "文件名称", "文件内容");
|
|
|
|
+ HSSFWorkbook hssfWorkbook = new HSSFWorkbook();//新建工作簿
|
|
|
|
+ HSSFSheet sheet = hssfWorkbook.createSheet();//新建sheet页
|
|
|
|
+ sheet.setDefaultColumnWidth(30);
|
|
|
|
+ HSSFRow headerRow = sheet.createRow(0);//新建标头行
|
|
|
|
+ headerRow.setHeight((short) 500);
|
|
|
|
+ HSSFCellStyle headerCellStyle = hssfWorkbook.createCellStyle();//新建标头行格式
|
|
|
|
+ HSSFCellStyle commonCellStyle = hssfWorkbook.createCellStyle();//新建普通行格式
|
|
|
|
+ for (int i = 0; i < headers.size(); i++) {//遍历设置标头
|
|
|
|
+ HSSFCell cell = headerRow.createCell(i);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(headerCellStyle);
|
|
|
|
+ headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
+ headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
|
+ headerCellStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.SKY_BLUE.getIndex());
|
|
|
|
+ headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
|
+ headerCellStyle.setWrapText(true);
|
|
|
|
+ cell.setCellStyle(headerCellStyle);
|
|
|
|
+ cell.setCellValue(headers.get(i));
|
|
|
|
+ }
|
|
|
|
+ List<String> list = vo.getList4().stream().map(CompareDetailWordDTO::getParagraphText).collect(Collectors.toList());
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
+ String content = list.get(i);
|
|
|
|
+ HSSFRow row = sheet.createRow(i + 1);//新建一普通行
|
|
|
|
+ row.setHeight((short) 1000);
|
|
|
|
+ HSSFCell cell = row.createCell(0);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell.setCellStyle(commonCellStyle);
|
|
|
|
+ cell.setCellValue(vo.getTotal());
|
|
|
|
+ HSSFCell cell1 = row.createCell(1);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell1.setCellStyle(commonCellStyle);
|
|
|
|
+ cell1.setCellValue(vo.getNumber4());
|
|
|
|
+ HSSFCell cell2 = row.createCell(2);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell2.setCellStyle(commonCellStyle);
|
|
|
|
+ cell2.setCellValue(vo.getNumber1());
|
|
|
|
+ HSSFCell cell3 = row.createCell(3);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell3.setCellStyle(commonCellStyle);
|
|
|
|
+ cell3.setCellValue(content);
|
|
|
|
+ }
|
|
|
|
+ hssfWorkbook.write(out);
|
|
|
|
+ byte[] bytes = out.toByteArray();
|
|
|
|
+ FileUtils.getFileByBytes(bytes, name, ".xlsx");
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
+ throw new FileNotFoundException();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|