Commit 96c855de authored by gaoyingwei's avatar gaoyingwei

修改 导入模板设置文本格式

parent ad580498
......@@ -226,7 +226,9 @@ public class FcryController extends BaseController
// List<String> fcList = fkqkService.selectFc();
// String[] fc = fcList.toArray(new String[]{});
// ExcelUtil.setClassExcelAttribute( clazz,"fcPlace","combo",fc);
util.importTemplateExcel(response, "方舱人员导入模板");
//设置文本格式表头在第几列
String columes = "3";
util.importTemplateExcelSetHead(response, "方舱人员导入模板",columes);
}
/**
......
......@@ -135,9 +135,9 @@ public class GldryController extends BaseController
// String[] streetTown=street_town.stream().map(SysDictData::getDictLabel).toArray(String[]::new);
// ExcelUtil.setClassExcelAttribute(clazz,"street","combo",streetTown);
//
// 设置 居委会 下拉框(暂无该数据字典)
util.importTemplateExcel(response,"隔离点人员数据导入空模板");
//设置文本格式表头在第几列
String columes = "3";
util.importTemplateExcelSetHead(response,"隔离点人员数据导入空模板",columes);
}
@Log(title = "导入隔离点人员数据",businessType = BusinessType.IMPORT)
......
......@@ -102,8 +102,9 @@ public class HscjController extends BaseController
// 设置 检测结果 下拉框
String[] resList = new String[]{"阳性","阴性"};
ExcelUtil.setClassExcelAttribute(clazz,"cjResult","combo",resList);
util.importTemplateExcel(response,"核酸采集导入空模板");
//设置文本格式表头在第几列
String columes = "7,8,10";
util.importTemplateExcelSetHead(response,"核酸采集导入空模板",columes);
}
@Log(title = "导入核算采集数据",businessType = BusinessType.IMPORT)
......
......@@ -160,8 +160,9 @@ public class YcsbController extends BaseController
// 是否做核酸
String[] hasAcid = new String[]{"是", "否"};
ExcelUtil.setClassExcelAttribute( clazz,"hasAcid","combo",hasAcid);
util.importTemplateExcel(response,"抗原异常上报");
//设置文本格式表头在第几列
String columes = "3";
util.importTemplateExcelSetHead(response,"抗原异常上报",columes);
}
/**
......
......@@ -164,7 +164,9 @@ public class YxryController extends BaseController
// ExcelUtil.setClassExcelAttribute( clazz,"isControl","combo",isControl);
ExcelUtil.setClassExcelAttribute( clazz,"isHome","combo",isHome);
// ExcelUtil.setClassExcelAttribute( clazz,"glPlace","combo",glPlace);
util.importTemplateExcel(response, "阳性人员");
//设置文本格式表头在第几列
String columes = "12";
util.importTemplateExcelSetHead(response, "阳性人员",columes);
}
@Log(title = "导入阳性人员", businessType = BusinessType.IMPORT)
......
......@@ -32,27 +32,7 @@ import org.apache.poi.hssf.usermodel.HSSFShape;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.DataValidation;
import org.apache.poi.ss.usermodel.DataValidationConstraint;
import org.apache.poi.ss.usermodel.DataValidationHelper;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Name;
import org.apache.poi.ss.usermodel.PictureData;
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.WorkbookFactory;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.util.IOUtils;
......@@ -531,7 +511,7 @@ public class ExcelUtil<T>
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
this.init(list, sheetName, title, Type.EXPORT);
exportExcel(response);
exportExcel(response, StringUtils.EMPTY);
}
/**
......@@ -566,7 +546,18 @@ public class ExcelUtil<T>
*/
public void importTemplateExcel(HttpServletResponse response, String sheetName)
{
importTemplateExcel(response, sheetName, StringUtils.EMPTY);
importTemplateExcel(response, sheetName, StringUtils.EMPTY, StringUtils.EMPTY);
}
/**
* 对list数据源将其里面的数据导入到excel表单
*
* @param sheetName 工作表的名称
* @return 结果
*/
public void importTemplateExcelSetHead(HttpServletResponse response, String sheetName,String columes)
{
importTemplateExcel(response, sheetName, StringUtils.EMPTY,columes);
}
/**
......@@ -576,12 +567,12 @@ public class ExcelUtil<T>
* @param title 标题
* @return 结果
*/
public void importTemplateExcel(HttpServletResponse response, String sheetName, String title)
public void importTemplateExcel(HttpServletResponse response, String sheetName, String title, String columes)
{
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
this.init(null, sheetName, title, Type.IMPORT);
exportExcel(response);
exportExcel(response,columes);
}
/**
......@@ -589,11 +580,11 @@ public class ExcelUtil<T>
*
* @return 结果
*/
public void exportExcel(HttpServletResponse response)
public void exportExcel(HttpServletResponse response, String columes)
{
try
{
writeSheet();
writeSheet(columes);
wb.write(response.getOutputStream());
}
catch (Exception e)
......@@ -616,7 +607,7 @@ public class ExcelUtil<T>
OutputStream out = null;
try
{
writeSheet();
writeSheet(StringUtils.EMPTY);
String filename = encodingFilename(sheetName);
out = new FileOutputStream(getAbsoluteFile(filename));
wb.write(out);
......@@ -637,7 +628,7 @@ public class ExcelUtil<T>
/**
* 创建写入数据到Sheet
*/
public void writeSheet()
public void writeSheet(String columes)
{
// 取出一共有多少个sheet.
int sheetNo = Math.max(1, (int) Math.ceil(list.size() * 1.0 / sheetSize));
......@@ -671,6 +662,20 @@ public class ExcelUtil<T>
fillExcelData(index, row);
addStatisticsRow();
}
if (Type.IMPORT.equals(type))
{
String[] colume= columes.split(",");
for (String c : colume) {
CellStyle textStyle = wb.createCellStyle();
DataFormat format = wb.createDataFormat();
//设置文本格式
textStyle.setDataFormat(format.getFormat("@"));
textStyle.setWrapText(true);
textStyle.setAlignment(HorizontalAlignment.CENTER); //水平居中
textStyle.setVerticalAlignment(VerticalAlignment.CENTER); //垂直居中
sheet.setDefaultColumnStyle(Integer.parseInt(c), textStyle);
}
}
}
}
......
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