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;
}
<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;
}
相关文章推荐
- 在struts2下不刷新上传excel文件,并回调页面方法!
- ocupload、struts2实现excel文件上传,poi解析
- struts2上传excel文件并解析数据插入数据库
- struts2 word、excel文件的上传。用到RandomAccessFile 类读取文件。
- extjs3.2+struts2实现多文件上传excel并插入到数据库
- struts2上传Excel 安装wps导致 application/kset 上传文件类型报错解决办法
- Struts2实现文件上传和下载
- JavaWeb框架_Struts2_(七)----->文件的上传和下载
- Struts2学习笔记之文件上传
- struts2中上传文件的实例应用
- 读取excel文件,支持doc ,docx格式 附带上传方法
- Struts2实现文件上传报错(一)
- struts2--文件上传和uploadFile拦截器
- 使用struts2上传文件,(单个上传和多个上传)
- Struts2文件的上传
- struts2上传文件
- Struts2+poi实现Excel文件上传并插入数据库的操作
- struts2文件上传
- struts2的文件上传
- Struts2实现文件上传