如何在ExternalStorage中输出WritableWorkbook,就像我创建Test.xls文件的情况一样:
String org = "test";
File file = null;
File root = Environment.getExternalStorageDirectory();
if (root.canWrite()) {
File dir = new File (root.getAbsolutePath() + "/Test");
dir.mkdirs();
file = new File(dir, "Test.xls");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
fos.write(org.getBytes());
} catch (IOException e) {
e.printStackTrace();
}
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
这是我目前的WritableWorkbook代码:
@Override
public void onClick(View arg0) {
try {
WritableWorkbook workbook = Workbook.createWorkbook(new File("output.xls"));
WritableSheet sheet = workbook.createSheet("First Sheet", 0);
Label label = new Label(0, 2, "A label record");
sheet.addCell(label);
workbook.write();
workbook.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RowsExceededException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}