Apparently using CF 7 or 8 with POI for Excel converts sheet
reference formulas in a chart text box (POI class textRecord) on a
chart area to text even if it has a formula reference. I did see
that anything the chart itself references works fine, including
Chart Options and Source Data.
I have a workbook that I edit a particular sheet i.e.
'DataSheet' using POI successfully with ColdFusion (CF7.02 and
CF8). The problem is I have a chart on another sheet in the
workbook with a formula referencing 'DataSheet' i.e. 'Chart
Title=DataSheet!$AA$2'. Every time I use POI to modify 'DataSheet',
my formulas convert the previous value to text, but the formula in
Chart Title= [blank]. The main formula value I needed refers to
when the data was last updated by POI that I store in the
'DataSheet'. There is a Macro and the chart itself and their
references are both fine, just the standalone formula references.
Any ideas why this occurs or how to fix it without recreating the
formulas each time? I tried protecting the workbook and chart
sheets, but that did not help. Also I see how to set formulas in a
worksheet, but not for a TextRecord. How could I do that? Here is
some of my code that may be of interest:
<!--- store the packages in a variable for more compact
code --->
<cfset loHssfPkg = "org.apache.poi.hssf.usermodel">
<cfset loPoifsPkg = "org.apache.poi.poifs.filesystem">
<!--- Modify a multi-sheet Excel report using POI-HSSF
--->
<!--- Create the file input stream. --->
<cfset loFile =
createObject("java","java.io.FileInputStream").init("#lcExcelFileFullPath#")
/>
<!--- Create the Excel file system object. This object is
responsible
for reading in the given Excel file. A handle to the file.
--->
<cfset loFs =
createObject("java","#loPoifsPkg#.POIFSFileSystem").init("#loFile#")
/>
<!--- Create a handle to the workbook. --->
<cfset loWorkBook = CreateObject("java",
"#loHssfPkg#.HSSFWorkbook").init(loFs)>
<!--- Get total number of sheets in the workbook. --->
<cfset loSheetCount = loWorkBook.GetNumberOfSheets()>
<!--- Now that we have a sheets collection lets get the
one we
want to update --->
<!--- This is an index loop, but is like a while loop
here. Java is 0-based. --->
<cfloop index= "loSheetNum" from="0" to="#loSheetCount#"
step = "1">
<!--- Obtain the name of the specific sheet in the
workbook --->
<cfset loSheetName = loWorkBook.GetSheetName(JavaCast(
"int", loSheetNum)) />
<!--- Search for a match to our sheet of interest. --->
<cfif UCASE(loSheetName) EQ loDataSheetName>
<!--- Get a reference to the Sheets in the Excel
spreadsheet. It looks like
org.apache.poi.hssf.usermodel.HSSFSheet@af4653 .--->
<cfset loSheet = loWorkBook.GetSheetAt(JavaCast( "int",
loSheetNum)) />
<!--- Break out of loop if condition is met. This is like
a while loop. --->
<cfbreak>
</cfif>
</cfloop>
[Here I make my mods to the worksheet]
...
<!--- Get a handle on the file location for the workbook.
--->
<cfset loFileOut =
createObject("java","java.io.FileOutputStream").init("#lcExcelFileFullPath#")/>
<!--- Write the output to the file --->
<cfset loWorkBook.write(loFileOut) />
<!--- Close the file output stream. This will release any
locks on
the file and finalize the process. --->
<cfset loFileOut.flush() />
<cfset loFileOut.close() />