0

我正在使用数据库中的数据创建一个 csv 文件。所选消费者 ID 的所有数据都必须附加到 csv 文件中。在我的程序中,csv 文件附加在电子邮件中,假设我有 3 个选定的消费者 ID,发送的电子邮件,但是当我检查 csv 文件时,第一个选定的 ID 没有显示,第一行留空,而csv 上的第二个和第三个附加。我不知道为什么我看不到我选择的第一个 ID 的数据。请帮帮我..这是我的代码:

 private String getConsumersDetails(ArrayList<String> arraylistConsumerId)
{           
    for (int j = 0; j < arraylistConsumerId.size(); j++)
    {
            //Cursor cursorConsumerDetails = null;
            Cursor cursorConsumerDetails = databaseAdapter.getCursorRegisteredConsumer(Integer.parseInt(arraylistConsumerId.get(j)));
            //if (cursorConsumerDetails.getCount() == 0)
                //cursorConsumerDetails = databaseAdapter.getCursorRegisteredConsumer(arraylistConsumerId.get(j));
                // consumerData.append("\n"+lastname+","+firstname+","+middleinitial+","+cellphone+","+emailadd+","+carefriend+","+company+","+regdate);     

            if (cursorConsumerDetails.getCount() > 0)
            {
                lastname = cursorConsumerDetails.getString(cursorConsumerDetails.getColumnIndex(Constants.CONSUMER_LASTNAME));
                firstname = cursorConsumerDetails.getString(cursorConsumerDetails.getColumnIndex(Constants.CONSUMER_FIRSTNAME));
                middleinitial = cursorConsumerDetails.getString(cursorConsumerDetails.getColumnIndex(Constants.CONSUMER_MIDDLEINITIAL));
                cellphone = cursorConsumerDetails.getString(cursorConsumerDetails.getColumnIndex(Constants.CONSUMER_CELLPHONENO));
                emailadd = cursorConsumerDetails.getString(cursorConsumerDetails.getColumnIndex(Constants.CONSUMER_EMAIL));
                carefriend = cursorConsumerDetails.getString(cursorConsumerDetails.getColumnIndex(Constants.CONSUMER_CAREFRIEND));
                company = cursorConsumerDetails.getString(cursorConsumerDetails.getColumnIndex(Constants.CONSUMER_COMPANY));
                regdate = cursorConsumerDetails.getString(cursorConsumerDetails.getColumnIndex(Constants.CONSUMER_REGISTRATIONDATE));

                code = cursorConsumerDetails.getString(cursorConsumerDetails.getColumnIndex(Constants.CONSUMER_COMPANYCODE));


            }

            consumerData.append("\n"+lastname+","+firstname+","+middleinitial+","+cellphone+","+emailadd+","+carefriend+","+company+","+regdate);    


       }

    return consumerData.toString();
}

这个调用上面的代码......

consumerData = new StringBuilder();
                    File personFile;
                    time = String.valueOf(calendar.get(Calendar.HOUR_OF_DAY))+String.valueOf(calendar.get(Calendar.MINUTE))+String.valueOf(calendar.get(Calendar.SECOND));
                    personFile = createCSV("Person_Table_"+date+"_"+time, Constants.COLUMN_STRING_PERSON_TABLE, getConsumersDetails(arraylistConsumerId), fileCounter, false);

                    createEmailWithAttachments(personFile);

....
4

1 回答 1

0
我不知道它是如何在 android 中完成的,但总的来说
 从 sqlite3 数据库获取 csv 文件。
.mode csv
.output filename.csv
select * from table;

csv 文件将出现在存储 sqlite 数据库文件的目录中。

于 2013-06-08T10:06:02.507 回答