Commit ba3488c5 authored by 竹天卫's avatar 竹天卫

下标问题处理

parent 0ae88aa1
......@@ -114,7 +114,16 @@
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.oschina.zcx7878/fastdfs-client-java -->
<dependency>
......
package cn.wise.sc.cement.business.controller;
import cn.wise.sc.cement.business.enumation.FileExt;
import cn.wise.sc.cement.business.model.BaseResponse;
import cn.wise.sc.cement.business.model.PageQuery;
import cn.wise.sc.cement.business.model.query.*;
import cn.wise.sc.cement.business.model.vo.EntrustVo;
import cn.wise.sc.cement.business.model.vo.SampleDistributionTeamVo;
import cn.wise.sc.cement.business.model.vo.SampleVo;
import cn.wise.sc.cement.business.service.IEntrustService;
import cn.wise.sc.cement.business.util.WordUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* <p>
* 前端控制器
* </p>
*
* @author ztw
* @since 2021-01-12
*/
@Api(tags = "数据统计")
@RestController
@RequestMapping("/business/dataStatistics")
public class DataStatisticsController {
private static final Logger log = LoggerFactory.getLogger("DataStatisticsController");
}
......@@ -3071,10 +3071,10 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl
Team team = teamMapper.selectById(Integer.valueOf(teamId));
if (team != null && team.getQualifications() == 1) {
String teamName = team.getName();
if(team.getName().contains("<sub>") || team.getName().contains("</sub>") ){
/*if(team.getName().contains("<sub>") || team.getName().contains("</sub>") ){
teamName = team.getName().replaceAll("<sub>","")
.replaceAll("</sub>","");
}
}*/
checkTeam = checkTeam.equals("") ? teamName : (checkTeam + "、" + teamName);
Method method = methodMapper.selectById(team.getMethodId());
if (method != null) {
......
......@@ -9,15 +9,17 @@ import java.util.List;
import javax.servlet.http.HttpServletResponse;
import cn.afterturn.easypoi.excel.annotation.Excel;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.wp.usermodel.Paragraph;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
* excel工具类
......@@ -156,14 +158,12 @@ public class ExcelUtil {
* @return
*/
public static Workbook getWorkbook(String[] headers, List<Object[]> datas) {
Workbook workbook = new HSSFWorkbook();
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet();
Sheet sheet = workbook.createSheet();
Row row = null;
Cell cell = null;
Font font = workbook.createFont();
XSSFFont font = workbook.createFont();
int line = 0, maxColumn = 0;
if (headers != null && headers.length > 0) { // 设置列头
CellStyle style = workbook.createCellStyle();
......@@ -185,6 +185,8 @@ public class ExcelUtil {
if (datas != null && datas.size() > 0) {// 渲染数据
CellStyle style = workbook.createCellStyle();
XSSFFont xxsfFont = workbook.createFont();
xxsfFont.setTypeOffset(FontFormatting.SS_SUB);
for (int index = 0, size = datas.size(); index < size; index++) {
Object[] data = datas.get(index);
if (data != null && data.length > 0) {
......@@ -197,10 +199,20 @@ public class ExcelUtil {
}
for (int i = 0; i < length; i++) {
style.setWrapText(true); //关键
// style.setWrapText(true); //关键
cell = row.createCell(i);
cell.setCellValue(data[i] == null ? null : data[i].toString());
cell.setCellStyle(style);
//处理下标
if(cell.getStringCellValue().contains("<sub>") || cell.getStringCellValue().contains("</sub>") ){
cell.setCellStyle(style);
XSSFRichTextString richString = new XSSFRichTextString(cell.getStringCellValue().replaceAll("</sub>","<sub>").replaceAll("<sub>",""));
//提取下标位置
applyRichStringFont(cell.getStringCellValue(), richString, xxsfFont);
cell.setCellValue(richString);
}else{
cell.setCellStyle(style);
}
}
}
}
......@@ -213,6 +225,21 @@ public class ExcelUtil {
return workbook;
}
private static void applyRichStringFont(String sub, XSSFRichTextString richString,XSSFFont xxsfFont) {
String[] split = sub.replaceAll("</sub>", "<sub>").split("<sub>");
String it_str = "";
for (int i = 1; i < split.length + 1; i++) {
if (i % 2 != 0) {
it_str = it_str + split[i - 1];
} else {
richString.applyFont(it_str.length(),(it_str+split[i-1]).length()-1,xxsfFont);
it_str = it_str + split[i - 1];
}
}
}
public static Workbook getWorkbookNew(String[] headers, List<Object[]> datas) {
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet();
......
......@@ -393,6 +393,7 @@ cn\wise\sc\cement\business\controller\NonStandardApprovalController.class
cn\wise\sc\cement\business\model\vo\ProductionVo.class
cn\wise\sc\cement\business\service\impl\SysPostServiceImpl.class
cn\wise\sc\cement\business\entity\Entrust.class
cn\wise\sc\cement\business\controller\DataStatisticsController.class
cn\wise\sc\cement\business\controller\SysGroupController.class
cn\wise\sc\cement\business\controller\QualityController.class
cn\wise\sc\cement\business\model\query\ClientQuery.class
......
......@@ -261,6 +261,7 @@ D:\idea_workspases\tianjin-cement\cement-business\src\main\java\cn\wise\sc\cemen
D:\idea_workspases\tianjin-cement\cement-business\src\main\java\cn\wise\sc\cement\business\util\weixin\message\send\NewsMessage.java
D:\idea_workspases\tianjin-cement\cement-business\src\main\java\cn\wise\sc\cement\business\model\vo\PlanPeopleVo.java
D:\idea_workspases\tianjin-cement\cement-business\src\main\java\cn\wise\sc\cement\business\controller\SysPermissionController.java
D:\idea_workspases\tianjin-cement\cement-business\src\main\java\cn\wise\sc\cement\business\controller\DataStatisticsController.java
D:\idea_workspases\tianjin-cement\cement-business\src\main\java\cn\wise\sc\cement\business\service\INonStandardApprovalService.java
D:\idea_workspases\tianjin-cement\cement-business\src\main\java\cn\wise\sc\cement\business\service\IProjectService.java
D:\idea_workspases\tianjin-cement\cement-business\src\main\java\cn\wise\sc\cement\business\entity\Chinastd.java
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment