问题描述
我的目标是从表中创建一个.csv文件,打印报告。然后,我可以在此.csv文件保存到我的SD卡。我曾提到类似这样的一些问题,但他们会问一个jar文件是present。是否有任何其他方式没有一个jar文件进行整合?
My aim is to create a .csv file from a table, to print a report. I can then store this .csv file into my sdCard. I have referred to some questions similar to this but they ask a jar file to be present. Is there any other way without a jar file to be integrated?
有集成在组件au.com.byte code.opencsv.CSVWriter一个jar文件...我不觉得有什么在这里是写入到一个新的生产线的逻辑...帮助?
Have integrate a jar file in the component au.com.bytecode.opencsv.CSVWriter...What I dont find here is the logic to write into a new line...Help?
推荐答案
检查以下code,生成CSV文件。没有必要使用jar文件
check below code to generate CSV file. no need to use jar file.
你要救一个csv文件中SD卡。
you have to save one csv file in to SD-CARD.
public void exportEmailInCSV() throws IOException {
{
File folder = new File(Environment.getExternalStorageDirectory()
+ "/Folder");
boolean var = false;
if (!folder.exists())
var = folder.mkdir();
System.out.println("" + var);
final String filename = folder.toString() + "/" + "Test.csv";
// show waiting screen
CharSequence contentTitle = getString(R.string.app_name);
final ProgressDialog progDailog = ProgressDialog.show(
MailConfiguration.this, contentTitle, "even geduld aub...",
true);//please wait
final Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
}
};
new Thread() {
public void run() {
try {
FileWriter fw = new FileWriter(filename);
Cursor cursor = db.selectAll();
fw.append("No");
fw.append(',');
fw.append("code");
fw.append(',');
fw.append("nr");
fw.append(',');
fw.append("Orde");
fw.append(',');
fw.append("Da");
fw.append(',');
fw.append("Date");
fw.append(',');
fw.append("Leverancier");
fw.append(',');
fw.append("Baaln");
fw.append(',');
fw.append("asd");
fw.append(',');
fw.append("Kwaliteit");
fw.append(',');
fw.append("asd");
fw.append(',');
fw.append('\n');
if (cursor.moveToFirst()) {
do {
fw.append(cursor.getString(0));
fw.append(',');
fw.append(cursor.getString(1));
fw.append(',');
fw.append(cursor.getString(2));
fw.append(',');
fw.append(cursor.getString(3));
fw.append(',');
fw.append(cursor.getString(4));
fw.append(',');
fw.append(cursor.getString(5));
fw.append(',');
fw.append(cursor.getString(6));
fw.append(',');
fw.append(cursor.getString(7));
fw.append(',');
fw.append(cursor.getString(8));
fw.append(',');
fw.append(cursor.getString(9));
fw.append(',');
fw.append(cursor.getString(10));
fw.append(',');
fw.append('\n');
} while (cursor.moveToNext());
}
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
// fw.flush();
fw.close();
} catch (Exception e) {
}
handler.sendEmptyMessage(0);
progDailog.dismiss();
}
}.start();
}
}
在清单中添加此权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
这篇关于如何创建Android上的.csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!