我一直在搜索一周,但仍然不知道我的代码缺少什么。我想知道你们中是否有人知道为什么我的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);
在这种情况下&#34; BORDER_MEDIUM&#34;无法识别,在构建时会出错。谁知道我错过了什么?
答案 0 :(得分:0)
OP解决方案。
Axel Richter评论:
最新的
fprintf
版本需要HSSFCellStyle.setBorderBottom作为参数{。}}。
通过更新以下参数解决:
apache poi
要:
borderBottom.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);