2016-06-30 14 views
0

Ich verwende CF9. Ich habe eine Arbeitsmappe mit mehreren Blättern erstellt. Ich versuche, die Spalten für jedes Blatt zu formatieren. Die Formatierung übernimmt nur das erste Blatt. Wie kann ich es auf alle Blätter anwenden lassen? Auch kann ich nicht herausfinden, wie man die Spaltenbreite für irgendein Blatt arbeiten lässt.ColdFusion9 Wie formatiere ich Spalten in Excel aus einem <cfscript>

Hier ist der Code, den ich im Moment habe:

<cfscript> 
    qExecSummary = queryNew(""); 
    queryAddColumn(qExecSummary, "responsible", [1,12,13]); 
    queryAddColumn(qExecSummary, "bud_sum", [100,500,1000]); 
    queryAddColumn(qExecSummary, "Spent_YTD", [10,50,100]); 
    queryAddColumn(qExecSummary, "Name", ["A","B","C"]); 
    queryAddColumn(qExecSummary, "Description", ["Descrip1","Descrip2","Descrip3"]); 
    queryAddColumn(qExecSummary, "Committed", ["Committed1","Committed2","Committed3"]); 


    //Create new workbook with one sheet 
    //by default that sheet is the active sheet 
    Workbook = SpreadsheetNew("ExecSummary"); 
    //Add Data to the sheet 
    //Formatting 
    format1.bold="true"; 
    format1.fontsize=12; 
    format1.font="Calibri"; 
    format2.bold="true"; 
    format2.fontsize=18; 
    format2.font="Calibri"; 
    formatNum.dataformat="0.0%"; 
    //adding the formating to the cells 
    //adding the Headers 
    SpreadSheetSetCellValue(Workbook,"Executive Summary Report",1,1); 
    Spreadsheetformatcell(Workbook,format2,1,1); 
    SpreadSheetSetCellValue(Workbook,"#dateFormat(now(),'mm/dd/yyyy')#",3,1); 
    Spreadsheetformatcell(Workbook,format1,3,1); 
    SpreadSheetSetCellValue(Workbook,"Data Date",5,1); 
    Spreadsheetformatcell(Workbook,format1,5,1); 
    SpreadSheetSetColumnWidth(Workbook,1,10); 
    SpreadSheetSetCellValue(Workbook,"Level",5,2); 
    Spreadsheetformatcell(Workbook,format1,5,2); 
    SpreadSheetSetColumnWidth(Workbook,2,10); 
    SpreadSheetSetCellValue(Workbook,"Name",5,3); 
    Spreadsheetformatcell(Workbook,format1,5,3); 
    SpreadSheetSetColumnWidth(Workbook,3,17); 
    SpreadSheetSetCellValue(Workbook,"Description",5,4); 
    Spreadsheetformatcell(Workbook,format1,5,4); 
    SpreadSheetSetColumnWidth(Workbook,4,20); 
    SpreadSheetSetCellValue(Workbook,"Budget",5,5); 
    Spreadsheetformatcell(Workbook,format1,5,5); 
    SpreadSheetSetColumnWidth(Workbook,5,15); 
    SpreadSheetSetCellValue(Workbook,"Commited",5,6); 
    Spreadsheetformatcell(Workbook,format1,5,6); 
    SpreadSheetSetColumnWidth(Workbook,6,15); 
    SpreadSheetSetCellValue(Workbook,"Spent YTD",5,7); 
    Spreadsheetformatcell(Workbook,format1,5,7); 
    SpreadSheetSetColumnWidth(Workbook,7,15); 
    SpreadSheetSetCellValue(Workbook,"% Spent",5,8); 
    Spreadsheetformatcell(Workbook,format1,5,8); 
    SpreadSheetSetColumnWidth(Workbook,8,15); 
    //check to make sure that data was pulled back by the query 
    if (qExecSummary.recordCount) { 
     rowNum = 6; 
     do {//if data is pulled back loop through it and add it to the correct cell 
      SpreadSheetSetCellValue(Workbook,dateFormat(now(),'mm/dd/yyy'),rowNum,1); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.responsible[rowNum-5],rowNum,2); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.name[rowNum-5],rowNum,3); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.Description[rowNum-5],rowNum,4); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.bud_sum[rowNum-5],rowNum,5); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.committed[rowNum-5],rowNum,6); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.Spent_YTD[rowNum-5],rowNum,7); 
      if (qExecSummary.bud_sum[rowNum-5] NEQ 0){ 
       Spreadsheetformatcell(Workbook,formatNum,rowNum,8);//if there is a percentage used then format as a percent 
       SpreadSheetSetCellValue(Workbook,(qExecSummary.Spent_YTD[rowNum-5]/qExecSummary.bud_sum[rowNum-5]),rowNum,8); 
      } 
      else { 
       SpreadSheetSetCellValue(Workbook,0,rowNum,8); 
      } 
      rowNum++; 
     } while (rowNum - 6 LT qExecSummary.recordCount); 
    } else { 
     SpreadSheetAddRows(Workbook,"No results for your criteria."); 
    } 

    SpreadsheetCreateSheet(Workbook,"ExecSummary331-333"); 
    SpreadsheetSetActiveSheet(Workbook,"ExecSummary331-333"); 

    //adding the Headers 
    SpreadSheetSetCellValue(Workbook,"Executive Summary Report",1,1); 
    Spreadsheetformatcell(Workbook,{bold="true"},1,1); 
    Spreadsheetformatcell(Workbook,{fontsize=18},1,1); 
    Spreadsheetformatcell(Workbook,{font="Calibri"},1,1); 
    SpreadSheetSetCellValue(Workbook,"#dateFormat(now(),'mm/dd/yyyy')#",3,1); 
    Spreadsheetformatcell(Workbook,format1,3,1); 
    SpreadSheetSetCellValue(Workbook,"Data Date",5,1); 
    Spreadsheetformatcell(Workbook,format1,5,1); 
    SpreadSheetSetColumnWidth(Workbook,1,10); 
    SpreadSheetSetCellValue(Workbook,"Level",5,2); 
    Spreadsheetformatcell(Workbook,format1,5,2); 
    SpreadSheetSetColumnWidth(Workbook,2,10); 
    SpreadSheetSetCellValue(Workbook,"Name",5,3); 
    Spreadsheetformatcell(Workbook,format1,5,3); 
    SpreadSheetSetColumnWidth(Workbook,3,17); 
    SpreadSheetSetCellValue(Workbook,"Description",5,4); 
    Spreadsheetformatcell(Workbook,format1,5,4); 
    SpreadSheetSetColumnWidth(Workbook,4,20); 
    SpreadSheetSetCellValue(Workbook,"Budget",5,5); 
    Spreadsheetformatcell(Workbook,format1,5,5); 
    SpreadSheetSetColumnWidth(Workbook,5,15); 
    SpreadSheetSetCellValue(Workbook,"Commited",5,6); 
    Spreadsheetformatcell(Workbook,format1,5,6); 
    SpreadSheetSetColumnWidth(Workbook,6,15); 
    SpreadSheetSetCellValue(Workbook,"Spent YTD",5,7); 
    Spreadsheetformatcell(Workbook,format1,5,7); 
    SpreadSheetSetColumnWidth(Workbook,7,15); 
    SpreadSheetSetCellValue(Workbook,"% Spent",5,8); 
    Spreadsheetformatcell(Workbook,format1,5,8); 
    SpreadSheetSetColumnWidth(Workbook,8,15); 
    //check to make sure that data was pulled back by the query 
    if (qExecSummary.recordCount) { 
     rowNum = 6; 
     do {//if data is pulled back loop through it and add it to the correct cell 
      SpreadSheetSetCellValue(Workbook,dateFormat(now(),'mm/dd/yyy'),rowNum,1); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.responsible[rowNum-5],rowNum,2); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.name[rowNum-5],rowNum,3); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.Description[rowNum-5],rowNum,4); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.bud_sum[rowNum-5],rowNum,5); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.committed[rowNum-5],rowNum,6); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.Spent_YTD[rowNum-5],rowNum,7); 
      if (qExecSummary.bud_sum[rowNum-5] NEQ 0){ 
       Spreadsheetformatcell(Workbook,formatNum,rowNum,8);//if there is a percentage used then format as a percent 
       SpreadSheetSetCellValue(Workbook,(qExecSummary.Spent_YTD[rowNum-5]/qExecSummary.bud_sum[rowNum-5]),rowNum,8); 
      } 
      else { 
       SpreadSheetSetCellValue(Workbook,0,rowNum,8); 
      } 
      rowNum++; 
     } while (rowNum - 6 LT qExecSummary.recordCount); 
    } else { 
     SpreadSheetAddRows(Workbook,"No results for your criteria."); 
    } 
    //check to make sure that data was pulled back by the query 
    if (qExecSummary.recordCount) { 
     rowNum = 18; 
     do {//if data is pulled back loop through it and add it to the correct cell 
      SpreadSheetSetCellValue(Workbook,dateFormat(now(),'mm/dd/yyy'),rowNum,1); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.responsible[rowNum-17],rowNum,2); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.name[rowNum-17],rowNum,3); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.Description[rowNum-17],rowNum,4); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.bud_sum[rowNum-17],rowNum,5); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.committed[rowNum-17],rowNum,6); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.Spent_YTD[rowNum-17],rowNum,7); 
      if (qExecSummary.bud_sum[rowNum-17] NEQ 0){ 
       Spreadsheetformatcell(Workbook,formatNum,rowNum,8);//if there is a percentage used then format as a percent 
       SpreadSheetSetCellValue(Workbook,(qExecSummary.Spent_YTD[rowNum-17]/qExecSummary.bud_sum[rowNum-17]),rowNum,8); 
      } 
      else { 
       SpreadSheetSetCellValue(Workbook,0,rowNum,8); 
      } 
      rowNum++; 
     } while (rowNum - 17 LT qExecSummary.recordCount); 
    } else { 
     SpreadSheetAddRows(Workbook,"No results for your criteria."); 
    } 
    //check to make sure that data was pulled back by the query 
    if (qExecSummary.recordCount) { 
     rowNum = 29; 
     do {//if data is pulled back loop through it and add it to the correct cell 
      SpreadSheetSetCellValue(Workbook,dateFormat(now(),'mm/dd/yyy'),rowNum,1); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.responsible[rowNum-28],rowNum,2); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.name[rowNum-28],rowNum,3); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.Description[rowNum-28],rowNum,4); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.bud_sum[rowNum-28],rowNum,5); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.committed[rowNum-28],rowNum,6); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.Spent_YTD[rowNum-28],rowNum,7); 
      if (qExecSummary.bud_sum[rowNum-28] NEQ 0){ 
       Spreadsheetformatcell(Workbook,formatNum,rowNum,8);//if there is a percentage used then format as a percent 
       SpreadSheetSetCellValue(Workbook,(qExecSummary.Spent_YTD[rowNum-28]/qExecSummary.bud_sum[rowNum-28]),rowNum,8); 
      } 
      else { 
       SpreadSheetSetCellValue(Workbook,0,rowNum,8); 
      } 
      rowNum++; 
     } while (rowNum - 28 LT qExecSummary.recordCount); 
    } else { 
     SpreadSheetAddRows(Workbook,"No results for your criteria."); 
    } 

    SpreadsheetCreateSheet(Workbook,"ExecSummary334-336"); 
    SpreadsheetSetActiveSheet(Workbook,"ExecSummary334-336"); 

    //adding the Headers 
    SpreadSheetSetCellValue(Workbook,"Executive Summary Report",1,1); 
    Spreadsheetformatcell(Workbook,format2,1,1); 
    SpreadSheetSetCellValue(Workbook,"#dateFormat(now(),'mm/dd/yyyy')#",3,1); 
    Spreadsheetformatcell(Workbook,format1,3,1); 
    SpreadSheetSetCellValue(Workbook,"Data Date",5,1); 
    Spreadsheetformatcell(Workbook,format1,5,1); 
    SpreadSheetSetColumnWidth(Workbook,1,10); 
    SpreadSheetSetCellValue(Workbook,"Level",5,2); 
    Spreadsheetformatcell(Workbook,format1,5,2); 
    SpreadSheetSetColumnWidth(Workbook,2,10); 
    SpreadSheetSetCellValue(Workbook,"Name",5,3); 
    Spreadsheetformatcell(Workbook,format1,5,3); 
    SpreadSheetSetColumnWidth(Workbook,3,17); 
    SpreadSheetSetCellValue(Workbook,"Description",5,4); 
    Spreadsheetformatcell(Workbook,format1,5,4); 
    SpreadSheetSetColumnWidth(Workbook,4,20); 
    SpreadSheetSetCellValue(Workbook,"Budget",5,5); 
    Spreadsheetformatcell(Workbook,format1,5,5); 
    SpreadSheetSetColumnWidth(Workbook,5,15); 
    SpreadSheetSetCellValue(Workbook,"Commited",5,6); 
    Spreadsheetformatcell(Workbook,format1,5,6); 
    SpreadSheetSetColumnWidth(Workbook,6,15); 
    SpreadSheetSetCellValue(Workbook,"Spent YTD",5,7); 
    Spreadsheetformatcell(Workbook,format1,5,7); 
    SpreadSheetSetColumnWidth(Workbook,7,15); 
    SpreadSheetSetCellValue(Workbook,"% Spent",5,8); 
    Spreadsheetformatcell(Workbook,format1,5,8); 
    SpreadSheetSetColumnWidth(Workbook,8,15); 
    //check to make sure that data was pulled back by the query 
    if (qExecSummary.recordCount) { 
     rowNum = 6; 
     do {//if data is pulled back loop through it and add it to the correct cell 
      SpreadSheetSetCellValue(Workbook,dateFormat(now(),'mm/dd/yyy'),rowNum,1); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.responsible[rowNum-5],rowNum,2); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.name[rowNum-5],rowNum,3); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.Description[rowNum-5],rowNum,4); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.bud_sum[rowNum-5],rowNum,5); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.committed[rowNum-5],rowNum,6); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.Spent_YTD[rowNum-5],rowNum,7); 
      if (qExecSummary.bud_sum[rowNum-5] NEQ 0){ 
       Spreadsheetformatcell(Workbook,formatNum,rowNum,8);//if there is a percentage used then format as a percent 
       SpreadSheetSetCellValue(Workbook,(qExecSummary.Spent_YTD[rowNum-5]/qExecSummary.bud_sum[rowNum-5]),rowNum,8); 
      } 
      else { 
       SpreadSheetSetCellValue(Workbook,0,rowNum,8); 
      } 
      rowNum++; 
     } while (rowNum - 6 LT qExecSummary.recordCount); 
    } else { 
     SpreadSheetAddRows(Workbook,"No results for your criteria."); 
    } 
    //check to make sure that data was pulled back by the query 
    if (qExecSummary.recordCount) { 
     rowNum = 18; 
     do {//if data is pulled back loop through it and add it to the correct cell 
      SpreadSheetSetCellValue(Workbook,dateFormat(now(),'mm/dd/yyy'),rowNum,1); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.responsible[rowNum-17],rowNum,2); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.name[rowNum-17],rowNum,3); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.Description[rowNum-17],rowNum,4); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.bud_sum[rowNum-17],rowNum,5); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.committed[rowNum-17],rowNum,6); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.Spent_YTD[rowNum-17],rowNum,7); 
      if (qExecSummary.bud_sum[rowNum-17] NEQ 0){ 
       Spreadsheetformatcell(Workbook,formatNum,rowNum,8);//if there is a percentage used then format as a percent 
       SpreadSheetSetCellValue(Workbook,(qExecSummary.Spent_YTD[rowNum-17]/qExecSummary.bud_sum[rowNum-17]),rowNum,8); 
      } 
      else { 
       SpreadSheetSetCellValue(Workbook,0,rowNum,8); 
      } 
      rowNum++; 
     } while (rowNum - 17 LT qExecSummary.recordCount); 
    } else { 
     SpreadSheetAddRows(Workbook,"No results for your criteria."); 
    } 
    //check to make sure that data was pulled back by the query 
    if (qExecSummary.recordCount) { 
     rowNum = 29; 
     do {//if data is pulled back loop through it and add it to the correct cell 
      SpreadSheetSetCellValue(Workbook,dateFormat(now(),'mm/dd/yyy'),rowNum,1); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.responsible[rowNum-28],rowNum,2); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.name[rowNum-28],rowNum,3); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.Description[rowNum-28],rowNum,4); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.bud_sum[rowNum-28],rowNum,5); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.committed[rowNum-28],rowNum,6); 
      SpreadSheetSetCellValue(Workbook,qExecSummary.Spent_YTD[rowNum-28],rowNum,7); 
      if (qExecSummary.bud_sum[rowNum-28] NEQ 0){ 
       Spreadsheetformatcell(Workbook,formatNum,rowNum,8);//if there is a percentage used then format as a percent 
       SpreadSheetSetCellValue(Workbook,(qExecSummary.Spent_YTD[rowNum-28]/qExecSummary.bud_sum[rowNum-28]),rowNum,8); 
      } 
      else { 
       SpreadSheetSetCellValue(Workbook,0,rowNum,8); 
      } 
      rowNum++; 
     } while (rowNum - 28 LT qExecSummary.recordCount); 
    } else { 
     SpreadSheetAddRows(Workbook,"No results for your criteria."); 
    } 

    SpreadsheetSetActiveSheet(Workbook,"ExecSummary"); 
</cfscript> 

<cfheader name="Content-Disposition" value='attachment; filename="execSummaryNew.xls"'> 
<cfcontent type="application/msexcel" variable="#SpreadsheetReadBinary(Workbook)#" reset="true"> 

Ich weiß, dass es wirklich lang ist, aber das ist, wie ich es wegen der DB, die ich mit zur Arbeit zu tun haben, hatte ich musste mehrere Abfragen verwenden, um die Daten zu erhalten, wie ich es wollte.

Ich habe versucht, die SpreadSheetSetColumnWidth innerhalb der <cfscript>, um die Spalten zu formatieren, aber das hat auch nicht funktioniert. Im Moment funktioniert die Formatierung nur auf dem ersten Blatt mit Ausnahme der Breite, die auf keinem Blatt funktioniert.

EDIT

Ich habe es fast alle arbeiten. Jetzt ist es nur die Formatierung. Es funktioniert für 2,5 Blatt. Auf dem 3. Blatt hört es auf, halb durchzuarbeiten. Es gibt 8 Spalten und die letzten 4 nehmen nicht die Formatierung. Ich habe alles versucht, was ich mir vorstellen kann. Ich habe es als Beispiel here hinzugefügt, ich weiß, dass es lang ist, aber ich kann das Problem nirgendwo reproduzieren. Ich bekomme es nur in der Produktion. Ich habe kopiert, was ich in prod sowohl zu meinem Computer und zu dem Beispiel habe, das ich oben verband. Sowohl auf meinem lokalen Computer als auch in dem Beispiel funktioniert es gut. Aber ich habe CF 2016 und der Prod-Server ist CF 9.

Ich weiß, es ist eine Menge Code zu betrachten, aber wenn jemand helfen könnte, wäre toll. Ich knalle meinen Kopf gegen die Wand und versuche zu sehen, wo ich es vermasselt habe, aber für jedes Blatt habe ich das Blatt vorher kopiert und dann die Abfrage-Nummern geändert, also sollte es funktionieren.

Ich kann das hier gepostete Beispiel auch aktualisieren, aber wie gesagt, das Beispiel, das ich verwende, ist lang.

FINAL EDIT

Here ist die abgeschlossene Code als Beispiel. Es generiert 3 Blätter und die zweiten beiden Blätter führen die Abfrage dreimal aus, um die Seite auszufüllen. Jedes Blatt hat die gleichen Überschriften und Formatierungen.

+0

Ich würde versuchen, die Breite auf etwas kleiner und einfacher einzustellen. Ich würde dann die Daten später hinzufügen. Ich vermute, dass entweder etwas darin auslöst, dass die Breite nicht gesetzt wird ODER dass es nie an erster Stelle gesetzt wird. So oder so, das ist viel zu viel Code, um sich zu vergewissern. Erstellen Sie ein kleineres Beispiel für Ihr Problem. –

+0

@JamesAMohler Ich habe etwa 200 Zeilen Code entfernt, um es einfacher zu machen. Formatiert immer noch nicht das zweite Blatt oder nehme die Breite, die ich angeben möchte. Anders als die Breite unten einzustellen, setze ich sie nirgendwo anders ein. – Mike

+1

"Hat nicht funktioniert" wie? SpreadSheetSetColumnWidth funktioniert nur auf dem Blatt * active *. Wenn man es am Ende einmal aufruft, wird es nicht funktionieren. Es muss auf jedem Blatt für jede Spalte aufgerufen werden, die Sie ändern möchten. ** (Bearbeiten) ** Wird der echte Bericht die gleichen Abfragespalten auf jedem Blatt ausgeben, oder ist das nur für Demozwecke? Es wird die Abfrage Spalten wirklich gleich sein, der Code könnte eine Menge vereinfacht werden. – Leigh

Antwort

1

SpreadSheetSetColumnWidth funktioniert nur auf dem aktiven Blatt. Wenn man es am Ende einmal aufruft, wird es nicht funktionieren. Diese Funktion muss unter jeweils Blatt aufgerufen werden, für jede Spalte, die Sie ändern möchten.

Wie Sie bemerkt haben, kann die Spaltenbreite nur geändert werden nach fügen Sie einige Daten zu dieser Spalte hinzu. Der Grund dafür ist, dass die Spalten (oder Zellen) erst dann erstellt werden, wenn Sie einen Wert oder eine Formel anwenden. Wenn Sie also versuchen, ihre Eigenschaften zu ändern, bevor sie überhaupt existieren, passiert nichts. Für "Formate" gelten die gleichen Regeln: Die Zellen müssen existieren, bevor Sie ein Format anwenden können.

Optimizations:

Ein paar Tipps, die den ursprünglichen Code erheblich vereinfachen und verbessern die Lesbarkeit:

  1. Da der Bericht die gleichen Abfragespalten verwenden, auf jedem Blatt, das ist ein perfekte Arbeit für eine UDF. Anstatt für jedes Blatt denselben Code zu kopieren, erstellen Sie einfach eine einzelne Funktion, die einen beliebigen Blattnamen mithilfe der angegebenen Abfrage auffüllt.

    function populateSummarySheet(any workbook 
         , string sheetName 
         , date reportDate 
         , query qryData 
         , boolean createNewSheet) { 
    

    Dann ist die Funktion so oft aufrufen, wie Sie benötigen:

    Workbook = SpreadsheetNew("FirstSheet"); 
    populateSummarySheet(Workbook, "FirstSheet", reportDate, query1, false); 
    populateSummarySheet(Workbook, "SecondSheet", reportDate, query2, true); 
    populateSummarySheet(Workbook, "ThirdSheet", reportDate, query3, true); 
    // .... 
    

    Wenn Sie mit Funktionen in CF nicht vertraut sind, sollten Sie lesen, auf, wie man richtig Scope-Funktion lokale Variablen. Ein gewöhnlicher Fehler ist das Vergessen, alle lokalen Variablen Ihrer Funktion zu definieren, was oft seltsame und schwierig zu reproduzierende Probleme auf der ganzen Linie erzeugt.

  2. CF9 + unterstützt Verknüpfungen für die Struktur- und Array-Erstellung. dh

    headerFormat = { bold="true", fontsize=18, font="Calibri" }; 
    
  3. Wenn Sie alle Zellen in einer bestimmten Zeile oder Spalte zu formatieren müssen, ist es effizienter, die Zeile oder Spalte zu formatieren, anstatt jede einzelne Zelle. Lesen Sie die Dokumentation auf: SpreadSheetFormatRow, SpreadSheetFormatColumnSpreadSheetFormatColumns

    Auch Excel Grenzen, wie viele Arten, die Sie anwenden können. Das Formatieren einzelner Zellen verbraucht mehr Stile und erhöht die Wahrscheinlichkeit, dass Sie die Grenzwerte überschreiten: SpreadsheetFormatRow abruptly stops working Die Grenzen für das neuere .xlsx-Format sind höher als für das .xls-Format. Wenn möglich, ist es besser, .xlsx-Arbeitsmappen anstelle von .xls zu verwenden.

Ich habe CF 2016 und der prod Server CF 9

Wie ich schon in einem anderen Thread erwähnt, verschiedene Versionen in Dev mit und Prod ist eine wirklich schlechte Idee. Dadurch wird es unmöglich, Ihren Code zu testen. Wenn Sie eine Suche durchführen, können Sie immer noch Downloads für ältere Versionen finden. Zum Beispiel: Direct download link for ColdFusion 9 Installer (64-bit Windows)

+0

Danke, das wird sehr helfen. Nur eine Frage, obwohl ich denke, dass ich die Antwort bereits kenne. Die "Funktion" wäre in der '' zusammen mit dem Rest des Codes, den ich richtig habe? – Mike

+0

Ja. Nichtsdestoweniger gibt es, technisch gesehen, nichts Falsches, normalerweise möchten Sie Funktionen in strukturierten Komponenten getrennt und organisiert halten. Leider hat CF9 keine so gute Unterstützung für cfscript wie CF11. Bei bestimmten Dingen müssen Sie sich entscheiden, ob Sie nur bei cfml bleiben möchten oder ob Sie eine Mischung aus cfml und cfscript (etwas weniger lesbar) haben. – Leigh

+0

Ein Hinweis zu Funktionen. Wenn Sie nicht mit ihnen vertraut sind, lesen Sie unbedingt die Bereichsvariablen und die Bereiche "var" und "local".Ein sehr häufig auftretendes Problem ist das Vergessen, * alle * lokalen Variablen zu definieren. Wenn die Funktion später in freigegebenen Bereichen verwendet wird, treten später seltsame Threading-Probleme auf. – Leigh