Android Question Excel columns

palmaf

Member
Licensed User
Longtime User
it is possible to insert an existing Excel spreadsheet keeps the size of the columns ?
Thanks
 

eps

Expert
Licensed User
Longtime User
Hi @palmaf what exactly are you trying to achieve? Are you able to break down your question in to some steps or screenshots?

i.e. are you asking about displaying an Excel spreadsheet within your own App on a device?

or

creating an Excel spreadsheet or CSV using an App of your own and then using it on a desktop?
 
Upvote 0

palmaf

Member
Licensed User
Longtime User
Hi eps,
insert an existing Excel spreadsheet in my app and see the columns with the size exactly as they are on the excel sheet
 
Upvote 0

palmaf

Member
Licensed User
Longtime User
My original sheet has two columns one in four digits and the other forty digits on my app the two columns are exactly alike
 
Upvote 0

palmaf

Member
Licensed User
Longtime User
B4X:
Sub LoadTable(Dir As String, FileName As String)
    Dim workbook1 As ReadableWorkbook
    Dim moviesSheet As ReadableSheet
    workbook1.Initialize(Dir, FileName)
    moviesSheet = workbook1.GetSheet(0)
    table1.Initialize(Me, "Table1", moviesSheet.ColumnsCount)
    table1.AddToActivity(Activity, 0, 0, 100%x, 100%y)
    For row = 0 To moviesSheet.RowsCount - 1
        Dim values(moviesSheet.ColumnsCount) As String
        For i = 0 To values.Length -1
            values(i) = moviesSheet.GetCellValue(i, row)
        Next
        If row = 0 Then
            table1.SetHeader(values)
        Else
            table1.AddRow(values)
        End If
    Next

End Sub
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Ah, okay... so you're using this https://www.b4x.com/android/forum/threads/read-write-excel-files-on-android.25632/ to read the file

I'm not sure the particular class you need has been surfaced in the library above - but it probably could be. It wraps the following : http://jexcelapi.sourceforge.net/resources/javadocs/2_6_10/docs/jxl/Sheet.html#getColumnView(int)

Which from within I think you need :

getColumnView
public CellView getColumnView(int col)
Gets the column width for the specified column


Parameters:
col - the column number
Returns:
the column format, or the default format if no override is specified

That's a bit out of my comfort zone - but someone else may well be able to help you with that... Actually @Erel may be the best port of call for this - as the library 'only' contains a few classes and the one above is not one of them. The Excel wrapper doesn't contain the source code used either - so it may well be easier for Erel to add this - or possibly make the source code available or point us in the right direction to make the changes necessary. I guess most users of the library aren't looking to perform this action. To be honest I'm not sure about you needing it either...

You could always perform a character count of all cells and get the most characters in either column and then set the width according to this - a possibly workaround if the changes you need don't get added to the library.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…