使用Apache poi和android的HSSFCellStyle错误
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用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”无法识别,并且在构建时会出错。谁知道我错过了什么?
答案
OP解决方案。
Axel Richter评论:
最新的
apache poi
版本需要以HSSFCellStyle.setBorderBottom为参数的BorderStyle。
通过更新以下参数解决:
borderBottom.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
至:
borderBottom.setBorderBottom(BorderStyle.BORDER_MEDIUM);
以上是关于使用Apache poi和android的HSSFCellStyle错误的主要内容,如果未能解决你的问题,请参考以下文章
org.apache.poi.hssf.usermodel.HSSFWorkbookorg.apache.poi.xssf.usermodel.XSSFWorkbook excel2003 exce