Android Tutorial Read / Write Excel files on Android

Status
Not open for further replies.

texwillerx

Member
Licensed 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
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
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
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

laiberica

Member
Licensed User
You can access SheetSettings with JavaObject and modify the sheet settings.

The API is described here: http://jexcelapi.sourceforge.net/resources/javadocs/2_6_10/docs/jxl/SheetSettings.html

You can get a reference to the settings with:
B4X:
Dim settings As JavaObject = Sheet1
settings.RunMethod("setOrientation", Array("LANDSCAPE"))
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

Administrator
Staff member
Licensed 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
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"))
Thanks, i understand it now.

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

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

tdocs2

Well-Known Member
Licensed 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
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
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.
 
Status
Not open for further replies.
Top