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:
- import flash.system.System;
- import com.mycompany.dto.SaleDTO;
- public function exportAsTSVtoClipBoard():void
- {
- var TSVString:String = "";
- // Run through each field to create the column headers row
- TSVString += "Buyer name" + "\t";
- TSVString += "Buyer id" + "\t";
- TSVString += "Buyer address" + "\t";
- TSVString += "Gross Amount" + "\t";
- TSVString += "VAT AMount" + "\t";
- TSVString += "Net Amount" + "\t";
- // Line break
- TSVString += "\t" + "\t" + "\t" + "\t" + "\t" + "\n";
- // Run through each datagrid row
- for each(var item:SaleDTO in this.model.sales)
- {
- TSVString += item.buyerName + "\t";
- TSVString += item.buyerId + "\t";
- TSVString += item.buyerAddress + "\t";
- TSVString += this.numberFormatter.format(item.grossAmount) + "\t";
- TSVString += this.numberFormatter.format(item.vatAmount) + "\t";
- TSVString += this.numberFormatter.format(item.netAmount) + "\n";
- }
- // Copy the TSV string to the clipboard
- System.setClipboard(TSVString);
- }
Topics:
Adobe-Flex |
No Comments »
|
Tags: CSV, DataGrid, Excel, setClipboard, TSV