The following actionscript function allows one to copy a datagrid to the
clicpboard.  You would then manually paste the contents of the datagrid
ino another program like Excel.  It uses an html table as an
intermediate format (which excel is more than happy to work with).

A server side solution will be much more efficient, but this works.


   /**
    * Copy the entries in a datadrid to the system clipboard
    *
    */
    static public function copyDataGridContents(dg) : Void
   {

             var str:String = '<table><tr>';

             for(var i=0;i<dg.__columns.length;i++)

             {

                         if(dg.__columns[i].headerText != null)

                         {

                                    
str+="<th>"+dg.__columns[i].headerText+"</th>";

                         }

                         else

                         {

                                     str+=
"<th>"+dg.__columns[i].columnName+"</th>";

                         }

             }

                         str += "</tr>";

             for(var j=0;j<dg.length;j++)

             {

                         str+="<tr>";

                         for(var i=0;i<dg.__columns.length;i++)

                         {

                                     if(dg.getItemAt(j) != null &&
dg.getItemAt(j) != null)

                                                
if(dg.__columns[i].labelFunction != null)

                                                             str +=
"<td>"+dg.__columns[i].labelFunction(dg.getItemAt(j),dg.__columns[i].col\
umnName)+"</td>";

                                                 else

                                                             str +=
"<td>"+dg.getItemAt(j)[dg.__columns[i].columnName]+"</td>";



                         }

                         str += "</tr>";

             }

             System.setClipboard(str);

     }

--- In flexcoders@yahoogroups.com, "Doug Lowder" <[EMAIL PROTECTED]> wrote:
>
>
> Another way to generate Excel is to post tab-delimited text to a
server
> side page that sets the proper headers and sends the text right back.
> Here's a JSP example:
>
> <%
>      response.setContentType("application/ms-excel");
>      response.setHeader ("Content-Disposition", "attachment;
> filename=\"myExcel.xls\"");
>
>      ServletOutputStream outstream = response.getOutputStream();
>      String data = request.getParameter("data");
>      if (data != null) {
>          byte[] b = data.getBytes();
>          outstream.write(b, 0, b.length);
>      }
> %>
>
> Posting ASCII text such as "First Name\tLast Name\r\nJoe\tSmith" for
the
> data parameter will give you a nice Excel spreadsheet.  I use
something
> similar to allow dataGrid contents to be exported to Excel and other
> formats.
>
>
>
> Doug
>
>
> --- In flexcoders@yahoogroups.com, "Steve Gustafson" <steve.gus@>
> wrote:
> >
> > The Time Tracker application is not really exporting to excel. it is
> just
> > saving HTML with a .xls extension.
> >
> > ColdFusion does not have a native way of generating true Excel files
> either.
> >
> > As far as I know, the two ways to create native excel files on the
> server
> > side is using COM, or POI-HSSF.
> >
> > POI-HSSF is part of the Apache-Jakarta project, open source, and
plays
> > nicely with ColdFusion MX or any other J2EE server.
> > Check it out here: POI-HSSF
> <http://jakarta.apache.org/poi/hssf/index.html>
> >
> > Gus
> >
> >
> > On 6/12/06, vestcomprogrammer vestcomprogrammer@ wrote:
> > >
> > > Does anyone know how to export to excel, like they do on the
> > > timetracker application on the showcase page on
> > > http://labs.adobe.com/showcase/.
> > >
> > > Thanks
> > > Bill
> > >
> > >
> > >
> >
>

--- In flexcoders@yahoogroups.com, "Doug Lowder" <[EMAIL PROTECTED]> wrote:
>
>
> Another way to generate Excel is to post tab-delimited text to a
server
> side page that sets the proper headers and sends the text right back.
> Here's a JSP example:
>
> <%
>      response.setContentType("application/ms-excel");
>      response.setHeader ("Content-Disposition", "attachment;
> filename=\"myExcel.xls\"");
>
>      ServletOutputStream outstream = response.getOutputStream();
>      String data = request.getParameter("data");
>      if (data != null) {
>          byte[] b = data.getBytes();
>          outstream.write(b, 0, b.length);
>      }
> %>
>
> Posting ASCII text such as "First Name\tLast Name\r\nJoe\tSmith" for
the
> data parameter will give you a nice Excel spreadsheet.  I use
something
> similar to allow dataGrid contents to be exported to Excel and other
> formats.
>
>
>
> Doug
>
>
> --- In flexcoders@yahoogroups.com, "Steve Gustafson" steve.gus@
> wrote:
> >
> > The Time Tracker application is not really exporting to excel. it is
> just
> > saving HTML with a .xls extension.
> >
> > ColdFusion does not have a native way of generating true Excel files
> either.
> >
> > As far as I know, the two ways to create native excel files on the
> server
> > side is using COM, or POI-HSSF.
> >
> > POI-HSSF is part of the Apache-Jakarta project, open source, and
plays
> > nicely with ColdFusion MX or any other J2EE server.
> > Check it out here: POI-HSSF
> <http://jakarta.apache.org/poi/hssf/index.html>
> >
> > Gus
> >
> >
> > On 6/12/06, vestcomprogrammer vestcomprogrammer@ wrote:
> > >
> > > Does anyone know how to export to excel, like they do on the
> > > timetracker application on the showcase page on
> > > http://labs.adobe.com/showcase/.
> > >
> > > Thanks
> > > Bill
> > >
> > >
> > >
> >
>






------------------------ Yahoo! Groups Sponsor --------------------~--> 
You can search right from your browser? It's easy and it's free.  See how.
http://us.click.yahoo.com/_7bhrC/NGxNAA/yQLSAA/nhFolB/TM
--------------------------------------------------------------------~-> 

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to