这是导出栏,
根据获得的文件路径,
在手机文件复制并打开,
可以得到xlsx表格,
查看录入的信息内容
路径获取函数:
public void exportExcel() {
file = new File(getSDPath(this) + "/Record2");
makeDir(file);
ExcelUtils.initExcel(file.toString() + "/14天健康登记表.xlsx");
fileName = getSDPath(this) + "/Record2/14天健康登记表.xlsx";
ExcelUtils.writeObjListToExcel(getRecordData(), fileName, this);
}
/**
* 将数据集合 转化成ArrayList<ArrayList<String>>
* @return
*/
private ArrayList<ArrayList<String>> getRecordData() {
recordList = new ArrayList<>();
for (int i = 0; i <students.size(); i++) {
temBean student = students.get(i);
ArrayList<String> beanList = new ArrayList<String>();
beanList.add(student.getTime());
beanList.add(student.getAddress());
beanList.add(student.getTemperature());
beanList.add(student.getAddition());
recordList.add(beanList);
}
return recordList;
}
//获取sd卡地址
public static String getSDPath(Context context) {
File sdDir = null;
boolean sdCardExist = Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED);// 判断sd卡是否存在
if (sdCardExist) {
if (Build.VERSION.SDK_INT>=29){
//Android10之后
sdDir = context.getExternalFilesDir(null);
}else {
sdDir = Environment.getExternalStorageDirectory();// 获取SD卡根目录
}
} else {
sdDir = Environment.getRootDirectory();// 获取跟目录
}
return sdDir.toString();
}
public void makeDir(File dir) {
if (!dir.getParentFile().exists()) {
makeDir(dir.getParentFile());
}
dir.mkdir();