android将数据库表导出成excel,Android程序将SQLite数据库转换为excel

这篇博客介绍了如何将Android应用中的SQLite数据库转换为CSV文件,然后进一步将CSV转换为Excel(XLS)文件。通过使用opencsv和Apache POI库,实现了在后台线程中导出数据并生成Excel文件的功能。
摘要由CSDN通过智能技术生成

我的解决方案是在第一步将sqlite数据库转换为csv然后在第二步将csv文件转换为xls并且它对我来说工作正常,你将需要2个库(opencsv-1.7.jar; poi-3.8-20120326.罐)

public class ExportDatabaseCSVTask extends AsyncTask

{

private final ProgressDialog dialog = new ProgressDialog(DatabaseExampleActivity.this);

@Override

protected void onPreExecute()

{

this.dialog.setMessage("Exporting database...");

this.dialog.show();

}

protected Boolean doInBackground(final String... args)

{

File dbFile=getDatabasePath("database_name");

//AABDatabaseManager dbhelper = new AABDatabaseManager(getApplicationContext());

AABDatabaseManager dbhelper = new AABDatabaseManager(DatabaseExampleActivity.this) ;

System.out.println(dbFile); // displays the data base path in your logcat

File exportDir = new File(Environment.getExternalStorageDirectory(), "");

if (!exportDir.exists())

{

exportDir.mkdirs();

}

File file = new File(exportDir, "excerDB.csv");

try

{

if (file.createNewFile()){

System.out.println("File is created!");

System.out.println("myfile.csv "+

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值