Looping through DB and saving to excel
Thank you Erel did see that one but thought you cannot modify a excel file already created
Will play around with it and if I struggle I will get back to you.
I tried this post but seems to me that the headers are only string values and it does not save any values that is in my db.
http://www.b4x.com/forum/basic4android-updates-questions/24990-database-db-csv.html#post144802
How do you loop through a database that you created through dbutils?
I want to select all my data that is stored in table and go through each record and then use that excel values to save each one using something like this you created:
For col = 0 To table1.NumberOfColumns - 1
For row = 0 To table1.Size - 1
Dim cell As WritableCell
cell.InitializeText(col, row + 1, table1.GetValue(col, row))
cell.SetCellFormat(rowsFormat)
sheet1.AddCell(cell)
Next
Next
Then you can just save the last cell value position in db and then select that value to continue to save data or go to next line?
Here is my code for this activity.
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim SQL As SQL
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
'My text boxes and spinner
Dim SpnPerson As Spinner
Dim txtAssignment As EditText
Dim txtDwelling As EditText
Dim Txtphone As EditText
Dim txtPhysical As EditText
Dim txtPSUNumber As EditText
Dim TxtQuestionare As EditText
Dim Button1 As Button
'Dim WebView1 As WebView
Dim WebView1 As WebView
Dim db As db 'Dims a variable to use for the db class
db.Initialize(Me) 'Initializes the db object for use, pass Me so the class will know the calling Activity
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
'Create DB
SQL.Initialize(File.DirRootExternal,"Food.db",True)
End If
'Do not forget to load the layout file created with the visual designer. For example:
'Load layout and add data to spinners
Activity.LoadLayout("SectionA")
SpnPerson.Add("1")
SpnPerson.Add("2")
SpnPerson.Add("3")
SpnPerson.Add("4")
SpnPerson.Add("5")
SpnPerson.Add("6")
SpnPerson.Add("7")
SpnPerson.Add("8")
SpnPerson.Add("9")
SpnPerson.Add("10")
'create my db attributes
Dim m As Map
m.Initialize
m.Put("ID",DButils.DB_TEXT)
m.Put("PSUNumber",DButils.DB_TEXT)
m.Put("Assignment",DButils.DB_TEXT)
m.Put("DwellingUnitNumber",DButils.DB_TEXT)
m.Put("DwellingID",DButils.DB_TEXT)
m.Put("Telephonenumber",DButils.DB_TEXT)
m.Put("TotalPersons",DButils.DB_TEXT)
m.Put("Questionarenumber",DButils.DB_TEXT)
DButils.CreateTable(SQL,"SectionA",m,"ID")
'ShowTableInWebView
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub SpnPerson_ItemClick (Position As Int, Value As Object)
End Sub
Sub Button1_Click
'After data is entered and the continue button is clicked it will save the data to database
Dim SectionAlist As List
SectionAlist.Initialize
Dim m As Map
m.Initialize
m.Put("ID",Null)
m.Put("PSUNumber",txtPSUNumber.Text)
m.Put("Assignment",txtAssignment.Text)
m.Put("DwellingUnitNumber",txtDwelling.Text)
m.Put("DwellingID",txtPhysical.Text)
m.Put("Telephonenumber",Txtphone.Text)
m.Put("TotalPersons",SpnPerson.SelectedItem)
m.Put("Questionarenumber",TxtQuestionare.Text)
SectionAlist.Add(m)
DButils.InsertMaps(SQL,"SectionA",SectionAlist)
End Sub
Thank you so much for all your help!