digitalwise
asked on
cfspreadsheet
We have an excel file (xlsm) that we are adding data to. The first bunch of writes work just fine but I am trying to write multiple lines to a specific worksheet and it just comes up blank.
I start by reading the sheet
The I am making my query which outputs in a cfdump so I know that it is populated.
This has all of the data I am expecting
<CFDump var="#q#">
I populate the query and then I end with
It is blank. I know it isn't writing anything at all because i Put some junk text on that worksheet and it is still there. What the heck am I missing?
I start by reading the sheet
<cfspreadsheet action="read"
src="#application.loadpath#\#Session.NewWorking#"
name="RawData"
SHEET="6" />
The I am making my query which outputs in a cfdump so I know that it is populated.
<cfset q = queryNew("PropertyID, PICDevNo, PropertyName, PHAName, CHAPIssuedDate, FncgPlanDueDate, FncgPlanSubmissionDate, FncgPlanAcceptedDate, AnticipatedRCCDate, RCCIssuedDate, ExpectedCloseDate, ClosingDate, TotalUnits, NoUnitsConvertingtoRAD, GPRMarketRateApartmentsUnits, GPRAffordableApartmentsUnits_Other, TransactionManager, ClosingCoordinator, PHASize, PHACode, ConstructionCosts, RHF, PHOperatingReserves, PHCapFunds, MortgageAmt, LIHTC9, LIHTC4, OtherFunding1, OtherFunding2, OtherFunding3, OtherFunding4, OtherFunding5, OtherFunding6, FHAInsurance, Region, SubsidyType, PartPortfolioAward, PartMPAward, NewConstruction, HAPContractNumber", "cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar, cf_sql_varchar")>
This has all of the data I am expecting
<CFDump var="#q#">
I populate the query and then I end with
<cfscript>
SpreadsheetAddRows(RawData,q);
</cfscript>
<cfspreadsheet action="write" overwrite="true"
filename="#application.loadpath#\#Session.NewWorking#"
name="RawData" />
It is blank. I know it isn't writing anything at all because i Put some junk text on that worksheet and it is still there. What the heck am I missing?
Just for grins, any difference if you use functions instead of cfspreadsheet ?
<!--- use a different file name for testing, just to rule out possible file locking issues --->
<cfset SpreadSheetWrite(RawData, "c:\temp\DifferentFileName .xlsm", true)>
<!--- use a different file name for testing, just to rule out possible file locking issues --->
<cfset SpreadSheetWrite(RawData, "c:\temp\DifferentFileName
ASKER
So I have been trying a whole bunch of things trying to figure this out. The problem I think is that I have null values in the query - not all of of them are populated. I changed it out to a straight, clean CFQUERY and then a straight
and get
An exception occurred while using action=write.
java.lang.NullPointerExcep tion
I tried
and that works but I didn't know how to loop the query in cfscript and read/write for 1500 lines is stupid. So these null values...
<cfspreadsheet action="write" overwrite="true"
filename="#application.loadpath#\#Session.NewWorking#"
sheetname="Data-HUDStat Report" query="PropertiesClosed" />
and get
An exception occurred while using action=write.
java.lang.NullPointerExcep
I tried
spreadsheetSetCellValue(sObj,#propertyid#,#currentrow#+1,1);
spreadsheetSetCellValue(sObj,#propertyname#,#currentrow#+1,2);
spreadsheetSetCellValue(sObj,#pha_name#,#currentrow#+1,3);
spreadsheetSetCellValue(sObj,#dateformat(complete180, "mm/dd/yyyy")#,#currentrow#+1,4);
spreadsheetSetCellValue(sObj,#dateformat(accepted, "mm/dd/yyyy")#,#currentrow#+1,5);
spreadsheetSetCellValue(sObj,#dateformat(RCCIssuedDate, "mm/dd/yyyy")#,#currentrow#+1,6);
spreadsheetSetCellValue(sObj,#dateformat(actclosedate, "mm/dd/yyyy")#,#currentrow#+1,7);
spreadsheetSetCellValue(sObj,#nounitconvert#,#currentrow#+1,8);
spreadsheetSetCellValue(sObj,#ReReplaceNoCase(cccost,"[^0-9.]","","ALL")#,#currentrow#+1,9);
and that works but I didn't know how to loop the query in cfscript and read/write for 1500 lines is stupid. So these null values...
ASKER
Your sample didn't work either. I just tried it. WTH!!!
ASKER
I have 10 locally and 11 on the production server and it doesn't work there either.
ASKER
My file is an .xlsm file - maybe that is the issue?
ASKER
The rest of it writes though - why would that be an issue?
Didn't even work with the sample query? Now that's really weird...
I tried creating some null values manually:
<!--- deliberately make these NULL --->
<cfset row = queryAddRow(q, 1)>
<cfset q.RCCIssuedDate[row] = javacast("null", "")>
<cfset q.PropertyID[row] = javacast("null", "")>
and via a db query - but so far no luck reproducing that error.
<cfquery name="q" datasource="#myDSN#">
SELECT NULL AS PropertyID, NULL AS RCCIssuedDate UNION ALL
SELECT '1' AS PropertyID, getDate() AS RCCIssuedDate
</cfquery>
What version of CF? There's some major differences in the spreadsheet stuff between 9, 10 and 11.
I tried creating some null values manually:
<!--- deliberately make these NULL --->
<cfset row = queryAddRow(q, 1)>
<cfset q.RCCIssuedDate[row] = javacast("null", "")>
<cfset q.PropertyID[row] = javacast("null", "")>
and via a db query - but so far no luck reproducing that error.
<cfquery name="q" datasource="#myDSN#">
SELECT NULL AS PropertyID, NULL AS RCCIssuedDate UNION ALL
SELECT '1' AS PropertyID, getDate() AS RCCIssuedDate
</cfquery>
What version of CF? There's some major differences in the spreadsheet stuff between 9, 10 and 11.
>> My file is an .xlsm file - maybe that is the issue?
I don't see why, but ... yes I was wondering that too. I was going to ask if you get the same error with .xlsx and/or .xls files too.
I don't see why, but ... yes I was wondering that too. I was going to ask if you get the same error with .xlsx and/or .xls files too.
ASKER
I just tried .xlsx and that didn't work either - I can write all I want but I can't write a row. The only thing that has worked is a loop but I don't know how to loop a query in cfscript so I only have to write once. It is too slow to read/write each time - 1500 lines... We are using 10 and 11. Doesn't work on either of them.
spreadsheetSetCellValue(sObj,#propertyid#,#currentrow#+1,1);
spreadsheetSetCellValue(sObj,#propertyname#,#currentrow#+1,2);
spreadsheetSetCellValue(sObj,#pha_name#,#currentrow#+1,3);
spreadsheetSetCellValue(sObj,#dateformat(complete180, "mm/dd/yyyy")#,#currentrow#+1,4);
spreadsheetSetCellValue(sObj,#dateformat(accepted, "mm/dd/yyyy")#,#currentrow#+1,5);
spreadsheetSetCellValue(sObj,#dateformat(RCCIssuedDate, "mm/dd/yyyy")#,#currentrow#+1,6);
spreadsheetSetCellValue(sObj,#dateformat(actclosedate, "mm/dd/yyyy")#,#currentrow#+1,7);
spreadsheetSetCellValue(sObj,#nounitconvert#,#currentrow#+1,8);
spreadsheetSetCellValue(sObj,#ReReplaceNoCase(cccost,"[^0-9.]","","ALL")#,#currentrow#+1,9);
I think CF10 supports query for loops. Does this test work for you under CF10?
<cfscript>
q = queryNew("");
queryAddColumn(q, "colA", [1,18,46,45]);
queryAddColumn(q, "colB", [1,18,46,45]);
for (row in q ){
writeDump(row.colA);
writeDump(row.colB);
}
</cfscript>
<cfscript>
q = queryNew("");
queryAddColumn(q, "colA", [1,18,46,45]);
queryAddColumn(q, "colB", [1,18,46,45]);
for (row in q ){
writeDump(row.colA);
writeDump(row.colB);
}
</cfscript>
ASKER
That does - so how do I translate writeDump for the code above?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
As usual - THANK YOU!
You're welcome. Anytime :)
Then ran the test code:
Open in new window
And the data was added to the 6th sheet as expected: