使用Apache poi和android的HSSFCellStyle错误

春衣少年当酒歌,起舞四顾以笑和。这篇文章主要讲述使用Apache poi和android的HSSFCellStyle错误相关的知识,希望能为你提供帮助。
我一直在寻找一个星期,仍然不知道我的代码缺少什么。我想知道你们中是否有人知道为什么我的HSSFCellstyle语法不会被android studio识别。

public boolean exportToExcel(final Context context, final String fileName){ if (!isExternalStorageAvailable() || isExternalStorageReadOnly()) { Log.e("External Storage", "Storage not available or read only"); return false; }resultExcelArrayList = new ArrayList< > (); success = false; String sheetName = "Sheet1"; wb = new HSSFWorkbook(); sheet = wb.createSheet(sheetName) ; HSSFCellStyle borderBottom = wb.createCellStyle(); borderBottom.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM); HSSFRow row = sheet.createRow(0); HSSFCell cell1 = row.createCell(0); HSSFCell cell2 = row.createCell(2); cell1.setCellValue("KanziApp"); cell2.setCellValue(new Date()); HSSFRow row2 = sheet.createRow(2); HSSFCell cell3 = row2.createCell(0); HSSFCell cell4 = row2.createCell(1); HSSFCell cell5 = row2.createCell(2); cell3.setCellValue("Scan"); cell4.setCellValue("Class"); cell5.setCellValue("Result"); if (mScansReference.child(mUserID).child("current_scan").child("scans") != null){ mScansReference.child(mUserID).child("current_scan").child("scans") .addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { int count = 3; for (DataSnapshot snapshot : dataSnapshot.getChildren()) { String detail = snapshot.child("detail").getValue().toString(); String result = snapshot.child("result").getValue().toString(); HSSFRow row = sheet.createRow(count); HSSFCell cell1 = row.createCell(0); HSSFCell cell2 = row.createCell(1); HSSFCell cell3 = row.createCell(2); cell1.setCellValue(snapshot.getValue().toString()); cell2.setCellValue(detail); cell3.setCellValue(result); resultExcelArrayList.add(new Result(detail, result)); count++; }File file = new File(context.getExternalFilesDir(null), fileName); FileOutputStream os = null; try { os = new FileOutputStream(file); wb.write(os); Log.w("FileUtils", "Writing file" + file); success = true; sendEmail(getBaseContext(), "textFile.xls"); } catch (IOException e) { Log.w("FileUtils", "Error writing " + file, e); } catch (Exception e) { Log.w("FileUtils", "Failed to save file", e); } finally { try { if (null != os) os.close(); } catch (Exception ex) { } }}@Override public void onCancelled(DatabaseError databaseError) {} }); }return success; }

在我的代码的这一部分;
HSSFCellStyle borderBottom = wb.createCellStyle(); borderBottom.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);

在这种情况下,“BORDER_MEDIUM”无法识别,并且在构建时会出错。谁知道我错过了什么?
答案【使用Apache poi和android的HSSFCellStyle错误】OP解决方案。
Axel Richter评论:
最新的apache poi版本需要以HSSFCellStyle.setBorderBottom为参数的BorderStyle。
通过更新以下参数解决:
borderBottom.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);

至:
borderBottom.setBorderBottom(BorderStyle.BORDER_MEDIUM);


    推荐阅读