java 如何一列一列读取excel数据 20
2个回答
展开全部
工作用导入excel通些插件导入代码要自基本原理...
public Object importDoucument(MultipartFile uploadfile)
{
StringBuffer resultMessage = new StringBuffer();
ExcelImport excelImport = new ExcelImport();
Sheet sheet = null;
try
{
// 验证文件格式 错 返工作簿
excelImport.verifyExeclFile(uploadfile);
ExcelBean excelBean = excelImport.getExcelBean();
if (null != excelBean)
{
sheet = excelBean.getSheet();
}
//导入excel文件析整理list象
List dataList = getAssessCateRange(sheet, "战略要素名称", "战略要素名称", 2, 1);
int num = 0;
if(dataList.size()>0){
for (StcCoreElements itemStcVO : dataList)
{
StcCoreElements stcCoreElementsVo = nitemStcVO
//*****修改些处
this.save(stcCoreElementsVo);
++num;
}
}
resultMessage.append("已功导入 "+num+" 条核要素信息");
}
catch (Exception e)
{
resultMessage.append(e.getMessage());
e.printStackTrace();
}
finally
{
excelImport.close();
}
return resultMessage;
}
private List getAssessCateRange(Sheet sheet, String startName, String endName, int rowNum, int titleRowNum)
{
int[] cateRange = new int[2];
List dataList = new ArrayList();
int lastRowNumber = sheet.getLastRowNum();
Row cateRow = sheet.getRow(rowNum - 1);
Cell cateCell = cateRow.getCell(0);
String cateCellValue = ImportExcelUtil.getCellValue(cateCell, sheet);
if (StringUtils.isNotBlank(cateCellValue))
{
if (StringUtils.startsWith(cateCellValue, startName))
{
cateRange[0] = rowNum + titleRowNum;
}
}
String currentCellValue0 = "";
do
{
Row currentRow = sheet.getRow(rowNum);
StcCoreElements info =new StcCoreElements();
Cell currentCell0 = currentRow.getCell(0);
currentCellValue0 = ImportExcelUtil.getCellValue(currentCell0, sheet);
info.setOverallPlan(currentCellValue0);
dataList.add(info);
rowNum++;
} while (rowNum <= lastRowNumber);
return dataList;
}
public Object importDoucument(MultipartFile uploadfile)
{
StringBuffer resultMessage = new StringBuffer();
ExcelImport excelImport = new ExcelImport();
Sheet sheet = null;
try
{
// 验证文件格式 错 返工作簿
excelImport.verifyExeclFile(uploadfile);
ExcelBean excelBean = excelImport.getExcelBean();
if (null != excelBean)
{
sheet = excelBean.getSheet();
}
//导入excel文件析整理list象
List dataList = getAssessCateRange(sheet, "战略要素名称", "战略要素名称", 2, 1);
int num = 0;
if(dataList.size()>0){
for (StcCoreElements itemStcVO : dataList)
{
StcCoreElements stcCoreElementsVo = nitemStcVO
//*****修改些处
this.save(stcCoreElementsVo);
++num;
}
}
resultMessage.append("已功导入 "+num+" 条核要素信息");
}
catch (Exception e)
{
resultMessage.append(e.getMessage());
e.printStackTrace();
}
finally
{
excelImport.close();
}
return resultMessage;
}
private List getAssessCateRange(Sheet sheet, String startName, String endName, int rowNum, int titleRowNum)
{
int[] cateRange = new int[2];
List dataList = new ArrayList();
int lastRowNumber = sheet.getLastRowNum();
Row cateRow = sheet.getRow(rowNum - 1);
Cell cateCell = cateRow.getCell(0);
String cateCellValue = ImportExcelUtil.getCellValue(cateCell, sheet);
if (StringUtils.isNotBlank(cateCellValue))
{
if (StringUtils.startsWith(cateCellValue, startName))
{
cateRange[0] = rowNum + titleRowNum;
}
}
String currentCellValue0 = "";
do
{
Row currentRow = sheet.getRow(rowNum);
StcCoreElements info =new StcCoreElements();
Cell currentCell0 = currentRow.getCell(0);
currentCellValue0 = ImportExcelUtil.getCellValue(currentCell0, sheet);
info.setOverallPlan(currentCellValue0);
dataList.add(info);
rowNum++;
} while (rowNum <= lastRowNumber);
return dataList;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2017-08-21
展开全部
使用jxl可以做到。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询