Flex中通过调用setClipboard将DataGrid数据复制到剪贴板便于导出Excel的代码

By Minidxer | July 23, 2008

也许你想给用户更多的导出数据的选择,下面是一段简单的代码,实现了将DataGrid数据复制到剪贴板,TAB区分,保存为TSV,也可以简单的替换成逗号区分便于保存为CSV。


  1. import flash.system.System;
  2. import com.mycompany.dto.SaleDTO;
  3.  
  4. public function exportAsTSVtoClipBoard():void
  5. {
  6.     var TSVString:String = "";
  7.  
  8.     // Run through each field to create the column headers row
  9.  
  10.     TSVString += "Buyer name" + "\t";
  11.     TSVString += "Buyer id" + "\t";
  12.     TSVString += "Buyer address" + "\t";
  13.     TSVString += "Gross Amount" + "\t";
  14.     TSVString += "VAT AMount" + "\t";
  15.     TSVString += "Net Amount" + "\t";
  16.   
  17.     // Line break
  18.     TSVString += "\t" + "\t" + "\t" + "\t" + "\t" + "\n";
  19.   
  20.     // Run through each datagrid row
  21.   
  22.     for each(var item:SaleDTO in this.model.sales)
  23.     {
  24.         TSVString += item.buyerName + "\t";
  25.         TSVString += item.buyerId + "\t";
  26.         TSVString += item.buyerAddress + "\t";
  27.         TSVString += this.numberFormatter.format(item.grossAmount) + "\t";
  28.         TSVString += this.numberFormatter.format(item.vatAmount) + "\t";
  29.         TSVString += this.numberFormatter.format(item.netAmount) + "\n";
  30.     }
  31.       
  32.     // Copy the TSV string to the clipboard
  33.     System.setClipboard(TSVString);
  34. }

Topics: Adobe其他 | Tags: , , , , ,

Related Post

2 comments | Add One

  1. opera - 07/23/2008 at 6:43 pm

    好久没上网了,占个边~ 哈哈 再过几天就可以休假了 yes !!!

    来问候你一下拉 :)

  2. Minidxer - 07/23/2008 at 7:18 pm

    还可以休假,开心~

Leave a Comment

Name(*):

E-Mail(*) :

Website :

Comments :

Search Posts

Archives

Sponsored Ads