Android Question Download excel workbook into Flexable Table class

klaus

Expert
Licensed User
Longtime User
Here you are.
I added a LoadExcel method to the class in version 2.28, included in the zip file.
B4X:
Table1.LoadExcel(File.DirAssets, "test.xls", True)

You could also use the code below with Table version 2.27
B4X:
Private Workbook1 As ReadableWorkbook
Private Sheet1 As ReadableSheet
Workbook1.Initialize(File.DirAssets, "test.xls")
Sheet1 = Workbook1.GetSheet(0)

Table1.InitializeTable(Sheet1.ColumnsCount, Gravity.CENTER, False)
For row = 0 To Sheet1.RowsCount - 1
    Private values(Sheet1.ColumnsCount) As String
    For col = 0 To Sheet1.ColumnsCount - 1
        values(col) = Sheet1.GetCellValue(col, row)
    Next
    If row = 0 Then
        Table1.SetHeader(values)
        Table1.SetAutomaticWidths
    Else
        Table1.AddRowAutomaticWidth(values)
    End If
Next
 

Attachments

  • TableLoadExcel.zip
    43.4 KB · Views: 393
Upvote 0

trueboss323

Active Member
Licensed User
Longtime User
Thank you Klaus , that worked just as great! My other problem is trying to scale the table to work for different devices. I'm generally trying to avoid horizontal scrolling and have the width of the entire table fit the screen size.
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
When using the Flexible Table you can create each column adding the header name and setting each column width manually using %x. So if example if you have 7 columns, as long as the total %x don't exceed 100 (which is 100%x (width)) then you will not get a horizontal slider.

The above works then loading databases, so I presume it will also work with Excel workbooks.
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
I'm generally trying to avoid horizontal scrolling and have the width of the entire table fit the screen size.
Instead of this line:
Table1.LoadExcel(File.DirAssets, "test.xls", True)
use this code:
B4X:
Table1.LoadExcel(File.DirAssets, "test.xls", False)
Private NbCols As Int
NbCols = Table1.NumberOfColumns
Private Widths(NbCols) As Int
For i = 0 To NbCols - 1
   Widths(i) = Table1.Width / NbCols
Next
Table1.SetColumnsWidths(Widths)
 
Upvote 0
Top