jar包
package cn.kk.excel.city;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
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.Name;
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.ss.util.CellRangeAddressList;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ExcelCityChange {
public static void main(String[] args) {
String file = "d:/excel021.xlsx";
try {
excelChange(file);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void excelChange(String path) throws IOException {
File file = new File(path);
// 判断文件是否存在
if (!file.exists()) {
// 创建文件
file.createNewFile();
}
Workbook workBook = null;
// 根据文件名称后缀,创建excel模板
if (file.getName().endsWith(".xls")) {
workBook = new HSSFWorkbook();// .xls后缀模板
} else if (file.getName().endsWith(".xlsx")) {
workBook = new XSSFWorkbook();// .xls