是的,使用 POI Utility cfc 解决了问题。过去运行 30 分钟而超时现在只需要大约 90 秒。我已经发布了上面页面的新代码,以及我在下面创建的新 cfc 函数。
我代替使用电子表格对象所做的是创建一个新的查询对象,循环 qReconciled,并为该查询对象中的 39 列中的每一列填充一个数组。在每次循环迭代中,所有 39 个数组都会获得“STARS”行、“SACAP”行和空白行的值。然后,一旦完成所有迭代,我使用 queryAddColumn() 填充查询对象中的所有列,然后将该查询提供给 poiUtility.writeSingleExcel()。然后,excel 文件会保存到服务器上的文件夹中,但也会通过 cfheader/cfcontent 标记自动下载到用户的机器上。
动作页面:
<!---Originally used cf spreadsheet object to create Excel Export.
But this method used up too much memory; page would hang indefinitely on Production. Now using Ben Nadel's POI Utility instead.--->
<!---dates for from and to come in the format "yyyy-mm-dd"--->
<!---NOTE- if doing a date range without a specific importId, include ImportId as one of the columns in the report--->
<cfif len(trim(url.from & url.to)) AND NOT ( isDate(url.from) AND isDate(url.to) )>
<cfset url.from = "" />
<cfset url.to = "" />
</cfif>
<cfset vImportName = "" />
<cfset vDateTitle = "" />
<cfset oStarsImporter = CreateObject("component", "#application.cfcpath#.starsImporter") />
<cfset oPOI = CreateObject("component", "#application.cfcpath#.poiUtility").init() />
<cfset qReconciled = oStarsImporter.getReconciled(url.from, url.to) />
<cfset qDisplay = oStarsImporter.prepForExport(qReconciled) />
<cfif isDate(url.from) AND isDate(url.to)>
<cfif len(trim(vImportName))>
<cfset vImportName = vImportname & "-" />
</cfif>
<cfset vDateTitle = "From_" & dateFormat(url.from, "mm-dd-yyyy") & "_to_" & dateFormat(url.to, "mm-dd-yyyy") />
</cfif>
<cfset vFileName = vImportName & vDateTitle />
<cfif NOT len(trim(vFileName))>
<cfset vFileName = "All_reconciled_" & dateFormat(now(), "mm-dd-yyyy") />
<cfelse>
<cfset vFileName = vFileName & "_reconciled" />
</cfif>
<cfset oPOI.WriteSingleExcel(
FilePath=application.starsExportDirectory & vFileName & ".xls"
,query=qDisplay
,columnList="Assessment_Source,Client_Last,Client_First,SSN,Gender,Client_Case_Number,DoB,Zip_Code,Assessment_Type,Assessment_Status,NYCWAY_Appt_Code,Appt_Date,Appt_Time,CASAC_Worker,Approving_Supervisor,Benefit_Status_Case_Type,Final_Recommendation,Site_Code,Re_Assessment,Current_Living_Situation,Mental_Conditions,Candidate_for_WeCARE,Attend_Substance_Use,Agency_Name,Currently_Attending_Treatment_Program_Name,Type_of_Treatment,Opioid_Taken,Housing_Outcome,Return_to_Treatment_Provider,Non_HRA_Approved,Name_non_HRA_Site,New_Mandate,Transfer_to_New_Treatment_Provider,Check_in,Assessment_Start,Checked_Out_Time,Checked_in_Site,Addendum,Consent_B_signed"
,columnNames="Assessment Source,Client Last,Client First,SSN,Gender,Client Case Number,DoB,Zip Code,Assessment Type,Assessment Status,NYCWAY Appt Code,Appt Date,Appt Time,CASAC Worker,Approving Supervisor,Benefit Status (Case Type),Final Recommendation,Site Code,Re-Assessment,Current Living Situation,Mental Conditions,Candidate for WeCARE,Attend Substance Use,Agency Name,Currently Attending Treatment Program Name,Type of Treatment,Opioid Taken,Housing Outcome,Return to Treatment Provider,Non HRA-Approved,Name non-HRA Site,New Mandate,Transfer to New Treatment Provider,Check-in,Assessment Start,Checked Out Time,Checked-in Site,Addendum,Consent B signed"
)/>
<cfheader name="Content-Disposition" value="inline; filename=#vFileName#.xls">
<cfcontent type="application/vnd.ms-excel" file="#application.starsExcelExportURL##vFileName#.xls">
准备导出():
<cffunction name="prepForExport" returntype="query" hint="Preps query of reconciled assessments for Excel export">
<cfargument name="qReconciled" type="query" required="true" />
<cfset var qryRet = queryNew("") />
<cfset var arrAssessmentSource = arrayNew(1) />
<cfset var arrClientLast = arrayNew(1) />
<cfset var arrClientFirst = arrayNew(1) />
<cfset var arrSSN = arrayNew(1) />
<cfset var arrGender = arrayNew(1) />
<cfset var arrCaseNumber = arrayNew(1) />
<cfset var arrDob = arrayNew(1) />
<cfset var arrZip = arrayNew(1) />
<cfset var arrAssessmentType = arrayNew(1) />
<cfset var arrAssessmentStatus = arrayNew(1) />
<cfset var arrNYCApptCode = arrayNew(1) />
<cfset var arrApptDate = arrayNew(1) />
<cfset var arrApptTime = arrayNew(1) />
<cfset var arrCasacWorker = arrayNew(1) />
<cfset var arrApprovingSup = arrayNew(1) />
<cfset var arrBenStatus = arrayNew(1) />
<cfset var arrFinalRecommend = arrayNew(1) />
<cfset var arrSiteCode = arrayNew(1) />
<cfset var arrReAssess = arrayNew(1) />
<cfset var arrLivingSit = arrayNew(1) />
<cfset var arrMentalCond = arrayNew(1) />
<cfset var arrCandidateWecare = arrayNew(1) />
<cfset var arrAttendSubsUse = arrayNew(1) />
<cfset var arrAgencyname = arrayNew(1) />
<cfset var arrCurrentTxProg = arrayNew(1) />
<cfset var arrTypeTx = arrayNew(1) />
<cfset var arrOpioid = arrayNew(1) />
<cfset var arrHousingOutcome = arrayNew(1) />
<cfset var arrReturnToTxProv = arrayNew(1) />
<cfset var arrNonHRAApproved = arrayNew(1) />
<cfset var arrNameNonHRASite = arrayNew(1) />
<cfset var arrNewMandate = arrayNew(1) />
<cfset var arrXferToNewTxprov = arrayNew(1) />
<cfset var arrCheckIn = arrayNew(1) />
<cfset var arrAssessmentStart = arrayNew(1) />
<cfset var arrCheckOut = arrayNew(1) />
<cfset var arrCheckedInSite = arrayNew(1) />
<cfset var arrAddendum = arrayNew(1) />
<cfset var arrConsentBSigned = arrayNew(1) />
<cfset var tCheckin = "" />
<cfset var tAssessmentStart = "" />
<cfset var tCheckouttime = "" />
<cfset var tTimeInBin = "" />
<cfset var tApptBeginTime = "" />
<cfset var tApptEndTime = "" />
<cfset var tAppointmentTime = "" />
<cfset var tScheduledTime = "" />
<!---populate qryRet by inserting 3 rows for every row in qReconciled: one for STARS, one for SACAP, and one blank row as a seperator--->
<cfloop query="arguments.qReconciled">
<cfset tCheckin = timeformat(dcheckin,'short') />
<cfset tAssessmentStart = timeformat(dAssessmentStart,'short') />
<cfset tCheckouttime = timeformat(dCheckouttime,'short') />
<cfset tTimeInBin = timeformat(timeInBin,'short') />
<cfset tApptBeginTime = timeformat(dApptBeginTime,'short') />
<cfset tApptEndTime = timeformat(dApptEndTime,'short') />
<cfset tAppointmentTime = timeformat(dAppointmentdate,'short') />
<cfset tScheduledTime = timeformat(scheduledTime, 'short') />
<cfset arrayAppend(arrAssessmentSource, 'STARS') />
<cfset arrayAppend(arrAssessmentSource, 'SACAP') />
<cfset arrayAppend(arrAssessmentSource, '') />
<cfset arrayAppend(arrClientLast, vClientlname) />
<cfset arrayAppend(arrClientLast, sacap_clientLName) />
<cfset arrayAppend(arrClientLast, '') />
<cfset arrayAppend(arrClientFirst, vClientfname) />
<cfset arrayAppend(arrClientFirst, sacap_clientFName) />
<cfset arrayAppend(arrClientFirst, '') />
<cfset arrayAppend(arrSSN, vSSN) />
<cfset arrayAppend(arrSSN, sacap_ssn) />
<cfset arrayAppend(arrSSN, '') />
<cfset arrayAppend(arrGender, vGender) />
<cfset arrayAppend(arrGender, sacap_gender) />
<cfset arrayAppend(arrGender, '') />
<cfset arrayAppend(arrCaseNumber, listFirst(vClientcasenumber, '-')) />
<cfset arrayAppend(arrCaseNumber, vHRAClientId) />
<cfset arrayAppend(arrCaseNumber, '') />
<cfset arrayAppend(arrDob, dateFormat(dDOB, 'mm/dd/yyyy')) />
<cfset arrayAppend(arrDob, dateFormat(vAge, 'mm/dd/yyyy')) />
<cfset arrayAppend(arrDob, '') />
<cfset arrayAppend(arrZip, vZipcode) />
<cfset arrayAppend(arrZip, vClientPermZip) />
<cfset arrayAppend(arrZip, '') />
<cfset arrayAppend(arrAssessmentType, vAssessmenttype) />
<cfset arrayAppend(arrAssessmentType, sacap_StarsAssessmentType) />
<cfset arrayAppend(arrAssessmentType, '') />
<cfset arrayAppend(arrAssessmentStatus, vAssessmentstatus) />
<cfset arrayAppend(arrAssessmentStatus, '') />
<cfset arrayAppend(arrAssessmentStatus, '') />
<cfset arrayAppend(arrNYCApptCode, vNycwayappointmentcode) />
<cfset arrayAppend(arrNYCApptCode, sacap_clienttype) />
<cfset arrayAppend(arrNYCApptCode, '') />
<cfset arrayAppend(arrApptDate, dateFormat(dAssessmentStart, 'mm/dd/yyyy')) />
<cfset arrayAppend(arrApptDate, dateFormat(dCasacDate, 'mm/dd/yyyy')) />
<cfset arrayAppend(arrApptDate, '') />
<cfset arrayAppend(arrApptTime, tAppointmentTime) />
<cfset arrayAppend(arrApptTime, tScheduledtime) />
<cfset arrayAppend(arrApptTime, '') />
<cfset arrayAppend(arrCasacWorker, vCasacworker) />
<cfset arrayAppend(arrCasacWorker, vEmpFName & ' ' & vEmpLName) />
<cfset arrayAppend(arrCasacWorker, '') />
<cfset arrayAppend(arrApprovingSup, vApprovingsupervisor) />
<cfset arrayAppend(arrApprovingSup, supervisor_fname & ' ' & supervisor_lname) />
<cfset arrayAppend(arrApprovingSup, '') />
<cfset arrayAppend(arrBenStatus, vBenefitstatus_casetype) />
<cfset arrayAppend(arrBenStatus, sacap_benefitstatus) />
<cfset arrayAppend(arrBenStatus, '') />
<cfset arrayAppend(arrFinalRecommend, vFinalrecommendation) />
<cfset arrayAppend(arrFinalRecommend, sacap_finalRecommendation) />
<cfset arrayAppend(arrFinalRecommend, '') />
<cfset arrayAppend(arrSiteCode, vSitecode) />
<cfset arrayAppend(arrSiteCode, vHRACode) />
<cfset arrayAppend(arrSiteCode, '') />
<cfset arrayAppend(arrReAssess, dReassessment) />
<cfset arrayAppend(arrReAssess, sacap_reassessment) />
<cfset arrayAppend(arrReAssess, '') />
<cfset arrayAppend(arrLivingSit, vCurrentlivingsituation) />
<cfset arrayAppend(arrLivingSit, '') />
<cfset arrayAppend(arrLivingSit, '') />
<cfset arrayAppend(arrMentalCond, vMentalconditions) />
<cfset arrayAppend(arrMentalCond, vMHdiagnoses) />
<cfset arrayAppend(arrMentalCond, '') />
<cfset arrayAppend(arrCandidateWecare, vCandidateforwecare) />
<cfset arrayAppend(arrCandidateWecare, sacap_wecaretype) />
<cfset arrayAppend(arrCandidateWecare, '') />
<cfset arrayAppend(arrAttendSubsUse, vAttendsubstanceuse) />
<cfset arrayAppend(arrAttendSubsUse, '') />
<cfset arrayAppend(arrAttendSubsUse, '') />
<cfset arrayAppend(arrAgencyname, vAgencyname) />
<cfset arrayAppend(arrAgencyname, sacap_projects) />
<cfset arrayAppend(arrAgencyname, '') />
<cfset arrayAppend(arrCurrentTxProg, vTreatmentprogramname) />
<cfset arrayAppend(arrCurrentTxProg, '') />
<cfset arrayAppend(arrCurrentTxProg, '') />
<cfset arrayAppend(arrTypeTx, vTypeoftreatment) />
<cfset arrayAppend(arrTypeTx, '') />
<cfset arrayAppend(arrTypeTx, '') />
<cfset arrayAppend(arrOpioid, vOpioidtaken) />
<cfset arrayAppend(arrOpioid, sacap_buprenorphine) />
<cfset arrayAppend(arrOpioid, '') />
<cfset arrayAppend(arrHousingOutcome, iHousingoutcome) />
<cfset arrayAppend(arrHousingOutcome, sacap_housingstatus) />
<cfset arrayAppend(arrHousingOutcome, '') />
<cfset arrayAppend(arrReturnToTxProv, vReturntotreatmentprovider) />
<cfset arrayAppend(arrReturnToTxProv, sacap_encounteroutcome) />
<cfset arrayAppend(arrReturnToTxProv, '') />
<cfset arrayAppend(arrNonHRAApproved, vNonhraapproved) />
<cfset arrayAppend(arrNonHRAApproved, sacap_nonhraapproved) />
<cfset arrayAppend(arrNonHRAApproved, '') />
<cfset arrayAppend(arrNameNonHRASite, vNamenonhrasite) />
<cfset arrayAppend(arrNameNonHRASite, sacap_namenonhrasite) />
<cfset arrayAppend(arrNameNonHRASite, '') />
<cfset arrayAppend(arrNewMandate, vNewhramandate) />
<cfset arrayAppend(arrNewMandate, iSNewlyMandated) />
<cfset arrayAppend(arrNewMandate, '') />
<cfset arrayAppend(arrXferToNewTxprov, vTransfertonewtreatmentprovider) />
<cfset arrayAppend(arrXferToNewTxprov, sacap_transferreason) />
<cfset arrayAppend(arrXferToNewTxprov, '') />
<cfset arrayAppend(arrCheckIn, tCheckin) />
<cfset arrayAppend(arrCheckIn, tTimeInBin) />
<cfset arrayAppend(arrCheckIn, '') />
<cfset arrayAppend(arrAssessmentStart, tAssessmentStart) />
<cfset arrayAppend(arrAssessmentStart, tApptBeginTime) />
<cfset arrayAppend(arrAssessmentStart, '') />
<cfset arrayAppend(arrCheckOut, tCheckouttime) />
<cfset arrayAppend(arrCheckOut, tApptEndTime) />
<cfset arrayAppend(arrCheckOut, '') />
<cfset arrayAppend(arrCheckedInSite, vCheckedinsite) />
<cfset arrayAppend(arrCheckedInSite, sacap_sacapsite) />
<cfset arrayAppend(arrCheckedInSite, '') />
<cfset arrayAppend(arrAddendum, vAddendum) />
<cfset arrayAppend(arrAddendum, '') />
<cfset arrayAppend(arrAddendum, '') />
<cfset arrayAppend(arrConsentBSigned, vConsentbsigned) />
<cfset arrayAppend(arrConsentBSigned, '') />
<cfset arrayAppend(arrConsentBSigned, '') />
</cfloop>
<cfset queryAddColumn(qryRet, "Assessment_Source", "varchar", arrAssessmentSource) />
<cfset queryAddColumn(qryRet, "Client_Last", "varchar", arrClientLast) />
<cfset queryAddColumn(qryRet, "Client_First","varchar", arrClientFirst) />
<cfset queryAddColumn(qryRet, "SSN", "varchar", arrSSN) />
<cfset queryAddColumn(qryRet, "Gender", "varchar", arrGender) />
<cfset queryAddColumn(qryRet, "Client_Case_Number", "varchar", arrCaseNumber) />
<cfset queryAddColumn(qryRet, "DoB", "varchar", arrDob) />
<cfset queryAddColumn(qryRet, "Zip_Code", "varchar", arrZip) />
<cfset queryAddColumn(qryRet, "Assessment_Type", "varchar", arrAssessmentType) />
<cfset queryAddColumn(qryRet, "Assessment_Status", "varchar", arrAssessmentStatus) />
<cfset queryAddColumn(qryRet, "NYCWAY_Appt_Code", "varchar", arrNYCApptCode) />
<cfset queryAddColumn(qryRet, "Appt_Date", "varchar", arrApptDate) />
<cfset queryAddColumn(qryRet, "Appt_Time", "varchar", arrApptTime) />
<cfset queryAddColumn(qryRet, "CASAC_Worker", "varchar", arrCasacWorker) />
<cfset queryAddColumn(qryRet, "Approving_Supervisor", "varchar", arrApprovingSup) />
<cfset queryAddColumn(qryRet, "Benefit_Status_Case_Type", "varchar", arrBenStatus) />
<cfset queryAddColumn(qryRet, "Final_Recommendation", "varchar", arrFinalRecommend) />
<cfset queryAddColumn(qryRet, "Site_Code", "varchar", arrSiteCode) />
<cfset queryAddColumn(qryRet, "Re_Assessment", "varchar", arrReAssess) />
<cfset queryAddColumn(qryRet, "Current_Living_Situation", "varchar", arrLivingSit) />
<cfset queryAddColumn(qryRet, "Mental_Conditions", "varchar", arrMentalCond) />
<cfset queryAddColumn(qryRet, "Candidate_for_WeCARE", "varchar", arrCandidateWecare) />
<cfset queryAddColumn(qryRet, "Attend_Substance_Use", "varchar", arrAttendSubsUse) />
<cfset queryAddColumn(qryRet, "Agency_Name", "varchar", arrAgencyname) />
<cfset queryAddColumn(qryRet, "Currently_Attending_Treatment_Program_Name", "varchar", arrCurrentTxProg) />
<cfset queryAddColumn(qryRet, "Type_of_Treatment", "varchar", arrTypeTx) />
<cfset queryAddColumn(qryRet, "Opioid_Taken", "varchar", arrOpioid) />
<cfset queryAddColumn(qryRet, "Housing_Outcome", "varchar", arrHousingOutcome) />
<cfset queryAddColumn(qryRet, "Return_to_Treatment_Provider", "varchar", arrReturnToTxProv) />
<cfset queryAddColumn(qryRet, "Non_HRA_Approved", "varchar", arrNonHRAApproved) />
<cfset queryAddColumn(qryRet, "Name_non_HRA_Site", "varchar", arrNameNonHRASite) />
<cfset queryAddColumn(qryRet, "New_Mandate", "varchar", arrNewMandate) />
<cfset queryAddColumn(qryRet, "Transfer_to_New_Treatment_Provider", "varchar", arrXferToNewTxprov) />
<cfset queryAddColumn(qryRet, "Check_in", "varchar", arrCheckIn) />
<cfset queryAddColumn(qryRet, "Assessment_Start", "varchar", arrAssessmentStart) />
<cfset queryAddColumn(qryRet, "Checked_Out_Time", "varchar", arrCheckOut) />
<cfset queryAddColumn(qryRet, "Checked_in_Site", "varchar", arrCheckedInSite) />
<cfset queryAddColumn(qryRet, "Addendum", "varchar", arrAddendum) />
<cfset queryAddColumn(qryRet, "Consent_B_signed", "varchar", arrConsentBSigned) />
<cfreturn qryRet />
</cffunction>