【文件属性】:
文件名称:导出Excel文件
文件大小:23.33MB
文件格式:RAR
更新时间:2020-10-15 15:26:00
导出Excel
public class MainActivity extends AppCompatActivity {
private List listExcelData=new ArrayList();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addDate();
}
private void addDate(){
ExcelData data1=new ExcelData("张三", "19","数学","男","大一","123");
ExcelData data2=new ExcelData("李四", "20","语文","女","大二","456");
ExcelData data3=new ExcelData("王五", "21","英语","不明","大三","789");
ExcelData data4=new ExcelData("赵六", "22","化学","不明","大四","135");
ExcelData data5=new ExcelData("阿七", "23","生物","不明","大五","246");
ExcelData data6=new ExcelData("傻八", "24","物理","不明","大六","159");
listExcelData.add(data1);
listExcelData.add(data2);
listExcelData.add(data3);
listExcelData.add(data4);
listExcelData.add(data5);
listExcelData.add(data6);
}
public void createExcel(View v) throws FileNotFoundException {
File file;
File dir = new File(Environment.getExternalStorageDirectory().toString());
Log.e("飞","路径是:"+dir.getAbsolutePath());
file=new File(Environment.getExternalStorageDirectory(),"excel.xls");
if (!dir.exists()){
Log.e("飞","创建文件夹");
dir.mkdirs();
}
WritableWorkbook wwb;
OutputStream os= null;
os = new FileOutputStream(file);