excel模板生成sql server建表语句

该博客介绍了一个Java工具类`ExcelToSqlUtil`,它能读取Excel文件并生成SQL建表语句。工具支持.xls和.xlsx格式,能处理表格中的空行,并为表和字段添加注释。使用`FileInputStream`读取文件,`XSSFWorkbook`处理工作簿,通过遍历行和单元格来构建SQL语句,最后将结果写入指定路径的文件中。
摘要由CSDN通过智能技术生成

因为需要进行大量的表创建所以才有此方法,需要的请copy

package com.spf.sp.util;

import com.spf.eap.util.common.Toolkit;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ExcelToSqlUtil {

    /**
     *
     * @param filePath
     * @param storePath
     * @return
     * @throws Exception
     */
    public static List<Map> readExcel(String filePath,String storePath) throws Exception{
        File file=new File(filePath);
        if (!file.exists()) {
            return null;
        }

        /**
         * Get the suffix of the file
         */
        String suffix= filePath.substring(filePath.lastIndexOf("."));

        /**
         * if suffix cannot equals .xls && .xlsx ,return null
         */
        if(!".xls".equals(suffix) && !".xlsx".equals(suffix)){
            return null;
        }

        //返回值列
        List<Map> reaultList=new ArrayList<Map>();
        if(".xls".equals(suffix)){
            reaultList=readExcel2007(filePath,storePath);
        }else if(".xlsx".equals(suffix)){
            reaultList=readExcel2007(filePath,storePath);
        }
        return reaultList;
    }

    /**
     *
     * @param filePath
     * @param storePath
     * 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值