Is it possible to define only one font/cell style/data object and just change the values as needed before calling AirExcel_setCellValuexxxx or would subsequent cell style changes affect previously updated cells?
Unconfigured Ad Widget
Collapse
Announcement
Collapse
No announcement yet.
Using the same font/cell style/data format objects instead of different copies
Collapse
X
-
Absolutely. You could just add the HSSFCellStyle_setFont code within your AirExcel_getCell procedure, right after you create your cell and it will automatically assign your default when the cell is created.
Or, instead of creating the default font each time in AirExcel_getCell method, you could set up a global font object in your service program that is accessible to all the procedures and initialize it to some default setting somewhere in the SvAirExcel service program, like maybe in the AirExcel_getWorkbook procedure, then it only gets created once per worksheet.
This will assign a default font to the cell when you create it, then you could assign a different font after you create it to override the default.
-
On re-reading your question, I see that you may be attempting to set a cell with one font, then changing the font and trying to reuse the font with different settings on subsequent cells. This will not work as it is. This is because the font is passed by reference, so any updates to the font object will also affect all the cells that are using it.
You could get around this by cloning the font object before you pass it in. This would create an different object so that it will not be impacted by changes to the font object. But, this would create a different font object for each cell and you'd have to clean up after yourself.
I would probably do something like what I described in my previous response.
Have a great day,
Tom
Comment
-
I thought I was already doing that. I have two sets of objects for font/cellstyle/dataformat. One set has a "norm" suffix...one has a "chg" suffix. Before I write the cell value, if the formatting needs to be changed from the previous cell written I load up some parameters and call subroutine "set_cellstyle". In this subroutine, I first copy the "norm" objects to the "chg" objects to start clean. I then change things (font color/alignment/data formatting/etc.) based on the passed parameters. I then use the cellstyle with the "chg" suffix as the third parameter when I come out of the subroutine and set the cell value.
This works for the first cell:
On the next cell, I change the horizontal alignment from left to center, set the next cell value and then I see that the horizontal alignment from the first cell changed.
Why is this?
Comment
-
To clarify, when I say I "copy the norm objects to the chg objects to start clean", I'm doing it this way:
Code:D #lcfontnorm s like(HSSFFont) D #lcfontchg s like(HSSFFont) D #lcdtafmtnorm s like(HSSFDataFormat) D #lcdtafmtchg s like(HSSFDataFormat) D #lcstylenorm s like(HSSFCellStyle) D #lcstylechg s like(HSSFCellStyle) ... // Reset font/dataformat/style back to normal #lcfontchg = #lcfontnorm; #lcdtafmtchg = #lcdtafmtnorm; #lcstylechg = #lcstylenorm;
Last edited by Guest; 11-12-2010, 11:04 AM.
Comment
-
I think they do take up the same space based on what I just found in the RPGIV manual...
A Java object is viewed as an object reference in RPG. This object reference is an integer value, which behaves like a pointer. Normal object references are positive values, assigned in increasing order from 1. Global references, which can be created using JNI function NewGlobalRef , are negative values. These values are assigned in increasing order from the smallest negative number (-2147483647). Normally, these values are not visible within the RPG code. However, this information may be useful when debugging RPG code.
So now the question is...how do I copy the contents of one java object to another without destroying and recreating the object each time?
Comment
-
Yes, when you create an object, the reference is to the address of the object. When you have another reference variable set to the same address, then both will be pointing to the same object.
You could check this a couple of ways:
- Set ObjectA = ObjectB,
- Look at the value of both reference variables, they will be the same
- Then change one of the attributes of one and then review the values of the other to see if they were changed
To make a copy, you would clone the object, which is a method that allows you to make a copy of the object.
Comment
Comment