Android Tutorial Read / Write Excel files on Android

Status
Not open for further replies.

texwillerx

Member
Licensed User
Longtime User
Dear Erel,

Would you please give me an example on how to use cellformat/getpattern method of the jar (as well as the other methods).

Thanks in advance.


After some research, I came to the following point:

Dim cellformat As Object
Dim cell,range,pattern As Object
Dim r As Reflector
r.Target=moviesSheet
cell=r.RunMethod2("getCell","B3","java.lang.String")
r.Target=cell
cellformat=r.RunMethod("getCellFormat")
r.Target=cellformat
pattern=r.RunMethod("getPattern")

Now, pattern is of type
jxl.format.Pattern

How can I refer to its properties?

OK! Problem is solved.

Just use the above code with the folowing code:

r.Target=pattern
a=r.RunMethod("getDescription")

Now a contains the textual description of the pattern.

Thanks for everybody who created Reflection library and JXL package.
 
Last edited:

texwillerx

Member
Licensed User
Longtime User
While running the example program, in the watch window, the moviessheet variable as well as the other variables that I have defined (cell, cellformat, etc.) shows several members.

When I try to use access these members (e.g. cell.cellFormat) I get some errors.

For example, if I use moviesSheet.cells(1,1) then I get "Unkown member cells".

If I use cell.cellFormat, I get "Unknown type: object".

How can I access the members of these variables which are shown in the watch window?
 

texwillerx

Member
Licensed User
Longtime User
Erel, thank you very much for your reply. I think JavaObject is more appropriate to access the internal members. When used as follows, I achived perfect results:

Dim cellformat As JavaObject
Dim cell,range,pattern As JavaObject
Dim r As Reflector,a As String

cellformat.InitializeStatic("jxl.format.CellFormat")
pattern.InitializeStatic("jxl.format.Pattern")

...

r.Target=moviesSheet
a=alpha(i)& (row+1)
cell=r.RunMethod2("getCell",a,"java.lang.String")
cellformat=cell.RunMethodJO("getCellFormat",Null)
pattern=cellformat.RunMethodJO("getPattern",Null)
a=pattern.RunMethod("getDescription",Null)
 

laiberica

Member
Licensed User
Longtime User
Hello, i have a little big problem.
I upload two pics with the problem.
When i save the new workbook (copy of original) it changes the page adjust of the original, and when you print it the format printed is different.
Can you help me with this? thanks!
 

Attachments

  • Before.jpg
    55.3 KB · Views: 704
  • After.jpg
    55.5 KB · Views: 674

Erel

B4X founder
Staff member
Licensed User
Longtime User

laiberica

Member
Licensed User
Longtime User

I have an error that says:

java.lang.runtimeException:Method:setOrientation not found in:
jxl.write.biff.WritableSheetImpl

jxl.jar is in the libraries folder
note: i dont see the reference in Libs tab B4A but it is in the folder
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
jxl.jar is in the libraries folder
note: i dont see the reference in Libs tab B4A but it is in the folder
It is referenced automatically when you add a reference to Excel library.

About the error. My code above was wrong. It should be:
B4X:
Dim jo As JavaObject = Sheet1
Dim settings As JavaObject = jo.RunMethod("getSettings", null)
settings.RunMethod("setOrientation", Array("LANDSCAPE"))
 

laiberica

Member
Licensed User
Longtime User

Thanks, i understand it now.

Respect to the error now it's another whit that code

"java.lang.RuntimeException: Method: setOrientation not matched."
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I assumed that PageOrientation is an enum. This is incorrect. However it is just an example. You need to find the settings that you are looking for.

The correct code for setOrientation is:
B4X:
Dim o As JavaObject
o.InitializeStatic("jxl.format.PageOrientation")
settings.RunMethod("setOrientation", Array(o.GetField("LANDSCAPE"))
 

tdocs2

Well-Known Member
Licensed User
Longtime User
Greetings, all. Thank you in advance for answering my question.

Thank you, Erel for a great, easy to use, and very useful library.

Question:
I would like to add a description(multi-line) to the xls Worksheet. For instance, in Erel's example, the description would be "Movies by Category - dated 08/17/2014".
How could I accomplish this? I would intend to print the xls from the Android tablet.

Alternative:
If that is not possible, could the name of the sheet print?

Alternative:
Insert a row with the description above the header containing the column names???

Best regards.

Sandy
 

tdocs2

Well-Known Member
Licensed User
Longtime User
Thank you, Erel.

I suspected as much. The key to my question was adding a single or multi-line description such as "Movies by Category - dated 08/17/2014" on top of the xls or a work-around of some sort.

Best regards.

Sandy
 

msfactory

Member
Licensed User
Longtime User
I'm sorry English is poor.
In this excelexample, image as (google quickoffice), please tell me how to highlight the selected cells.
Thank you very much in advance.
 

Attachments

  • Screenshot_2014-09-25-21-45-31.png
    83.6 KB · Views: 676
  • Screenshot_2014-09-25-21-45-31.png
    83.6 KB · Views: 598

msfactory

Member
Licensed User
Longtime User
Thank you, Erel
I was able to achieve the goal by using this code.

lbls = visibleRows.Get (rows)
lbls (COL) .Color = Colors.xxx

B4A is really the best.
 

agus mulyana

Member
Licensed User
Longtime User
Execuse me

Hi all, if I want to Open an excell file, from my SD Card, anyone can help me ? thank you
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…