1个回答
展开全部
try{
SysCodeTemplateForm scpForm = (SysCodeTemplateForm) form;
FormFile formfile = scpForm.getUploadfile();
SysCodeTemplate scp = new SysCodeTemplate();
String reportfn = formfile.getFileName();
String savePath = "D:\\";
byte[] b = formfile.getFileData();
File file = new File(savePath);
if (!file.exists()) {
file.mkdirs();
}
File uploadFile = new File(file, reportfn);
FileOutputStream fops = new FileOutputStream(uploadFile);
fops.write(b);
fops.close();
XSSFWorkbook wookbook = new XSSFWorkbook(new FileInputStream(uploadFile));
XSSFSheet sheet = wookbook.getSheet("Sheet1");
int rows = sheet.getPhysicalNumberOfRows();
ArrayList<SysCodeTemplate> list1 = new ArrayList<SysCodeTemplate>();
ArrayList<SysCode> list2 = new ArrayList<SysCode>();
for (int i = 1; i < rows; i++) {
XSSFRow row = sheet.getRow(i);
if (row != null) {
int cells = row.getPhysicalNumberOfCells();
String value = "";
for (int j = 0; j < cells; j++) {
XSSFCell cell = row.getCell(j);
if (cell != null) {
switch (cell.getCellType()) {
case XSSFCell.CELL_TYPE_NUMERIC:
value += (long)cell.getNumericCellValue() + ",";
break;
case XSSFCell.CELL_TYPE_STRING:
value += cell.getStringCellValue() + ",";
break;
}
}
}
String valu = value.substring(0, value.length()-1);
String[] val = valu.split(",");
scp.setCodeCode(val[0]);
scp.setCodeName(val[1]);
scp.setCodeType(new Long(val[2]));
list1.add(scp);
}
}
SysCodeTemplateForm scpForm = (SysCodeTemplateForm) form;
FormFile formfile = scpForm.getUploadfile();
SysCodeTemplate scp = new SysCodeTemplate();
String reportfn = formfile.getFileName();
String savePath = "D:\\";
byte[] b = formfile.getFileData();
File file = new File(savePath);
if (!file.exists()) {
file.mkdirs();
}
File uploadFile = new File(file, reportfn);
FileOutputStream fops = new FileOutputStream(uploadFile);
fops.write(b);
fops.close();
XSSFWorkbook wookbook = new XSSFWorkbook(new FileInputStream(uploadFile));
XSSFSheet sheet = wookbook.getSheet("Sheet1");
int rows = sheet.getPhysicalNumberOfRows();
ArrayList<SysCodeTemplate> list1 = new ArrayList<SysCodeTemplate>();
ArrayList<SysCode> list2 = new ArrayList<SysCode>();
for (int i = 1; i < rows; i++) {
XSSFRow row = sheet.getRow(i);
if (row != null) {
int cells = row.getPhysicalNumberOfCells();
String value = "";
for (int j = 0; j < cells; j++) {
XSSFCell cell = row.getCell(j);
if (cell != null) {
switch (cell.getCellType()) {
case XSSFCell.CELL_TYPE_NUMERIC:
value += (long)cell.getNumericCellValue() + ",";
break;
case XSSFCell.CELL_TYPE_STRING:
value += cell.getStringCellValue() + ",";
break;
}
}
}
String valu = value.substring(0, value.length()-1);
String[] val = valu.split(",");
scp.setCodeCode(val[0]);
scp.setCodeName(val[1]);
scp.setCodeType(new Long(val[2]));
list1.add(scp);
}
}
追问
兄弟看不懂,能不能给个完整的例子
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询