You can find the CFFiddle demo of this function and other spreadsheet functions as part of a project that is shared with you.
Click the button below to launch CFFiddle.
To copy the project in your workspace in CFFiddle, follow the steps below:
Sets the width of a column in a worksheet.
Nothing
SpreadSheetSetColumnWidth (spreadhsheetobj, column number, width)
ColdFusion 9: Added the function.
Parameter |
Description |
|---|---|
spreadsheetobj |
The Excel spreadsheet object to which to set the column width. |
column number |
Specifies the column to set the width. |
width |
Specifies the width in points. Enter an integer value for the width. |
<cfscript>
ArtOrders=QueryExecute("SELECT orderid,customerfirstname,customerlastname,address,total,city FROM orders
ORDER BY orderid",[],{datasource="cfartgallery"});
// Set the file path in the same location as this cfm
myFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & "myexcelfile.xls";
// create spreadsheet object. Set xml to true as this is an xlsx file
mySheet=SpreadsheetNew("ColdFusion",false);
// Create another worksheet coldfusion1
SpreadsheetCreateSheet(mySheet,"ColdFusion1");
// Set headers for the xlsx file
SpreadSheetAddRow(mySheet,"Order,First Name,Last Name,Address,Amount,City");
SpreadSheetAddRows(mySheet,ArtOrders);
// set coldfusion as active sheet
SpreadsheetSetActiveSheet(mySheet,"ColdFusion1");
// new query for the new sheet
Artists=QueryExecute("Select * from APP.ARTISTS",[],{datasource="cfartgallery"});
SpreadSheetAddRow(mySheet,"ARTISTID,First Name,Last Name,Address,CITY,STATE,POSTALCODE,EMAIL,PHONE,FAX,THEPASSWORD");
SpreadSheetAddRows(mySheet,Artists);
// Define the structure for formatting a column
myFormat=StructNew();
myFormat.color="blue";
myFormat.bold=true;
myFormat.underline=true;
myFormat.alignment="center";
myFormat.font="Arial";
// Set the width of column 2 to 35 points
SpreadSheetSetColumnWidth(mySheet,2,35);
SpreadsheetWrite(mySheet,"#myFile#",true);
</cfscript>
The following example creates a spreadsheet, adds columns to the spreadsheet, and sets the column width for the newly added columns.
|
a=SpreadSheetNew(); SpreadSheetAddRow(a,"1,2,3,4,5,6,7,8"); SpreadSheetAddRow(a,"1,2,3,4,5,6,7,8",2,1); </cfscript> <cfset SpreadSheetSetColumnWidth(a,2,10)> <cfset SpreadSheetSetColumnWidth(a,3,25)> <cfspreadsheet action="write" filename="#expandpath('.')#/b.xls" name="a" overwrite="true"> |
Sign in to your account