Flex中通过调用setClipboard将DataGrid数据复制到剪贴板便于导出Excel的代码
By Minidxer | July 23, 2008
也许你想给用户更多的导出数据的选择,下面是一段简单的代码,实现了将DataGrid数据复制到剪贴板,TAB区分,保存为TSV,也可以简单的替换成逗号区分便于保存为CSV。
- 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其他 |
Tags: CSV, DataGrid, Excel, setClipboard, TSV, 剪贴板
好久没上网了,占个边~ 哈哈 再过几天就可以休假了 yes !!!
来问候你一下拉
还可以休假,开心~