将SQLite中的数据转换为Excel表
此程序能将指定SQlite数据库中的数据转换为Excel表格形式
package zhaoxing.android.tool;
import java.io.File;
import java.io.IOException;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
public class DatabaseDump {
private String mDestXmlFilename;
private SQLiteDatabase mDb;
public DatabaseDump(SQLiteDatabase db, String destXml) {
mDb = db;
mDestXmlFilename = destXml;
}
public void exportData() {
try {
// Log.i("mdb", mDb.getPath());
// get the tables out of the given sqlite database
String sql = "SELECT * FROM sqlite_master";
Cursor cur = mDb.rawQuery(sql, new String[0]);
cur.moveToFirst();
String tableName;
while (cur.getPosition() < cur.getCount()) {
tableName = cur.getString(cur.getColumnIndex("name"));
// don't process these two tables since they are used
// for metadata
if (!tableName.equals("android_metadata")
&& !tableName.equals("sqlite_sequence")) {
writeExcel(tableName);
}
cur.moveToNext();
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 生成一个Excel文件
*
* @param fileName
*  
相关新闻>>
- 发表评论
-
- 最新评论 更多>>