>- see footer for list info -<
I do it this way...

<cfsetting showdebugoutput="no">

<cfquery name="qryComp" datasource="#dsn#">
SELECT respondent_title, respondent_firstname, respondent_lastname,
date_created
FROM myTable
ORDER BY date_created
</cfquery>

<cfsavecontent variable="xls"><cfoutput><?xml version="1.0"
encoding="UTF-8"?><?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
                  xmlns:o="urn:schemas-microsoft-com:office:office"
                  xmlns:x="urn:schemas-microsoft-com:office:excel"
                  xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
                  xmlns:html="http://www.w3.org/TR/REC-html40";>
    <Styles>
       <Style ss:ID="boldStyle">
            <Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
            <Font x:Family="Swiss" ss:Bold="1"/>
        </Style>
        <Style ss:ID="dateFormat">
   <NumberFormat ss:Format="dd/mm/yyyy;@"/>
  </Style>
  <Style ss:ID="timeFormat">
   <NumberFormat ss:Format="hh:mm:ss;@"/>
  </Style>
    </Styles>
    <Worksheet ss:Name="Name of My Worksheet">
        <Table ss:ExpandedColumnCount="4"
ss:ExpandedRowCount="#qryMyQuery.recordcount+1#" x:FullColumns="1"
x:FullRows="1"    >
        <Column/>
            <Row>
                <Cell ss:StyleID="boldStyle"><Data
ss:Type="String">Date</Data></Cell>
                <Cell ss:StyleID="boldStyle"><Data
ss:Type="String">Title</Data></Cell>
                <Cell ss:StyleID="boldStyle"><Data
ss:Type="String">Firstname</Data></Cell>
                <Cell ss:StyleID="boldStyle"><Data
ss:Type="String">Lastname</Data></Cell>

           </Row>
            <cfloop query="qryMyQuery">
            <Row>
                <Cell ss:StyleID="dateFormat"><Data
ss:Type="String">#dateformat(date_created,"dd/mm/yyyy")#</Data></Cell>

                <Cell><Data
ss:Type="String">#respondent_title#</Data></Cell>
                <Cell><Data
ss:Type="String">#respondent_firstname#</Data></Cell>
                <Cell><Data
ss:Type="String">#respondent_lastname#</Data></Cell>
            </Row>
            </cfloop>
        </Table>
    </Worksheet>

</Workbook></cfoutput></cfsavecontent>

<cfcontent reset="yes" type="application/msexcel"><cfheader
name="Content-Disposition" value="inline;
filename=NameOfMyExcelFile.xls"><cfoutput>#xls#</cfoutput><cfabort>

On Tue, May 13, 2008 at 6:38 PM, Peter Boughton <[EMAIL PROTECTED]> wrote:

> >- see footer for list info -<
> Create the data as a HTML table.
>
> In the main HTML tag, you need to add:
> xmlns:x="urn:schemas-microsoft-com:office:excel"
>
> Then, for each particular table cell you can add formatting information:
> <td x:str>12345678900000000000</td>
> (<td x:str>..<td> = format as a string, not a number)
>
> Finally, use cfheader/cfcontent to tell Excel to open it.
>
>
>
> So, putting all that together here is a very basic example:
>
> <cfheader
>        name="Content-Disposition"
>        value="inline; filename=report_#DateFormat(Now(),'yyyymmdd')#.xls"
> />
> <cfcontent
>        type="application/vnd.ms-excel"
>        reset="yes"
> />
> <html xmlns:x="urn:schemas-microsoft-com:office:excel">
> <table>
>        <tr><th>Preserve String:</th><td
> x:str>12345678900000000000</td></tr>
>        <tr><th>Auto-formatted:</th><td>12345678900000000000</td></tr>
> </table>
> </html>
>
>
> If you need more than auto-formatting and preserving strings, you'll
> have to find the partners to x:str as I don't have them to hand and
> I'd only end up Googling, so I might as well let you do that. ;)
>
>
>
> On Tue, May 13, 2008 at 3:57 PM, Nick Middleweek
> <[EMAIL PROTECTED]> wrote:
> > >- see footer for list info -<
> >  Hello,
> >
> >  Does anyone have any report templates for creating a dynamic Excel file
> from
> >  cfm?
> >
> >  I'm preparing my data and using cfloop but am in need for some pointers
> to
> >  format the data correctly.
> >
> >
> >  Thanks,
> >  Nick
> >
>
> _______________________________________________
>
> For details on ALL mailing lists and for joining or leaving lists, go to
> http://list.cfdeveloper.co.uk/mailman/listinfo
>
> --
> CFDeveloper Sponsors:-
> >- cfdeveloper Hosting provided by www.cfmxhosting.co.uk -<
> >- Lists hosted by www.Gradwell.com -<
> >- CFdeveloper is run by Russ Michaels, feel free to volunteer your help
> -<
>
_______________________________________________

For details on ALL mailing lists and for joining or leaving lists, go to 
http://list.cfdeveloper.co.uk/mailman/listinfo

--
CFDeveloper Sponsors:-
>- cfdeveloper Hosting provided by www.cfmxhosting.co.uk -<
>- Lists hosted by www.Gradwell.com -<
>- CFdeveloper is run by Russ Michaels, feel free to volunteer your help -<

Reply via email to