i am developing a app in which i need to retrieve data from sqlite database using different ids, i have done much work but my problem is when i make CSV file i get also columns names as well with every id Like i am get CSV file in this type
I am using this code
public void getData() {
File dbFile = getDatabasePath("formantime.db");
SQLITEDBTABLE dbhelper = new SQLITEDBTABLE(getApplicationContext());
File exportDir = new File(Environment.getExternalStorageDirectory(), "");
if (!exportDir.exists()) {
exportDir.mkdirs();
}
file = new File(exportDir, "FTSData.csv");
try {
file.createNewFile();
CSVWriter csvWrite = new CSVWriter(new FileWriter(file));
SQLiteDatabase db = dbhelper.getReadableDatabase();
for (String ids : TimeEntryListViewAdapter.emailintArrayList) {
curCSV = db.rawQuery("SELECT * FROM RecordsTable WHERE RecordId ='" + ids + "'", null);
csvWrite.writeNext(curCSV.getColumnNames());
if (curCSV.moveToFirst()) {
do {
//Which column you want to exprort
String[] arrStr = {curCSV.getString(0), curCSV.getString(1), curCSV.getString(2), curCSV.getString(3),
curCSV.getString(4), curCSV.getString(5), curCSV.getString(6)};
csvWrite.writeNext(arrStr);
} while (curCSV.moveToNext());
}
curCSV.close();
}
csvWrite.close();
} catch (Exception sqlEx) {
Log.e("MainActivity", sqlEx.getMessage(), sqlEx);
}
Uri u1 = null;
u1 = Uri.fromFile(file);
String[] emails;
ArrayList<String> mails = EmailReportsAdapter.emailsList;
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/richtext");
sendIntent.putExtra(Intent.EXTRA_EMAIL, mails.toArray(new String[mails.size()]));
sendIntent.putExtra(Intent.EXTRA_STREAM, u1);
try {
startActivity(Intent.createChooser(sendIntent, "Sending mail.."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(EmailReports.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
TimeEntryListViewAdapter.emailintArrayList.clear();
}
}
Please help me
