码迷,mamicode.com
首页 > 数据库 > 详细

增加字段规范表,并修改字段规范表导出Excel时自动增加SQL创建表语句

时间:2021-01-01 12:52:29      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:null   tab   int start   sql   规范   lis   索引   lex   _for   

在ExcelUtil.java中修改函数fillExcelData,判断是否为字段规范表的导出。

public void fillExcelData(int index, Row row)
{
int startNo = index * sheetSize;
int endNo = Math.min(startNo + sheetSize, list.size());
Integer iRow=0;
Integer iColumn =0;
String cellString="";
for (int i = startNo; i < endNo; i++)
{
row = sheet.createRow(i + 1 - startNo);
// 得到导出对象.
T vo = (T) list.get(i);
int column = 0;
for (Object[] os : fields)
{
Field field = (Field) os[0];
Excel excel = (Excel) os[1];
// 设置实体类私有属性可访问
field.setAccessible(true);
this.addCell(excel, row, vo, field, column++);
System.out.println("row:"+row+" column:"+column+" vo:"+vo.toString()+" field:"+field.toString());
}

// 如果是字段规范表导出,自动增加生成数据库SQL的语句
if(this.sheetName.equals("fieldStandard")){
// 创建cell
Cell cell = null;
iRow = i+2;
iColumn = column+4;
cell = row.createCell(iColumn);

if(i==endNo-1){
cellString="=\"`\"&B"+iRow+"&\"` \"&E"+iRow+"&IF(TRIM(F"+iRow
+")<>\"\",\"(\" & F"+iRow+"&\") \",\"\")&IF(ISNUMBER(FIND(\"无符号\",H"+iRow
+")),\" UNSIGNED \",\" \")&IF(TRIM(J"+iRow
+")=\"不允许\",\"NOT NULL \",\"\")&IF(TRIM(K"+iRow
+")<>\"\",\"DEFAULT \" & K"+iRow+",\"\")&IF(ISNUMBER(FIND(\"自增\",H"+iRow
+")),\"AUTO_INCREMENT\",\"\")&\" COMMENT ‘\"&C"+iRow+"&\"‘\"";
}else{
cellString ="=\"`\"&B"+iRow+"&\"` \"&E"+iRow+"&IF(TRIM(F"+iRow
+")<>\"\",\"(\" & F"+iRow+"&\") \",\"\")&IF(ISNUMBER(FIND(\"无符号\",H"+iRow
+")),\" UNSIGNED \",\" \")&IF(TRIM(J"+iRow
+")=\"不允许\",\"NOT NULL \",\"\")&IF(TRIM(K"+iRow
+")<>\"\",\"DEFAULT \" & K"+iRow+",\"\")&IF(ISNUMBER(FIND(\"自增\",H"+iRow
+")),\"AUTO_INCREMENT\",\"\")&\" COMMENT ‘\"&C"+iRow+"&\"‘,\"";
}

cell.setCellFormula(cellString);
System.out.println("==============================="+i);
}
}
// 如果是字段规范表导出,自动增加生成数据库SQL的语句
if(this.sheetName.equals("fieldStandard")){
Cell cell=null;
row = sheet.getRow(0);
cell = row.createCell(iColumn-4);
cell.setCellValue("允许为空");
cell.setCellStyle(styles.get("header"));
cell = row.createCell(iColumn-3);
cell.setCellValue("默认值");
cell.setCellStyle(styles.get("header"));
cell = row.createCell(iColumn-2);
cell.setCellValue("索引");
cell.setCellStyle(styles.get("header"));

cell = row.createCell(iColumn-1);
cell.setCellValue("此处输入表名,右侧自动获取SQL语句");

cell = row.createCell(iColumn);
cell.setCellFormula("=\"DROP TABLE IF EXISTS `\"&M1&\"`; CREATE TABLE `\"&M1&\"` (\"");

row = sheet.createRow(iRow);
cell = row.createCell(iColumn);
cell.setCellFormula("=\") ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT=‘\"&M1&\"‘\"");
}

}

增加字段规范表,并修改字段规范表导出Excel时自动增加SQL创建表语句

标签:null   tab   int start   sql   规范   lis   索引   lex   _for   

原文地址:https://www.cnblogs.com/tommickey/p/14202741.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!