java Excel操作工具类
程序员文章站
2022-07-13 14:19:48
...
java Excel操作工具类
一、描述
Excel操作工具类。
二、代码实现
package com.lanshen.utils.lsjavaUtils;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import jxl.Sheet;
import jxl.Workbook;
import org.springframework.web.multipart.MultipartFile;
/**
* Created by Lanshen on 2019/12/2.
* Excel操作工具类
*/
public class lsexcelUtils {
/**
* 判断Excel文件是否为空
* 仅有标题栏,没有数据项为空,
* 没有任何内容也为空
*/
public String excelIsNull(MultipartFile file, HttpServletResponse response) throws IOException {
String msg = "";
try {
Workbook rwb = Workbook.getWorkbook(file .getInputStream());
Sheet rs = rwb.getSheet(0);// 或者rwb.getSheet(0)
int rows = rs.getRows();// 得到所有的行
if(rows < 2 ){
System.out.println("上传的Excel为空文档");
msg = "error";
}else {
System.out.println("上传的Excel不为空文档");
msg = "success";
}
} catch (Exception e) {
e.printStackTrace();
}
return msg;
}
}