2 Excel文档导出
response.setContentType("application/octet-stream; charset=utf-8");
response.setHeader("Content-Disposition",
"attachment; filename=" + new String(fileName.getBytes("utf-8"), "ISO-8859-1"));
2.1
3 Excel文档导入
3.1
界面:
var htmlStr = "";
htmlStr += '';
$.layer({
type : 1,
title : '导入用户',
area : [ 'auto', 'auto' ],
page : {
html : htmlStr
}
});
function ValidateFileType() {
var array = new Array();
var excelName = $("#userExcelFile").val();
array = excelName.split(".");
var suffix = array[array.length - 1];
if (suffix != "xlsx" && suffix != "xls") {
alert("您选择的不是excel文档,请重新选择");
var file = document.getElementById("userExcelFile");
file.value = "";
}
}
function submitFrom() {
var options = {
beforeSubmit : showRequest,
success : showResponse,
resetForm : true,
dataType : 'json'
};
$("#userExcelFileFormId").submit(function() {
$(this).ajaxSubmit(options);
return false;
});
}
function showRequest(){
}
function showResponse(responseText) {
if (responseText.isSuccess == true) {
alert('导入成功');
window.location = "/SSMProject/user/userMana";
}
}
@RequestMapping("/uploadExcel")
public void uploadExcel(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> resultMap = new HashMap<>();
try {
MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multiRequest.getFileMap();
for (Map.Entry<String, MultipartFile> entry : fileMap.entrySet()) {
MultipartFile file = entry.getValue();
InputStream inputStream = file.getInputStream();
Workbook workbook = WorkbookFactory.create(inputStream);
List