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.
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. –
@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
"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