fix: 用例导出优化
This commit is contained in:
parent
082c634611
commit
c2cef4bd70
|
@ -1,8 +1,11 @@
|
||||||
package io.metersphere.excel.utils;
|
package io.metersphere.excel.utils;
|
||||||
|
|
||||||
import com.alibaba.excel.EasyExcel;
|
import com.alibaba.excel.EasyExcel;
|
||||||
|
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
|
||||||
|
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
|
||||||
import io.metersphere.commons.utils.LogUtil;
|
import io.metersphere.commons.utils.LogUtil;
|
||||||
import io.metersphere.exception.ExcelException;
|
import io.metersphere.exception.ExcelException;
|
||||||
|
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -29,9 +32,12 @@ public class EasyExcelExporter {
|
||||||
public void export(HttpServletResponse response, List data, String fileName, String sheetName) {
|
public void export(HttpServletResponse response, List data, String fileName, String sheetName) {
|
||||||
response.setContentType("application/vnd.ms-excel");
|
response.setContentType("application/vnd.ms-excel");
|
||||||
response.setCharacterEncoding("utf-8");
|
response.setCharacterEncoding("utf-8");
|
||||||
|
WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
|
||||||
|
contentWriteCellStyle.setWrapped(true);
|
||||||
try {
|
try {
|
||||||
|
HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(null, contentWriteCellStyle);
|
||||||
response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xlsx");
|
response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xlsx");
|
||||||
EasyExcel.write(response.getOutputStream(), this.clazz).sheet(sheetName).doWrite(data);
|
EasyExcel.write(response.getOutputStream(), this.clazz).registerWriteHandler(horizontalCellStyleStrategy).sheet(sheetName).doWrite(data);
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
LogUtil.error(e.getMessage(), e);
|
LogUtil.error(e.getMessage(), e);
|
||||||
throw new ExcelException("Utf-8 encoding is not supported");
|
throw new ExcelException("Utf-8 encoding is not supported");
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<el-dialog :close-on-click-modal="false"
|
<el-dialog :close-on-click-modal="false"
|
||||||
@close="close"
|
@close="close"
|
||||||
:title="operationType == 'edit' ? ( readOnly ? $t('test_track.case.view_case') : $t('test_track.case.edit_case')) : $t('test_track.case.create')"
|
:title="operationType == 'edit' ? ( readOnly ? $t('test_track.case.view_case') : $t('test_track.case.edit_case')) : $t('test_track.case.create')"
|
||||||
:visible.sync="dialogFormVisible" width="65%" :close-on-click-modal="false">
|
:visible.sync="dialogFormVisible" width="65%">
|
||||||
|
|
||||||
<el-form :model="form" :rules="rules" ref="caseFrom" v-loading="result.loading">
|
<el-form :model="form" :rules="rules" ref="caseFrom" v-loading="result.loading">
|
||||||
|
|
||||||
|
@ -352,8 +352,8 @@ export default {
|
||||||
handleAddStep(index, data) {
|
handleAddStep(index, data) {
|
||||||
let step = {};
|
let step = {};
|
||||||
step.num = data.num + 1;
|
step.num = data.num + 1;
|
||||||
step.desc = null;
|
step.desc = "";
|
||||||
step.result = null;
|
step.result = "";
|
||||||
this.form.steps.forEach(step => {
|
this.form.steps.forEach(step => {
|
||||||
if (step.num > data.num) {
|
if (step.num > data.num) {
|
||||||
step.num++;
|
step.num++;
|
||||||
|
|
Loading…
Reference in New Issue