|
|
|
@ -1,12 +1,6 @@
|
|
|
|
|
package UnitTest.ImportExcel;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import com.aspose.cells.Workbook;
|
|
|
|
|
import com.dsideal.QingLong.Util.AsposeUtil;
|
|
|
|
|
import com.dsideal.QingLong.Util.GenericTemplateUtil;
|
|
|
|
@ -15,17 +9,28 @@ import com.jfinal.kit.Kv;
|
|
|
|
|
import com.jfinal.kit.PropKit;
|
|
|
|
|
import com.jfinal.kit.StrKit;
|
|
|
|
|
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
import com.jfinal.plugin.activerecord.CaseInsensitiveContainerFactory;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
import com.jfinal.plugin.activerecord.dialect.PostgreSqlDialect;
|
|
|
|
|
import com.jfinal.plugin.hikaricp.HikariCpPlugin;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFCell;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
public class CreateTableAndTemplate {
|
|
|
|
|
public static String path = "D:\\dsWork\\QingLong\\src\\main\\resource\\Excel\\";
|
|
|
|
|
|
|
|
|
|
//模拟上传文件的文件名称
|
|
|
|
|
public static String upload_excel_filename = "b61a2af2-223f-4058-a675-b212e4dd9487" + ".xlsx";
|
|
|
|
|
//用户上传的模板
|
|
|
|
|
public static String userUploadExcel = "source.xlsx";
|
|
|
|
|
//我处理后的模板
|
|
|
|
|
public static String upload_excel_filename;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:模拟前端人机交互对表结构进行修改
|
|
|
|
@ -64,9 +69,14 @@ public class CreateTableAndTemplate {
|
|
|
|
|
arp.start();
|
|
|
|
|
|
|
|
|
|
//源文件
|
|
|
|
|
upload_excel_filename = UUID.randomUUID().toString().toLowerCase() + ".xlsx";
|
|
|
|
|
String source = path + File.separator + upload_excel_filename;
|
|
|
|
|
Workbook workbook = new Workbook(source);
|
|
|
|
|
int sheetCount = workbook.getWorksheets().getCount();//Sheet表数量
|
|
|
|
|
if (FileUtil.exist(source)) FileUtil.del(source);
|
|
|
|
|
//复制成我自己的,随便折腾
|
|
|
|
|
FileUtil.copy(path + File.separator + userUploadExcel, source, true);
|
|
|
|
|
|
|
|
|
|
Workbook asposeWb = new Workbook(source);
|
|
|
|
|
int sheetCount = asposeWb.getWorksheets().getCount();//Sheet表数量
|
|
|
|
|
//解析上传EXCEL中的每个Sheet,解析出表头信息,表名描述等信息
|
|
|
|
|
InputStream is = new FileInputStream(source);
|
|
|
|
|
XSSFWorkbook wb = new XSSFWorkbook(is);
|
|
|
|
@ -117,13 +127,20 @@ public class CreateTableAndTemplate {
|
|
|
|
|
for (Kv kv : kvList) {
|
|
|
|
|
int start_row = kv.getInt("start_row");
|
|
|
|
|
int end_row = kv.getInt("end_row");
|
|
|
|
|
int start_column = kv.getInt("start_column");
|
|
|
|
|
int end_column = kv.getInt("end_column");
|
|
|
|
|
List<Record> list = (List<Record>) kv.get("list");
|
|
|
|
|
int colIdx = 0;
|
|
|
|
|
for (Record record : list) {
|
|
|
|
|
boolean allow_blank = record.getBoolean("allow_blank");
|
|
|
|
|
System.out.println(allow_blank);
|
|
|
|
|
if (!allow_blank) {
|
|
|
|
|
//一行时,星号加在一行
|
|
|
|
|
//二行时,星号加在二行
|
|
|
|
|
XSSFCell cell = wb.getSheetAt(sheetIdx).getRow(end_row).getCell(colIdx);
|
|
|
|
|
if (StrKit.isBlank(cell.getStringCellValue())) {
|
|
|
|
|
cell = wb.getSheetAt(sheetIdx).getRow(start_row).getCell(colIdx);
|
|
|
|
|
}
|
|
|
|
|
PoiUtil.addStar(wb, cell);
|
|
|
|
|
PoiUtil.addComment(wb, cell, "此单元格内容必须输入!");
|
|
|
|
|
}
|
|
|
|
|
colIdx++;
|
|
|
|
|
}
|
|
|
|
|
sheetIdx++;
|
|
|
|
@ -150,6 +167,6 @@ public class CreateTableAndTemplate {
|
|
|
|
|
//关闭Excel
|
|
|
|
|
wb.close();
|
|
|
|
|
//输出
|
|
|
|
|
System.out.println("恭喜,数据库表创建成功,共创建" + kvList.size() + "个。");
|
|
|
|
|
System.out.println("恭喜,数据库表创建成功,共" + kvList.size() + "个。");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|