<!-- 页面代码 -->
<div>
<form id="ExcelAction" name="ExcelAction" action="QyxyAction_addExcel"
method="post" enctype="multipart/form-data" style="display: none;"
οnsubmit="return checkGs('Excelfile');">
<table id="ExcelTab" border="0" cellpadding="0" cellspacing="0"
width="100%" class="tableBorderOther2"
style="margin-left: 1px; margin: auto;">
<tr>
<td class="tdBlank1" height="30" style="width: 17%">导入数据</td>
<td class="tdBlank2" style="width: 60%"><input id="Excelfile"
type="file" name="Excelfile" style="width: 85%" /></td>
<td class="tdBlank1" height="30"
style="width: 23%; text-align: center"><input type="image"
id="btnQuery"
src="<%=request.getContextPath()%>/images/exportExcel.gif" /> </td>
</tr>
</table>
</form>
</div>
<!--后台部分代码-->
InputStream fis = new FileInputStream(Excelfile); //Excelfile 为file
XSSFWorkbook book = new XSSFWorkbook(fis);
XSSFSheet sh = book.getSheetAt(0);
int rowCount = sh.getLastRowNum()+1 - sh.getFirstRowNum();
for(int i=0;i<rowCount;i++){
String[] value_name = new String[12];
XSSFRow row = sh.getRow(i); //获得行数
int cols = row.getLastCellNum(); //获得列数
for(int j=0;j<cols;j++){
value_name[j] = String.valueOf(row.getCell(j));
if(value_name[j].indexOf(".")>0){
value_name[j] = value_name[j].substring(0, value_name[j].lastIndexOf(".")); //赋值
}
}