• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Cursor values to JXL

GoRo2010

Lurker
Good Day,

I am faced with a problem.
I have an SQL database that I have populated with all required information, I need to extract the tabels from the SQL and populate an XLS sheet via JXL, my coding for JXL is working fine but I need a method where I can pull all INT values from SQL to JXL and populate the cells with all the SQL values.
Please find my cursor below:

if (cursor.moveToFirst()) { do {
Contact contact = new Contact();
contact.setID(Integer.parseInt(cursor.getString(0)));
contact.setName(cursor.getString(1));
contact.setPhoneNumber(cursor.getString(2));
contact.setModel(cursor.getString(3));
// Adding contact to list
contactList.add(contact);
} while (cursor.moveToNext());
}

Here is my JXL button I have created:

Button Name4 = (Button) findViewById (R.id.Submit1);

Name4.setOnClickListener(new OnClickListener() {

EditText Name = (EditText) findViewById (R.id.Name1); EditText Number = (EditText) findViewById (R.id.Number1);
EditText Model = (EditText) findViewById (R.id.Model1);

@Override
public void onClick(View arg0) {


// TODO Auto-generated method stub
String Name1 = Name.getText().toString();
String Number1 = Number.getText().toString();
String Model1 = Model.getText().toString();


// Log.d("Insert: ", "Inserting ..");
db.addContact(new Contact(Name1, Number1, Model1));

// Log.d("Reading: ", "Reading all contacts..");
List<Contact> contacts = (List<Contact>) db.getAllContacts();


for (Contact cn : contacts) {
String log = "Id: "+cn.getID()+" ,Name: " + cn.getName() + " ,Phone: " + cn.getPhoneNumber() + " ,Model: " + cn.getModel();

// Writing Contacts to log
Log.d("Name: ", log);

Name.setText("");
Number.setText("");
Model.setText("");

try {

WorkbookSettings wbSettings = new WorkbookSettings();

wbSettings.setLocale(new Locale("en", "EN"));


try {

int a = cn.getID();
String b = cn.getName();
//int c = Integer.parseInt(b);
WritableWorkbook workbook = Workbook.createWorkbook(new File("/sdcard/CoolerMV.xls"));
//workbook.createSheet("Report", 0);
WritableSheet sheet = workbook.createSheet("Form", 0);
Label label = new Label(0, 2, "SECOND");
Label label1 = new Label(0,1,"first");
Label label0 = new Label(0,0,"HEADING");
Label label3 = new Label(1,0,"Heading2");
int row = sheet.getRows();
Label label4 = new Label(6,row ,String.valueOf(a));
Label label5 = new Label(0,14 ,String.valueOf(log));

for (int i = cn.getID(); i < 20; i++) {

Label label6 = new Label(5, i, "Boring text " + b);

workbook.write();
try {
workbook.close();
} catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//createExcel(excelSheet);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}finally{

}


}

}

I get the values pulled from the SQL to JXL but it overwrites the one line everytime.
Any help would be appricated.
Thanks
 
Back
Top Bottom