Android Question Read Rows from a Excel File

FabianGS

Member
Hello guys, hope you are doing well!
I have been trying to extract some values of a Excel, everything just works fine but im having some issues with the reading of this values.
What i did first:
Sub CC_Result (Success As Boolean, Dir As String, FileName As String)
    
    Dim suC As StringUtils
    
    
    MyListC.Initialize
    HeaderC.Initialize
    
    If Success = True Then
        ToastMessageShow("Success", True)
        'MyListC = suC.LoadCSV2(File.DirAssets, "EJEMPLO.csv", ",", HeaderC)
        MyListC = suC.LoadCSV2(Dir, FileName, ",", HeaderC)
        'MyListC = suC.LoadCSV2(Dir, FileName, ",", HeaderC)
        
    Else
        ToastMessageShow("No Success :(",True)
    End If
    
    Log(HeaderC.Get(0))
    Log(HeaderC.Get(1))
    Log(HeaderC.Get(2))
    Log(HeaderC.Get(3))
    Log(HeaderC.Get(4))
    Log(HeaderC.Get(5))
    Log(HeaderC.Get(6))
    Log(HeaderC.Get(7))
    Log(HeaderC.Get(8))
    Log(HeaderC.Get(9))
    
    NName = HeaderC.Get(0)
    
    Connection.Cursor = Connection.LocalSQL.ExecQuery("CREATE TABLE IF NOT EXISTS "& HeaderC.Get(0) &" (ID TEXT PRIMARY KEY, ProjectName TEXT, Name TEXT, Object TEXT, Type INTEGER, LocX INTEGER, LocY INTEGER, WidthX INTEGER, HeightY INTEGER, Color INTEGER, Registro INTEGER)")
    
    Log("Tabla Importada Y Creada")
    
    IDFind0
    
    Connection.LocalSQL.ExecNonQuery("INSERT INTO "& HeaderC.Get(0) &" VALUES('"& IDNum &"','"& HeaderC.Get(0) & "','"& HeaderC.Get(1) & "', '"& HeaderC.Get(2) &"' ,'"& HeaderC.Get(3) & "','"& HeaderC.Get(4) & "','"& HeaderC.Get(5) & "','"& HeaderC.Get(6) & "','"& HeaderC.Get(7) & "', '" & HeaderC.Get(8) & "', '"& HeaderC.Get(9) &"')")
        
    ShowDataBase
    
End Sub


So far so good, but as you can see this suC.LoadCSV2 just returns the first row infomations stored in it. I tried to use the LoadCSV but when i tried to log it, gives me some strange characters.
Why is this happenning?
Quick SS from the Excel file

1700686202314.png


and the result from the first logs i put
1700686257706.png
 
Solution
Connection.LocalSQL.ExecNonQuery("INSERT INTO "& HeaderC.Get(0) &" VALUES('"& IDNum &"','"& HeaderC.Get(0)
1. Please don't post such code. Learn how to use parameterized queries. It is very very simple.

2. Code and logs should be posted as text.

The header list stores the values of the first row.
Use su.LoadCSV instead of LoadCSV2 as your table doesn't include a header.

B4X:
For Each row() As String In MyListC 
 Log(row(0))
 Log(row(1))
Next

Erel

B4X founder
Staff member
Licensed User
Longtime User
Connection.LocalSQL.ExecNonQuery("INSERT INTO "& HeaderC.Get(0) &" VALUES('"& IDNum &"','"& HeaderC.Get(0)
1. Please don't post such code. Learn how to use parameterized queries. It is very very simple.

2. Code and logs should be posted as text.

The header list stores the values of the first row.
Use su.LoadCSV instead of LoadCSV2 as your table doesn't include a header.

B4X:
For Each row() As String In MyListC 
 Log(row(0))
 Log(row(1))
Next
 
Upvote 0
Solution
Top