简单的excel导入数据库

html代码
<input type="file" name="an" id="import_file" onchange="changes()"/>
<a href="javascript:void(0)" onclick="importExcel()" class="easyui-linkbutton" data-options="iconCls:'icon-save'">提交</a>
js代码
function importExcel(){
            var names=jQuery("#import_file").val();
            if(names==null||names==""){
                jQuery.messager.alert('系统提示','请选择要导入的文件模版!','');
                return;
            }
            var isValid = jQuery("#submitExcel").form('validate');
            if(isValid){
                // 提交导入表单
                jQuery("#submitExcel").form("submit",{
                    url :   '$!link.getContextPath()/base/baseStation_importExcel.htm',
                });
            }
        }

java后台方法
//导入数据库
public String importExcel() throws BiffException, IOException, InvalidFormatException{
List list=new ArrayList();
List baseList=new ArrayList();
String msg=”“;
String extName = anFileName.substring(anFileName.lastIndexOf(“.”)+1);
boolean flag=false;
if(“xlsx”.endsWith(extName)){
//解析excel
XSSFWorkbook rwb = new XSSFWorkbook(an[0]);
XSSFSheet sheet = rwb.getSheetAt(0);
int totalRows = sheet.getLastRowNum()+1;//总行数
int cols;
try{
if(totalRows>1){
for(int i=1;i

你可能感兴趣的:(JavaScript,java,html,Excel)