|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package UnitTest.ImportExcel;
|
|
|
|
|
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
@ -8,8 +9,10 @@ import java.util.List;
|
|
|
|
|
import com.aspose.cells.Workbook;
|
|
|
|
|
import com.dsideal.QingLong.Util.AsposeUtil;
|
|
|
|
|
import com.dsideal.QingLong.Util.GenericTemplateUtil;
|
|
|
|
|
import com.dsideal.QingLong.Util.PoiUtil;
|
|
|
|
|
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;
|
|
|
|
@ -36,6 +39,7 @@ public class TestAll {
|
|
|
|
|
for (Record record : _list) {
|
|
|
|
|
record.set("column_type", "varchar(2048)");
|
|
|
|
|
record.set("allow_blank", false);
|
|
|
|
|
record.set("options", "男,女,未知");//生成下拉框
|
|
|
|
|
}
|
|
|
|
|
cnt++;
|
|
|
|
|
kv.set("table_name", "ds_source_" + cnt);
|
|
|
|
@ -84,6 +88,7 @@ public class TestAll {
|
|
|
|
|
//提供给前台进行修改属性(现在这里是模拟的前端处理后的代码)
|
|
|
|
|
// (1)整体上需要添加一个参数:table_name
|
|
|
|
|
// (2)list中每个 Record 添加属性:column_type,allow_blank,在JAVA中,函数的参数是一个List<Kv>时,是按参数引用的,所以,直接修改即可
|
|
|
|
|
// (3)如果需要添加下拉框,需要设置下拉item的数据范围
|
|
|
|
|
change(kvList);
|
|
|
|
|
|
|
|
|
|
//开发时暴力删除掉原表,在正式上线前要注意:不能简单粗暴的删除!!
|
|
|
|
@ -106,6 +111,26 @@ public class TestAll {
|
|
|
|
|
String tableName = kv.getStr("table_name");
|
|
|
|
|
GenericTemplateUtil.createTable(tableName, kv, upload_excel_filename);//创建表
|
|
|
|
|
}
|
|
|
|
|
//检查是不是需要对于指定的Sheet+指定的列生成下拉框
|
|
|
|
|
|
|
|
|
|
//添加下拉框校验
|
|
|
|
|
int sheetIdx = 0;
|
|
|
|
|
for (Kv kv : kvList) {
|
|
|
|
|
int data_start_row = kv.getInt("data_start_row");
|
|
|
|
|
List<Record> list = (List<Record>) kv.get("list");
|
|
|
|
|
int colIdx = 0;
|
|
|
|
|
for (Record record : list) {
|
|
|
|
|
String options = record.getStr("options");
|
|
|
|
|
if (!StrKit.isBlank(options)) {
|
|
|
|
|
PoiUtil.addValidation(wb, sheetIdx, options, data_start_row, data_start_row + 20000, colIdx, colIdx);//范围
|
|
|
|
|
}
|
|
|
|
|
colIdx++;
|
|
|
|
|
}
|
|
|
|
|
sheetIdx++;
|
|
|
|
|
}
|
|
|
|
|
// 保存
|
|
|
|
|
FileOutputStream fileOut = new FileOutputStream(source);
|
|
|
|
|
wb.write(fileOut);
|
|
|
|
|
//关闭Excel
|
|
|
|
|
wb.close();
|
|
|
|
|
//输出
|
|
|
|
|