您的位置:首页 > 编程语言 > Java开发

struts2 excel文件上传

2011-10-21 15:56 363 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<div>

<form action="admin/getUploadExce.action" method="post" enctype="multipart/form-data" >

<input type="file" name="uploadFile" id="uploadFile" />

<input type="submit" value="导入" class="but3" />

</form>

<br />

</div>

</center>

</div>

<!-- 操作功能区域结束 -->

</body>

</html>

struts.xml--------------------------

<action name="getUploadExce" class="examPaperAction" method="getUploadExcel">

</action>

action--------------------------

private File uploadFile;

private String uploadFileFileName;

/**

* @return the uploadFileFileName

*/

public String getUploadFileFileName() {

return uploadFileFileName;

}

/**

* @param uploadFileFileName the uploadFileFileName to set

*/

public void setUploadFileFileName(String uploadFileFileName) {

this.uploadFileFileName = uploadFileFileName;

}

/**

* @return the uploadFile

*/

public File getUploadFile() {

return uploadFile;

}

/**

* @param uploadFile the uploadFile to set

*/

public void setUploadFile(File uploadFile) {

this.uploadFile = uploadFile;

}

public String getUploadExcel() {

try {

InputStream in = new FileInputStream(uploadFile);//不用request.getInputStream();

XSSFWorkbook xwb;

xwb = new XSSFWorkbook(in);

// 读取第一章表格内容

XSSFSheet sheet = xwb.getSheetAt(0);

// 定义 row、cell

XSSFRow row;

int rows = sheet.getPhysicalNumberOfRows();

System.out.println("有效行数=" + rows);

/////////////////////

///其他代码//

//////////////////////

} catch (Exception e) {

e.printStackTrace();

}

return null;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: