jsp页面:
form id=”excelForm” method=”” enctype=”multipart/form-data”>
input type=”file” id=”” name=”” text=”浏览”/>
并且建一个ActionForm
private FormFile fileName
设置FormBean在Structs配置文件中
form-beans>
form-bean name="fileForm" type="com.wq.form.ExcelForm"/>
/form-beans>
action name="excelForm" type="com.wq.action.AgentInfoAction"
parameter="method" scope="request" path="/AgentInfoAction">
forward name="importResult" path="url" />
/action>
在Action中以InputStream流的形式得到
ExcelForm ef = (ExcelForm)form;
FormFile file = ef.getFileName();
InputStream is = file.getInputStream();
对InputStream进行操作
Workbook book = Workbook.getWorkbook(is);
Sheet[] sheets = book.getSheets();//取工作薄中工作表(Sheet)对象数组
int shRow = sheet.getRows();//sheet表中总行数
int shCol = sheet. getColumns();//sheet表中总列数
Sheet sheet = sheets[0];//
For(int i = 0;i{
Map map = new HashMap();
Map.put(“xx”,sheet.getCell(1,i).getContents());
...
}
Excel内容存入map
参考帖子:http://www.iteye.com/topic/358361