Excel导入保存附件和解析数据

一,前端上传附件的组件

1、先给一个下载模板的按钮

      // 下载Excel模板
downLoadExcel: function () {
window.open(GLOBAL_CONFIG.webSiteRoot + "/main/common/files/xxx.xls");
},

2、Element上传控件

              <el-upload ref="upload"
:action="importFileUrl"
:before-upload="beforeUpload"
:multiple="false"
:on-success="uploadSuccess"
:on-error="uploadFail"
:show-file-list="false"
style="display: inline-block;">
<el-button type="primary" icon="el-icon-plus" size="medium">导入Excel</el-button>
</el-upload>

3、js中上传有关

var vue = new Vue({
el: '#app',
data: {
// 导入的后台接口地址
importFileUrl : '/excellImport/importFile', methods:{
// 上传前对文件的类型和大小判断
beforeUpload : function (file) {
var self = this;
const extension = file.name.split('.')[1] === 'xls'
const extension2 = file.name.split('.')[1] === 'xlsx'
const isLt2M = file.size / 1024 / 1024 < 50
if (!extension && !extension2 ) {
alert('上传文件只能是 xls、xlsx 格式!')
}
if (!isLt2M) {
alert('上传文件大小不能超过 50MB!')
}
console.log(file);
return extension || extension2 && isLt2M
},
// 文件上传成功
uploadSuccess: function (response, file, flieList) {
this.initTable();
console.log(response);
alert(response.msg);
},
// 文件上传失败
uploadFail: function (err, file, fileList) {
alert('上传失败,请重试!');
}, }

其中,data 中的 importFileUrl : '/excellImport/importFile', 就是后台的接口地址;

二、java代码

@SuppressWarnings({"unchecked", "finally" })
@ResponseBody
@RequestMapping(value="/importFile",method= RequestMethod.POST)
@ApiOperation("导入excel文件操作接口")
public JsonResult<XfImportexcelModel> importFile(HttpServletRequest request, HttpServletResponse response,
@RequestParam("file") MultipartFile[] excelFile, XfUser user) throws AccessExpiredException, DaoAccessException, Exception {
System.out.println("==========================================-进入导入excel文件操作接口==========================");
JsonResult<XfImportexcelModel> jsonResult = JsonResult.getDefaultResult();
try {
response.setCharacterEncoding("utf-8");
// 手动调用PrintWriter向客户端输入返回值,若本方法是有返回值的,则不需要
// PrintWriter out = response.getWriter(); //文件保存本地目录路径
String savePath = request.getSession().getServletContext().getRealPath(PATH_LINE) + "main"+PATH_LINE+"xxx"+PATH_LINE+"xxx"+PATH_LINE+"xxx"+PATH_LINE+"upload";
//文件保存目录URL
String saveUrl = request.getContextPath() + PATH_LINE +"upload"+PATH_LINE+"file"+PATH_LINE; if(!ServletFileUpload.isMultipartContent(request)){
// out.print(getError("请选择文件。"));
// out.close();
jsonResult.setMsg("请选择文件。");
return jsonResult;
}
//检查目录
File uploadDir = new File(savePath);
if(!uploadDir.isDirectory()){
uploadDir.mkdirs(); //目录不存在就创建目录
}
//检查目录写权限
if(!uploadDir.canWrite()){
// out.print(getError("上传目录没有写权限。"));
// out.close();
jsonResult.setMsg("上传目录没有写权限。");
return jsonResult;
} String dirName = request.getParameter("dir");
if (dirName == null) {
dirName = "file";
} //定义允许上传的文件扩展名
Map<String, String> extMap = new HashMap<String, String>();
extMap.put("image", "gif,jpg,jpeg,png,bmp");
extMap.put("flash", "swf,flv");
extMap.put("media", "swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb");
extMap.put("file", "doc,docx,xls,xlsx,ppt,htm,html,xml,txt,zip,rar,gz,bz2"); if(!extMap.containsKey(dirName)){
// out.print(getError("目录名不正确。"));
// out.close();
jsonResult.setMsg("目录名不正确。");
return jsonResult;
}
//创建文件夹
savePath += PATH_LINE+dirName + PATH_LINE;
saveUrl += PATH_LINE;
File saveDirFile = new File(savePath);
if (!saveDirFile.exists()) {
saveDirFile.mkdirs(); //保存到项目工程文件夹指定目录中
} SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String ymd = sdf.format(new Date());
savePath += ymd + PATH_LINE;
saveUrl += ymd + PATH_LINE;
File dirFile = new File(savePath); //存到本地之后在获取解析
if (!dirFile.exists()) {
dirFile.mkdirs();
} //最大文件大小
long maxSize = 10000000; // 保存文件
for(MultipartFile iFile : excelFile){
String fileName = iFile.getOriginalFilename(); //检查文件大小
if(iFile.getSize() > maxSize){
// out.print(getError("上传文件大小超过限制。"));
// out.close();
jsonResult.setMsg("上传文件大小超过限制。");
return jsonResult;
}
//检查扩展名
String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
if(!Arrays.<String>asList(extMap.get(dirName).split(",")).contains(fileExt)){
//return getError("上传文件扩展名是不允许的扩展名。\n只允许" + extMap.get(dirName) + "格式。");
// out.print(getError("上传文件扩展名是不允许的扩展名。\n只允许" + extMap.get(dirName) + "格式。"));
// out.close();
jsonResult.setMsg("上传文件扩展名是不允许的扩展名。\n只允许" + extMap.get(dirName) + "格式。");
return jsonResult;
} // 解析Excel数据存入数据库
JsonResult<Object> jsonResultHandle = handleExcelData(iFile, user); //调用另外一个方法解析excel中的数据交互项目生产库
// 解析或者入库有问题则反馈到前端
if(!jsonResultHandle.getSuccess()){
// 返回导入信息到前端页面
jsonResult.setSuccess(false);
jsonResult.setMsg(jsonResultHandle.getMsg());
return jsonResult;
} // 返回导入信息到前端页面
jsonResult.setMsg(jsonResultHandle.getMsg()); SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
String newFileName = df.format(new Date()) + "_" + iFile.getName() + "." + fileExt;
try{
File uploadedFile = new File(savePath, newFileName); // 写入文件
FileUtils.copyInputStreamToFile(iFile.getInputStream(), uploadedFile);
}catch(Exception e){
// out.print(getError("上传文件失败。"));
// out.close();
jsonResult.setMsg("上传文件失败。");
return jsonResult;
} JSONObject obj = new JSONObject();
obj.put("error", 0);
obj.put("url", saveUrl + newFileName); // out.print(obj.toJSONString());
// out.close();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
logger.error("", e);
System.out.println(e); } finally {
System.out.println("===========================================结束导入excel文件操作接口==");
return jsonResult;
} } /**
* 解析Excel数据存入数据库
* @param file
* @param user
* @return
*/
@SuppressWarnings("unchecked")
public JsonResult<Object> handleExcelData(MultipartFile file, XfUser user) throws Exception{
System.out.println("==================================================开始解析Excel数据存入数据库==");
// 返回导入的结果信息
String resultString = "";
JsonResult<Object> jsonResult = JsonResult.getDefaultResult();
if (file != null) {
try {
List<ImportexcelParam> ImportexcelParamList = null; // 获取解析的excel数据
JsonResult<List<List<String>>> JsonResultList = ExcelUtil.parseExcel(file.getInputStream(),
file.getOriginalFilename());
// 解析有问题反馈到调用地方
if(!JsonResultList.getSuccess()){
jsonResult.setSuccess(false);
jsonResult.setMsg(JsonResultList.getMsg());
return jsonResult;
}
// excel数据解析成功,进行获取和入库处理
List<List<List<String>>> resultList = JsonResultList.getData(); // 目前只检查第一个sheet
if (resultList != null && !resultList.isEmpty()) {
for (List<List<String>> sheetList : resultList) {
ImportexcelParamList = new ArrayList<>();
if (sheetList != null && !sheetList.isEmpty()) {
if (sheetList.size() > 200) {
jsonResult.setSuccess(false);
jsonResult.setMsg("单次上传文件记录条数不能超过200条!");
return jsonResult;
}
if(sheetList.get(0).size() != 20){
jsonResult.setSuccess(false);
jsonResult.setMsg("请使用正确的导入模板!");
return jsonResult;
}
// 导入开始时间,毫秒
long startTime = System.currentTimeMillis();
// 记录导入成功的数据条数
int successImportNum = 0;
// 重复的编号记录
String repeatInfo="";
for (List<String> rowList : sheetList){
if (!rowList.isEmpty()) {
// 投诉人和投诉内容筛选有效行
if(StringUtils.isNullOrEmpty(rowList.get(13))||StringUtils.isNullOrEmpty(rowList.get(14))){
continue;
}
// 导入数据举报编号去重
XfImportexcel xfImportexcel = iXfImportexcelService.getXfImportexcelByBussinesNo(rowList.get(2));
if (xfImportexcel != null) {
repeatInfo += "【";
repeatInfo += rowList.get(2);
repeatInfo += "】";
continue;
}
ImportexcelParam ImportexcelParam = new ImportexcelParam();
ImportexcelParam.setStatus(rowList.get(0));//状态
ImportexcelParam.setEmergencyLevel(rowList.get(1));//紧急程度
ImportexcelParam.setBussinesNo(rowList.get(2));//业务编号
ImportexcelParam.setCallSysNo(rowList.get(3));//来电编号
ImportexcelParam.setRepeatFlag("初件".equals(rowList.get(4))?false:true);//重复标志
ImportexcelParam.setReplyFlag("未答复".equals(rowList.get(5))?false:true);//答复标志
ImportexcelParam.setProcessUnitName(rowList.get(6));//处理单位
ImportexcelParam.setOperator(rowList.get(7));//经办人
ImportexcelParam.setProcessamento(rowList.get(8));//处理方式
ImportexcelParam.setProcessStatus(rowList.get(9));//处理状态
ImportexcelParam.setCallPhoneNum(rowList.get(10));//来电号码
ImportexcelParam.setLinkTelphone(rowList.get(11));//联系电话
ImportexcelParam.setCreateBy(rowList.get(12));//创建人
ImportexcelParam.setCallPerson(rowList.get(13));//来电人
ImportexcelParam.setComplainContent(rowList.get(14));//投诉内容
ImportexcelParam.setCallDate(StringUtils.isNullOrEmpty(rowList.get(15))?null:TimeUtils.string2Timestamp(DateUtil.YYYY_MM_DD_HH_MM_SS, rowList.get(15)));//来电日期
ImportexcelParam.setCallPhoneNum(rowList.get(16));//来电人数
ImportexcelParam.setItemType(rowList.get(17));//事项分类
ImportexcelParam.setCallPurpose(rowList.get(18));//来电目的
ImportexcelParam.setProcessTimeLimit(StringUtils.isNullOrEmpty(rowList.get(19))?null:TimeUtils.string2Timestamp(DateUtil.YYYY_MM_DD_HH_MM_SS, rowList.get(19)));//处理时限
ImportexcelParamList.add(ImportexcelParam); }
}
// 调用excel数据导入保存业务实现方法
successImportNum = iXfImportexcelService.save(ImportexcelParamList, user);
// 导入失败条数
int failImportNum = ImportexcelParamList.size()-successImportNum;
// 导入结束时间,毫秒
long endTime = System.currentTimeMillis();
if(repeatInfo!=""){
resultString = "成功导入"+successImportNum+"条记录,失败"+failImportNum+"条;共耗时"+(endTime-startTime)+"毫秒;"+repeatInfo+"编号数据已存在";
}else{
resultString = "成功导入"+successImportNum+"条记录,失败"+failImportNum+"条;共耗时"+(endTime-startTime)+"毫秒。";
}
// 解析和入库都无问题,设置sucess和信息反馈
jsonResult.setSuccess(true, resultString);
System.out.println("================================================="+resultString+"========="); }else{
jsonResult.setSuccess(false, "文件没有数据记录");
}
}
// List<List<String>> sheetList = resultList.get(0); }else{
jsonResult.setSuccess(false, "文件没有数据记录");
} }catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// String path = "E:/springUpload" + file.getOriginalFilename();
// 上传
// file.transferTo(new File(path));
}else{
jsonResult.setSuccess(false, "无法获取文件");
}
System.out.println("==================================================结束解析Excel数据存入数据库======");
return jsonResult;
}

2、解析Excel封装工具类

package com.xxx.xx.utils;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
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.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import com.mlsc.fw.common.exception.ParamDataException;
import com.mlsc.fw.common.utils.DateUtil;
import com.xxx.fw.web.JsonResult; public class ExcelUtil {
private static Logger logger = Logger.getLogger(ExcelUtil.class); public static final String OFFICE_EXCEL_2003_POSTFIX = "xls";
public static final String OFFICE_EXCEL_2010_POSTFIX = "xlsx";
public static final String CELL_TYPE_STRING="String"; /**
* 适用于第一行是标题行的excel,
*
* resultList --> sheetList --> rowList
*
* @throws Exception
*/
@SuppressWarnings("unchecked")
public static JsonResult<List<List<String>>> parseExcel(InputStream in, String suffixName) throws ParamDataException {
JsonResult<List<List<String>>> jsonResult = JsonResult.getDefaultResult();
List<List<List<String>>> resultList = new ArrayList<>();
List<List<String>> sheetList = null;
List<String> rowList = null;
String fileType = suffixName.substring(suffixName.lastIndexOf(".") + 1, suffixName.length());
Workbook wb = null;
try {
if (fileType.equalsIgnoreCase(OFFICE_EXCEL_2003_POSTFIX)) {
wb = new HSSFWorkbook(in);
} else if (fileType.equalsIgnoreCase(OFFICE_EXCEL_2010_POSTFIX)) {
wb = new XSSFWorkbook(in);
} else {
jsonResult.setSuccess(false);
jsonResult.setMsg("请使用正确的导入模板");
return jsonResult;
} int sheetSize = wb.getNumberOfSheets();
// 文件中不止一张工作表
if(sheetSize>1){
jsonResult.setSuccess(false);
jsonResult.setMsg("请使用正确的导入模板");
return jsonResult;
}
for (int i = 0; i < sheetSize; i++) {// 遍历sheet页
Sheet sheet = wb.getSheetAt(i); int rowSize = sheet.getLastRowNum() + 1;
if(rowSize<=1){
jsonResult.setSuccess(false);
jsonResult.setMsg("导入模板没有数据记录");
return jsonResult;
}
sheetList = new ArrayList<>();
int columnSize = 0; // 从第一行标题行开始向下遍历行,包括第一行
for (int j = 0; j < rowSize; j++) {
Row row = sheet.getRow(j); // 遍历第一行作用是为了获取每一行的列数
if (j == 0) {
// bypass the 1st row
columnSize = row.getLastCellNum();
continue;
} // 略过空行
if (row == null) {
continue;
}
rowList = new ArrayList<>();
for (int m = 0; m < columnSize; m++) {
// if (m == 0 && (row.getCell(3)==null||row.getCell(3).equals("")||row.getCell(3).getCellType() ==HSSFCell.CELL_TYPE_BLANK) ) {
// break;
// }
if (row.getCell(m) != null){
rowList.add(getValue(row.getCell(m)));
} else {
rowList.add("");
}
}
if (rowList.size() == columnSize)
sheetList.add(rowList);
}
resultList.add(sheetList);
} } catch (Exception e) {
logger.error("", e);
throw new ParamDataException("上传文件内容格式不正确,请检查文件内容格式!");
} finally {
if (wb != null) {
try {
wb.close();
} catch (Exception e) {
logger.error("关闭Workbook出现异常!", e);
}
}
if (in != null) {
try {
in.close();
} catch (Exception e) {
logger.error("关闭输入流出现异常!", e);
}
}
}
jsonResult.setSuccess(true);
jsonResult.setData(resultList);
return jsonResult;
} public static void exportByTemplate(FileInfo fileInfo, List<DataInfo> dataInfoList, HttpServletResponse response) {
try {
setResponseHeader(fileInfo.getGenerateFileName(), response);
XSSFWorkbook workbook = createWorkBook(fileInfo, dataInfoList, response);
outputFile(fileInfo, workbook, response);
} catch (UnsupportedEncodingException e) {
logger.error("", e);
} } private static void outputFile(FileInfo fileInfo, XSSFWorkbook workbook, HttpServletResponse response) {
BufferedOutputStream bufferedOutPut = null;
try {
OutputStream output = response.getOutputStream();
bufferedOutPut = new BufferedOutputStream(output);
bufferedOutPut.flush();
workbook.write(bufferedOutPut);
} catch (IOException e) {
logger.error("", e);
} finally {
if (workbook != null) {
try {
workbook.close();
} catch (IOException e) {
}
}
if (bufferedOutPut != null) {
try {
bufferedOutPut.close();
} catch (IOException e) {
}
} }
} @SuppressWarnings("deprecation")
private static XSSFWorkbook createWorkBook(FileInfo fileInfo, List<DataInfo> dataInfoList,
HttpServletResponse response) {
XSSFWorkbook workbook = null; try {
File fi = new File(fileInfo.getTemplatePath() + fileInfo.getTemplateName());
FileInputStream fs = new FileInputStream(fi);
// 读取excel模板
workbook = new XSSFWorkbook(fs);
if (dataInfoList == null || dataInfoList.size() == 0) {
return workbook;
}
int rowIndex = 0;
int columnIndex = 0;
// sheet
for (DataInfo dataInfo : dataInfoList) {
if(dataInfo.getSheetIndex()==null){
continue;
}
XSSFSheet sheet = workbook.getSheetAt(dataInfo.getSheetIndex());
rowIndex = dataInfo.getRowStart();
if(StringUtils.isNotEmpty(dataInfo.getModifiedTitle())){
CellStyle cs=sheet.getRow(0).getCell(0).getCellStyle();
sheet.getRow(0).getCell(0).setCellValue(dataInfo.getModifiedTitle());
sheet.getRow(0).getCell(0).setCellStyle(cs);
}
if (dataInfo.getData() == null || dataInfo.getData().isEmpty()) {
continue;
}
XSSFRow styleRow = null;
CellStyle style = null;
CellStyle style0 = null;
// row
for (int rIndex = 0; rIndex < dataInfo.getData().size(); rIndex++) {
if (dataInfo.getData().get(rIndex) == null || dataInfo.getData().get(rIndex).length == 0) {
continue;
}
columnIndex = dataInfo.getColumnStart();
XSSFRow row = sheet.getRow(rowIndex);
if (row == null) {
row = sheet.createRow(rowIndex);
}
if(rIndex==0){
styleRow = sheet.getRow(rowIndex);
} // cell
for (int cIndex = 0; cIndex < dataInfo.getColumnLength(); cIndex++) {
if(styleRow.getCell(columnIndex)==null){
System.out.println(222);
}
style = styleRow.getCell(columnIndex).getCellStyle(); if(dataInfo.isGenIndex()){
XSSFCell cell0 = row.getCell(0);
if(cell0==null){
cell0=row.createCell(0);
}
cell0.setCellValue(rIndex+1);
style0 = styleRow.getCell(0).getCellStyle();
cell0.setCellStyle(style0);
}
XSSFCell cell = row.getCell(columnIndex);
if (cell == null) {
cell = row.createCell(columnIndex);
}
// if(cIndex==17){
// System.out.println(333);
// }
// System.out.println("sheet:"+dataInfo.getSheetIndex()+"/rIndex:"+rIndex+"/cIndex:"+cIndex);
// if(null == dataInfo.getData().get(rIndex)[cIndex]){
// System.out.println(111);
// }
if(dataInfo.getTypeMap()!=null && dataInfo.getTypeMap().containsKey(cIndex)){
if(CELL_TYPE_STRING.equals(dataInfo.getTypeMap().get(cIndex))){
cell.setCellValue(dataInfo.getData().get(rIndex)[cIndex]);
}
}else if(null != dataInfo.getData().get(rIndex)[cIndex]
&& dataInfo.getData().get(rIndex)[cIndex].matches("^(-?\\d+)(\\.\\d+)?$")){
cell.setCellValue(Double.parseDouble(dataInfo.getData().get(rIndex)[cIndex]));
}else{
cell.setCellValue(dataInfo.getData().get(rIndex)[cIndex]);
}
cell.setCellStyle(style);
columnIndex++;
}
rowIndex++;
}
}
List<Integer> hideSheetList=new ArrayList<>();
for(DataInfo dataInfo : dataInfoList){
hideSheetList.add(dataInfo.getSheetIndex());
} for(int i=0;i<workbook.getNumberOfSheets();i++){
if(!hideSheetList.contains(i)){
workbook.setSheetHidden(i, 2);
}
} } catch (IOException e) {
logger.error("", e);
}
return workbook;
} @SuppressWarnings("deprecation")
private static String getValue(Cell cell) {
DecimalFormat df = new DecimalFormat("#.###");
if (cell == null) {
return "";
}
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_NUMERIC:
if (HSSFDateUtil.isCellDateFormatted(cell)) {
SimpleDateFormat sdf = new SimpleDateFormat(DateUtil.YYYY_MM_DD);
return sdf.format(HSSFDateUtil.getJavaDate(cell.getNumericCellValue()));
}
return df.format(cell.getNumericCellValue());
case HSSFCell.CELL_TYPE_STRING:
return cell.getStringCellValue();
case HSSFCell.CELL_TYPE_FORMULA:
return cell.getCellFormula();
case HSSFCell.CELL_TYPE_BLANK:
return ""; }
return "";
} @SuppressWarnings("unused")
public static String getExcelAcceptDepartment(InputStream in, String suffixName) throws ParamDataException {
String header = "";
String fileType = suffixName.substring(suffixName.lastIndexOf(".") + 1, suffixName.length());
Workbook wb = null;
try {
if (fileType.equalsIgnoreCase(OFFICE_EXCEL_2003_POSTFIX)) {
wb = new HSSFWorkbook(in);
} else if (fileType.equalsIgnoreCase(OFFICE_EXCEL_2010_POSTFIX)) {
wb = new XSSFWorkbook(in);
} else {
throw new ParamDataException("读取的不是excel文件");
} int sheetSize = wb.getNumberOfSheets();
for (int i = 0; i < sheetSize; i++) {// 遍历sheet页
Sheet sheet = wb.getSheetAt(i);
header = getValue(sheet.getRow(2).getCell(1)).trim();
break;
}
} catch (Exception e) {
logger.error("", e);
throw new ParamDataException("上传文件内容格式不正确,请检查文件内容格式!");
} finally {
if (wb != null) {
try {
wb.close();
} catch (Exception e) {
logger.error("关闭Workbook出现异常!", e);
}
}
if (in != null) {
try {
in.close();
} catch (Exception e) {
logger.error("关闭输入流出现异常!", e);
}
}
}
return header;
} private static void setResponseHeader(String fileName, HttpServletResponse response)
throws UnsupportedEncodingException {
response.reset();
// SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
// String date = sdf.format(new Date());
// String newFileName=fileName+date;
// 指定下载的文件名
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
}
}

Excel导入保存附件和解析数据的更多相关文章

  1. Excel—— [导入到数据库] or 将数据 [导入到Excel]

    将Excel导入到数据库实现如下: 前台代码: @model IEnumerable<Model.Student> @{ Layout = null; } <!DOCTYPE htm ...

  2. 通过Excel导入Mysql 超过65535条数据的办法

    1.截取 65534条数据,进行分sheet,然后1个sheet导入一张表,最后进行整合! 2.采用TXT导入方式,TXT的导入暂时没发现限制的数据条数,下午用TXT导入74万条数据成功 3.如果遇到 ...

  3. 解决从Excel导入数据库,导入到DataTable时数据类型发生变化的问题(如数字类型变成科学计数法,百分数变成小数)

    做项目的时候,C#读取Excel数据到DataTable或者DataSet,设断点查看DataTable,发现Excel的显示为较长位数数字的字段如0.000012在DataTable中显示为科学计数 ...

  4. Gson解析数据

    package com.bwie.test;import java.io.BufferedReader;import java.io.IOException;import java.io.InputS ...

  5. C#实现Excel模板导出和从Excel导入数据

    午休时间写了一个Demo关于Excel导入导出的简单练习 1.窗体 2.引用office命名空间 添加引用-程序集-扩展-Microsoft.Office.Interop.Excel 3.封装的Exc ...

  6. Open XML操作Excel导入数据

    项目中发现使用OleDb(using System.Data.OleDb)相关对象处理Excel导入功能,不是很稳定经常出问题,需要把这个问题解决掉.项目组提出使用OpenXML来处理Excel的导入 ...

  7. Java 使用poi导入excel,结合xml文件进行数据验证的例子(增加了jar包)

    ava 使用poi导入excel,结合xml文件进行数据验证的例子(增加了jar包) 假设现在要做一个通用的导入方法: 要求: 1.xml的只定义数据库表中的column字段,字段类型,是否非空等条件 ...

  8. 解析大型.NET ERP系统 设计通用Microsoft Excel导入功能

    做企业管理软件很难避免与Microsoft Excel打交道,常常是软件做好了,客户要求说再做一个Excel导入功能.导入Excel数据的功能的难度不大,从Excel列数据栏位的取值,验证值,再导入到 ...

  9. 项目经验之:再来一章:excel导入数据 封装成最棒的不容易!!!

    我见过很的系统,包括OA,ERP,CRM等,在常用的功能当中,从外部导入数据是最常用到的.因为很多客户需要以excel的形式提供数据,,这样的方式我们又如何做呢, 大家最常见的做法可能是这样的,在需要 ...

随机推荐

  1. MarkDown语法(Typora软件为例)

    Hello    !我又来了 这篇文章主要给大家讲一下MarkDown的一些基础语法,MarkDown语法是一种轻量级标记语言,它允许人们使用易读易写的纯文本格式编写文档,然后转换成有效的XHTML( ...

  2. C语言复习(六)----typedef 的作用

    typedef的作用 重命名变量:typedef unsigned int Uint;//可以使用Uint代替unsigned int 定义新的数据类型 typedef struct Books{ c ...

  3. Python正则表达式re库的初次使用入门

    正则表达式常用操作符: 操作符 说明 实例 . 表示任何单个字符,不包括换行符 [] 字符集,对单个字符给出取值范围 [abc]表示a.b.c,[a-z]表示a到z单个字符 [^ ] 非字符集 [^a ...

  4. mysql《一》

    一.启动和停止服务器 通过管理员权限打开cmd命令指示符 通过 net stop mysql(自己的服务器名字)  停止服务器 通过 net start mysql(自己的服务器名字)  启动服务器 ...

  5. 关于shell脚本——echo、for语句、while语句、until语句

    目录 一.echo 1.1.echo命令用法 1.2.echo截取字符 二.for语句 2.1.实例 创建用户名文件 创建脚本文件 运行脚本 三.while语句 3.1.实例 创建脚本文件 运行脚本 ...

  6. sqlplus登录用户被锁问题

    oracle有三个默认的用户名和密码: 1.用户名:sys密码:change_on_install 2.用户名:system密码:manager 3.用户名:scott密码:tiger   当登录用户 ...

  7. Java Lambda 表达式源码分析

    基本概念 Lambda 表达式 函数式接口 方法引用 深入实现原理 字节码 为什么不使用匿名内部类? invokedynamic 总结 参考链接 GitHub 项目 Lambda 表达式是什么?JVM ...

  8. JavaScript-DOM-节点简介与分类

    简介 节点(node)是一个网络术语,它表示网络中的一个连接点.一个网络就是由一些节点构成的集合. 在DOM里,文档是由节点构成的集合,此时的节点是文档树上的树枝和树叶. 分类 DOM中包含许多不同类 ...

  9. kali2020更换JDK&&安装burpsuite pro

    写在前面 之前因为安装maven把JDK换成了1.8.0_261,尝试诸多方法依然打不开自带的burp,正好在做CTF做不出来 QAQ,一气之下打算安个破解版burp. 安装 0x00 更换JDK 使 ...

  10. 手机摄像头作为视频画面捕捉设备与OBS连接(有线)

    手机有线连接OBS(以无他伴侣作为测试案例) 1.硬件设备 安卓手机1台.安卓手机对应的数据线.电脑2台(windows系统,1台做OBS与手机连接.1台做直播后台:配置等如果能达到要求也可以只使用一 ...