Hi Tony,
I'm not a java programmer at all,
I am not a natural Java programmer either, so I'll probably use a term incorrectly somewhere :-)
I'm not sure if this is the correct place to ask
Unless it related directly to something in this article, I would suggest in the future creating a dedicated thread in the Genero BDL board
https://forum.4js.com/fjs_forum/index.php?board=2.0I hadn't used CellUtil
https://poi.apache.org/apidocs/dev/org/apache/poi/ss/util/CellUtil.html but I was reading it it thinking I perhaps should have used it in places.
Re: your question on Java.Util.Map
I can get setCellStyleProperty() to work fine, but I want to make multiple style changes on a cell - e.g. borders all round + colours, bold, etc. - so it is recommended to use setCellStyleProperties(), which I can't get to work. I am struggling with the 'Map' java type, which I understand is an Interface type (
https://docs.oracle.com/javase/8/docs/api/java/util/Map.html).
The definition for this function is:-
public static void setCellStyleProperties(Cell cell, java.util.Map<java.lang.String,java.lang.Object> properties)
Have you come across this before ? Would you be able to please explain how to declare the 'Map'
I wonder if the pieces of the puzzle you are missing is point 1 in the limitations
http://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_JavaBridge_001.html, and secondly with Map being an Interface type it is not a case of creating something of Map type but of something that implements the Map type. You can use java.util.hashMap to implement something that matches that Interface.
After some trial and error I found that adding to fgl_excel.4gl
IMPORT JAVA org.apache.poi.ss.util.CellUtil
IMPORT JAVA org.apache.poi.ss.usermodel.IndexedColors
IMPORT JAVA org.apache.poi.ss.usermodel.BorderStyle
IMPORT JAVA java.util.HashMap
IMPORT JAVA java.lang.Integer
...
FUNCTION cellutil_set_cell_property_experiment(c cellType)
DEFINE h java.util.HashMap
LET h = java.util.HashMap.create()
CALL h.put(CellUtil.BORDER_TOP, BorderStyle.MEDIUM)
CALL h.put(CellUtil.BORDER_BOTTOM, BorderStyle.MEDIUM)
CALL h.put(CellUtil.BORDER_LEFT, BorderStyle.MEDIUM)
CALL h.put(CellUtil.BORDER_RIGHT, BorderStyle.MEDIUM)
CALL h.put(CellUtil.TOP_BORDER_COLOR, java.lang.Integer.create(IndexedColors.RED.getIndex()))
CALL h.put(CellUtil.BOTTOM_BORDER_COLOR, java.lang.Integer.create(IndexedColors.BLUE.getIndex()))
CALL h.put(CellUtil.LEFT_BORDER_COLOR, java.lang.Integer.create(IndexedColors.YELLOW.getIndex()))
CALL h.put(CellUtil.RIGHT_BORDER_COLOR, java.lang.Integer.create(IndexedColors.GREEN.getIndex()))
CALL CellUtil.setCellStyleProperties(c, h)
END FUNCTION
I then had a function I could call that utllised CellUtil.setCellStyleProperties passing in the appropriate cell
CALL fgl_excel.cellutil_set_cell_property_experiment(cell)
and it added a border around the appropriate spreadsheet cell.
The java.lang.Integer.create was required to turn the integer into an object.
One thought in general is for any complex Java that the Genero Java interface does not cater for is to create a Java class that simplifies it that you can then call with IMPORT JAVA. That is not necessary in this case but I thought I was heading in that direction if I had needed a complex equivalent of " HashMap<String, XXX> h = new HashMap<String, XXX>(); "when I couldn't figure out what XXX was required to be. As it was java.util.HashMap.create() created a suitable hashmap.
Hope that helps,
Reuben