我试图解码base64字符串以生成Excel文件
出于上述目的,我使用base64解码方法
public Response addToDB(String base64){
try{
s=sf.openSession();
tx=s.beginTransaction();
/*FileInputStream file = new FileInputStream(new File("C:/Users/Ayesha.Syed/Desktop/eclipse_neon/students.xlsx"));
XSSFWorkbook workbook = new XSSFWorkbook(file); */
byte[] decodedString = Base64.getDecoder().decode(base64);
ByteArrayInputStream st = new ByteArrayInputStream(decodedString);
XSSFWorkbook workbook = new XSSFWorkbook(st);
XSSFSheet sheet = workbook.getSheetAt(0);
/*int starRow = sheet.getFirstRowNum();*/
/*int endRow = sheet.getLastRowNum();*/
XSSFRow row;
for (int i = 1; i <= sheet.getLastRowNum(); i++) {
//points to the starting of excel i.e excel first row
Student stud=new Student();
row = sheet.getRow(i);
stud.setRollnumber(row.getCell(0).toString());
System.out.println(row.getCell(0).getCellTypeEnum());
stud.setName(row.getCell(1).toString());
System.out.println(row.getCell(1).getCellTypeEnum());
stud.setEnglish(row.getCell(2).toString());
System.out.println(row.getCell(2).getCellTypeEnum());
stud.setHindi(row.getCell(3).toString());
System.out.println(row.getCell(3).getCellTypeEnum());
stud.setMaths(row.getCell(4).toString());
System.out.println(row.getCell(4).getCellTypeEnum());
stud.setMarks( row.getCell(5).toString());
System.out.println(row.getCell(5).getCellTypeEnum());
stud.setPercentage(row.getCell(6).toString());
System.out.println(row.getCell(6).getCellTypeEnum());
s.save(stud);
}
response.setStatus("200");
response.setMessage("succesfull");
tx.commit();
} catch (Exception e) {
System.err.println("Exception : " + e.getMessage());
response.setStatus("500");
response.setMessage("unsuccesfull");
tx.rollback();
} finally {
s.close();
}
return response;
}
假设对字符串进行解码,并生成一个Excel工作表以及我通过邮递员推送的数据