Copy DataGrid Data by setClipboard in Flex For Convenience to Export Code of Excel in Flex

By admin | November 16, 2008

Maybe you want to make more choice for user to export the data. Following is a paragraph of code which could help you to copy the data of DataGrid to clipboard. It is formated by Tab and saved as TSV file or you coould save it as CSV file by comma. More detail please see the following code:


  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-Flex | No Comments » | Tags: , , , ,

Related Posts

Leave a Comment

Name:

E-Mail :

Website :

Comments :

Search Posts

Sponsor Links