3
Sqliteデータベース経由でAmountという名前の列を合計するにはどうすればよいですか?私は金額を入力した金額を加算したいと思っています。挿入している間にダイプレイを作成しました。作成されたExcelシートに金額の合計が表示されました。よろしくお願いします。アドバンスでお願いします。SqliteデータベースのVeritacal Columを合計してExcelシートでエクスポートする方法
public void saveExcelFile() {
try {
dbHelper = new DBHelper(MainActivity.this);
final Cursor cursor = dbHelper.getuser(selectedDate);
//create directory if not exist
if (!directory.isDirectory()) {
directory.mkdirs();
}
File file = new File(directory, edtDate.getText().toString() + ".xls");
WorkbookSettings wbSettings = new WorkbookSettings();
wbSettings.setLocale(new Locale("en", "EN"));
WritableWorkbook workbook;
workbook = Workbook.createWorkbook(file, wbSettings);
//Excel sheet name. 0 represents first sheet
WritableSheet sheet = workbook.createSheet("userList", 0);
// column and row
sheet.addCell(new Label(0, 0, "id"));
sheet.addCell(new Label(1, 0, "name"));
sheet.addCell(new Label(2, 0, "email"));
sheet.addCell(new Label(3, 0, "date"));
sheet.addCell(new Label(4, 0, "amount"));
if (cursor.moveToFirst()) {
do {
String id = cursor.getString(cursor.getColumnIndex("id"));
String name = cursor.getString(cursor.getColumnIndex("name"));
String email = cursor.getString(cursor.getColumnIndex("email"));
String date = cursor.getString(cursor.getColumnIndex("date"));
String amount = cursor.getString(cursor.getColumnIndex("amount"));
int i = cursor.getPosition() + 1;
sheet.addCell(new Label(0, i, id));
sheet.addCell(new Label(1, i, name));
sheet.addCell(new Label(2, i, email));
sheet.addCell(new Label(3, i, date));
sheet.addCell(new Label(4, i, amount));
} while (cursor.moveToNext());
}
//closing cursor
cursor.close();
workbook.write();
workbook.close();
Toast.makeText(getApplication(), "Data Exported in a Excel Sheet", Toast.LENGTH_SHORT).show();
} catch (WriteException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}