> I am trying to send data to excel using cfobject.
>
> I can get the data there fine.
>
> The only problem is the formatting on the spreadsheet.  The requirement is
> to have the excel file with nice bold headings etc.
>
> Has anyone done this before?
>
> I can find documentation for everything but this.

OK, since I've now played with Excel COM and (sucessfully) built a formatted
sheet, here's how it goes.

I'm assuming you've already done the CFOBJECT;

<CFSCRIPT>
    // Open Excel in the background
    objExcel.Visible = false;

    // Disable client alerts such as: 'Save this workbook?'
    objExcel.DisplayAlerts = false;

    // Define the workbooks object
    objWorkBook = objExcel.Workbooks;

    // Add a new workbook
    objOpenedBook = objWorkBook.Add();

    // Get the WorkSheets' collection
    objWorkSheets = objExcel.WorkSheets;

    // Add a new worksheet (this will contain our data)
    objWorkSheet =  objWorkSheets.Add();

    // We cannot use the Cells(1,1) syntax, so we have to create a range
    // for EVERY value we want to insert -- yep, this really sucks.
    objRange = objExcel.Range("A1:A1");
    objRange.value = 5;

    // Make a Font object
    objFont = objRange.Font;
    // Set Bold to be on
    objFont.Bold = "True";
    // Set font face (Name in M$ COM) to Arial
    objFont.Name = "Arial";
    // Set font size to be 12 point
    objFont.Size = 12;
    // Select the cell "Interior"
    objInterior = objRange.Interior;
    // set the background color to be light grey
    objInterior.ColorIndex = 15;

    // SaveAs() does not work with workbooks, only with worksheets
    objWorkSheet.SaveAs("c:\Book1.xls",Val(1));

    // Close the document
    objWorkBook.Close();

    // Quit Excel
    objExcel.Quit();

    // Release the object
    objExcel = "Nothing";
</CFSCRIPT>

If this doesn't answer your Excel COM formatting questions, I don't know
what will <g>

!! Beginning code learnt from CFComet - no that Dain's code has given me the
push I needed, I just spend hours with by COM book !!

Philip Arnold
Director
Certified ColdFusion Developer
ASP Multimedia Limited
T: +44 (0)20 8680 1133

"Websites for the real world"

**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
**********************************************************************


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to