<form id="fileUpload" action="importOCRExcelData.do" enctype="multipart/form-data" method="post">
<input id="excelFile" name="excelFile" type="file" />
<a href='javascript:void(0);' title="点击下载模板" onclick="downloadModalExcel();">点击下载模板</a>
<input type="button" value="提交" class="quickpro-button" onclick="submitExcel();"/>
</form>
/**
* 数据文件导入
*
* @param request
* @param response
* @throws IOException
* @throws FileNotFoundException
*/
@RequestMapping({ "importOCRExcelData" })
public void importOCRExcelData(HttpServletRequest request,HttpServletResponse response) throws FileNotFoundException, IOException
{
MultipartHttpServletRequest mulRequest = (MultipartHttpServletRequest) request;
MultipartFile file = File("excelFile");
String filename = OriginalFilename();
if (filename == null || "".equals(filename))
{
}
try
{
InputStream input = InputStream();
XSSFWorkbook workBook = new XSSFWorkbook(input);
List<String> sfList = ExportHelper.exportListFromExcel(workBook, 0);
for(int i=0 ; i<sfList.size();i++)
{
LOGGER.info("【"+(i).toString()+"】 ");
}
}
catch (Exception e)
{
LOGGER.error(e);
}
}
/**
* 由指定的Sheet导出至List
*
* @param workbook
* @param sheetNum
* @return
* @throws IOException
*/
public static List<String> exportListFromExcel(Workbook workbook,
int sheetNum)
{
Sheet sheet = SheetAt(sheetNum);
// 解析公式结果
FormulaEvaluator evaluator = CreationHelper()
.createFormulaEvaluator();
List<String> list = new ArrayList<String>();
intinputtypefile不上传文件 minRowIx = FirstRowNum();
int maxRowIx = LastRowNum();
for (int rowIx = minRowIx; rowIx <= maxRowIx; rowIx++)
{
Row row = Row(rowIx);
StringBuilder sb = new StringBuilder();
short minColIx = FirstCellNum();
short maxColIx = LastCellNum();
for (short colIx = minColIx; colIx <= maxColIx; colIx++)
{
Cell cell = Cell(new Integer(colIx));
CellValue cellValue = evaluator.evaluate(cell);
if (cellValue == null)
{
continue;
}
Object result = null;
switch (CellType())
{
case Cell.CELL_TYPE_BOOLEAN:
result = BooleanCellValue();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
if (HSSFDateUtil.isCellDateFormatted(cell))
{
// 处理日期格式、时间格式
SimpleDateFormat sdf = null;
if (CellStyle().getDataFormat() == HSSFDataFormat.getBuiltinFormat("h:mm"))
{
sdf = new SimpleDateFormat("HH:mm");
}
else if(CellStyle().getDataFormat() == HSSFDataFormat.getBuiltinFormat("h:mm:ss"))
{
sdf = new SimpleDateFormat("HH:mm:ss");
}
else
{
sdf = new SimpleDateFormat("yyyy-MM-dd");
}
Date date = DateCellValue();
result = sdf.format(date);
}
else if (CellStyle().getDataFormat() == 58)
{
// 处理自定义日期格式:m月d日(通过判断单元格的格式id解决,id的值是58)
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
发表评论