B4J Question POI Header/Footer - data, page, numpages

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Dim sheetJo As JavaObject = Sheet1
Dim header As JavaObject = sheetJo.RunMethod("getHeader", Null)
Now you can call the methods from that link.

The header/footer allows me to set the variable for showing the date, page number, numpages, etc

Tried
Dim sheetJo As JavaObject = Sheet1
Dim header As JavaObject = sheetJo.RunMethod("getHeaderFooter", Null)

but this fails. Also tried HeaderFooter

Sorry for all these questions.
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Been able to do it using VB codes https://msdn.microsoft.com/en-us/library/bb225426(v=office.12).aspx

B4X:
  Dim sheetJo As JavaObject = Sheet
   Dim header As JavaObject = sheetJo.RunMethod("getHeader", Null)
   
   header.RunMethod("setLeft", Array("&B&D&B"))
   header.RunMethod("setCenter", Array("&B" &Text &"&B"))
   header.RunMethod("setRight", Array("&BPage &P"  &" of " &"&N&B"))

But that doesn't help me change the font size in the header or footer.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Here is the link for the formatting codes that can be used for the underlying XSSHeaderFooter class: https://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/extensions/XSSFHeaderFooter.html

The two codes you are looking for are (as per documentation above):

&font size
code for "text font size", where font size is a font size in points.

&"font name,font type"
code for "text font name" and "text font type", where font name and font type are strings specifying the name and type of the font, separated by a comma. When a hyphen appears in font name, it means "none specified". Both of font name and font type can be localized values.

It took me a couple of tries to see how font size works, but this stackoverflow post helped me figure it out.

So on your left side code if I want to use Arial font with bold type at size 24 the formatting code would be:

B4X:
header.RunMethod("setLeft", Array($"&"Arial,Bold"&24&D"$))

Please note that I used a Smart String Literal to make the embedding of quotes easier.
 
Upvote 0
Top