如何在 Flex 中将数据网格导出到 Excel 文件?

发布于 2024-08-09 04:39:31 字数 325 浏览 4 评论 0原文

如何将数据网格中的数据导出到 Excel 文件中/en.wikipedia.org/wiki/Adobe_Flex" rel="noreferrer">Flex?

谁能提供一些例子吗?我正在浏览,但找不到此类示例。

编辑

浏览了很多并找到了如何将datagrid数据转换为csv格式。现在如何将其转换为Excel?有没有办法在不使用任何服务器脚本的情况下做到这一点?不能单独用Flex来完成吗?

How do I export data in my datagrid to an Excel file in Flex?

Can anyone provide some examples for that? I am browsing but couldn't find out a single example of that kind.

EDIT

Browsed a lot and found out how to convert datagrid data to csv format. Now How to convert that to excel? Is there a way to do that without using any server script ? Can't it be done in Flex alone?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

绝對不後悔。 2024-08-16 04:39:31

as3xls 供您写入 xls 文件。它只支持一张纸(但我认为这很好)。

但我认为,如果您不需要使用 excel 函数(如单元格公式),那么使用 @susichan 和 @Rafal Ziolkowski 所说的 csv 或 html 会更简单。

哦,还有 csvlib 用于编写 csv。对于html来说,像写XML一样就可以了。

There is as3xls for you to write xls file. It only support a single sheet(but I think that's fine).

But I think using csv or html as stated by @susichan and @Rafal Ziolkowski will be more simple if you do not need to use excel functions (like cell formula).

Oh, and there is csvlib for writing csv. For html, do it like writing XML will be fine.

和我恋爱吧 2024-08-16 04:39:31

如果您有 Java servlet 后端,则可以使用 servlet 来输出文件。

我唯一的 Flex 想法是输出 CSV 数据到带有文本区域的弹出窗口,用户可以将其复制并粘贴到文件中。

If you have a Java servlet back-end you can use a servlet to output the file.

My only Flex-only idea was to output the CSV data to a popup with a textarea that could be copied and pasted into a file by the user.

独自←快乐 2024-08-16 04:39:31

Excel 将 HTML 表作为一种电子表格进行读取。只需逐行、逐列读取网格并生成一组 HTML 表格单元格并生成一个名为whatever.xls 的文件。

Excel reads the HTML table as a kind of spreadsheet. Just read the grid row by row, column by column and produce a set of HTML table cells and produce a file named whatever.xls.

掩耳倾听 2024-08-16 04:39:31

首先从以下链接下载 swc 文件

链接

现在您需要做一些工作,只需复制该代码并适当地给出列名称即可。

public function roExport_export_Result(e:ResultEvent):void
        {
            if(e.result.length != 0)
            {
                btnExportToExcel.enabled = true;

                var arrExportResult:Array = e.result as Array;

                xlsFile = new ExcelFile();
                var sheet:Sheet = new Sheet();

                sheet.resize(arrExportResult.length+1,14);

                sheet.setCell(0,0,'Id');
                sheet.setCell(0,1,'Full Name');
                sheet.setCell(0,2,'Gender');
                sheet.setCell(0,3,'Birth Date');
                sheet.setCell(0,4,'College Name');
                sheet.setCell(0,5,'Qualification');
                sheet.setCell(0,6,'Email Id');
                sheet.setCell(0,7,'Mobile');
                sheet.setCell(0,8,'Position Applied For');
                sheet.setCell(0,9,'Technology Interested');
                sheet.setCell(0,10,'User Name');
                sheet.setCell(0,11,'Password');
                sheet.setCell(0,12,'Exam Date');
                sheet.setCell(0,13,'Percentage');
                sheet.setCell(0,14,'IsActive');

                for(var i:int=0;i<arrExportResult.length;i++)
                {
                    sheet.setCell(i+1, 0, arrExportResult[i].Id);
                    sheet.setCell(i+1, 1, arrExportResult[i].FullName);
                    if(arrExportResult[i].Gender == 1)
                    {
                        arrExportResult[i].Gender = "Male"
                    }
                    else
                    {
                        arrExportResult[i].Gender = "Female";
                    }
                    sheet.setCell(i+1, 2, arrExportResult[i].Gender);
                    var date:String = arrExportResult[i].BirthDate.date.toString();
                    var month:String = (arrExportResult[i].BirthDate.month + 1).toString();
                    var year:String = arrExportResult[i].BirthDate.fullYear.toString();
                    var bDate:String = date + "/" + month + "/" + year;
                    arrExportResult[i].BirthDate = bDate;
                    sheet.setCell(i+1, 3, arrExportResult[i].BirthDate);
                    sheet.setCell(i+1, 4, arrExportResult[i].CollegeId);
                    sheet.setCell(i+1, 5, arrExportResult[i].QualificationId);
                    sheet.setCell(i+1, 6, arrExportResult[i].EmailId);
                    sheet.setCell(i+1, 7, arrExportResult[i].Mobile);
                    sheet.setCell(i+1, 8, arrExportResult[i].PositionName);
                    sheet.setCell(i+1, 9, arrExportResult[i].TechForTraining);
                    sheet.setCell(i+1, 10, arrExportResult[i].UserName);
                    sheet.setCell(i+1, 11, arrExportResult[i].Password);
                    var date:String = arrExportResult[i].CreatedDate.date.toString();
                    var month:String = (arrExportResult[i].CreatedDate.month + 1).toString();
                    var year:String = arrExportResult[i].CreatedDate.fullYear.toString();
                    var hour:String = arrExportResult[i].CreatedDate.hours.toString();
                    var min:String = arrExportResult[i].CreatedDate.minutes.toString();
                    var sec:String = arrExportResult[i].CreatedDate.seconds.toString();
                    var cDate:String = date + "/" + month + "/" + year + " " + hour + ":" + min + ":" + sec;
                    arrExportResult[i].CreatedDate = cDate;
                    sheet.setCell(i+1, 12, arrExportResult[i].CreatedDate);
                    sheet.setCell(i+1, 13, arrExportResult[i].Percentage);
                    sheet.setCell(i+1, 14, arrExportResult[i].IsActive);
                }

                dataGridResult.dataProvider = arrExportResult;

                xlsFile.sheets.addItem(sheet);      
                bytes = xlsFile.saveToByteArray();                  
            }
            else
            {
                arrExportResult = new Array();
                dataGridResult.dataProvider = arrExportResult;
                btnExportToExcel.enabled = false;
                xlsFile = new ExcelFile();
                var sheet:Sheet = new Sheet();
                Alert.show("No Records Found",parentApplication.alertTitle);
            }
        }

First Download swc file from the following Link

Link

Now you need to do little bit of work just copy that code and give column names appropriately.

public function roExport_export_Result(e:ResultEvent):void
        {
            if(e.result.length != 0)
            {
                btnExportToExcel.enabled = true;

                var arrExportResult:Array = e.result as Array;

                xlsFile = new ExcelFile();
                var sheet:Sheet = new Sheet();

                sheet.resize(arrExportResult.length+1,14);

                sheet.setCell(0,0,'Id');
                sheet.setCell(0,1,'Full Name');
                sheet.setCell(0,2,'Gender');
                sheet.setCell(0,3,'Birth Date');
                sheet.setCell(0,4,'College Name');
                sheet.setCell(0,5,'Qualification');
                sheet.setCell(0,6,'Email Id');
                sheet.setCell(0,7,'Mobile');
                sheet.setCell(0,8,'Position Applied For');
                sheet.setCell(0,9,'Technology Interested');
                sheet.setCell(0,10,'User Name');
                sheet.setCell(0,11,'Password');
                sheet.setCell(0,12,'Exam Date');
                sheet.setCell(0,13,'Percentage');
                sheet.setCell(0,14,'IsActive');

                for(var i:int=0;i<arrExportResult.length;i++)
                {
                    sheet.setCell(i+1, 0, arrExportResult[i].Id);
                    sheet.setCell(i+1, 1, arrExportResult[i].FullName);
                    if(arrExportResult[i].Gender == 1)
                    {
                        arrExportResult[i].Gender = "Male"
                    }
                    else
                    {
                        arrExportResult[i].Gender = "Female";
                    }
                    sheet.setCell(i+1, 2, arrExportResult[i].Gender);
                    var date:String = arrExportResult[i].BirthDate.date.toString();
                    var month:String = (arrExportResult[i].BirthDate.month + 1).toString();
                    var year:String = arrExportResult[i].BirthDate.fullYear.toString();
                    var bDate:String = date + "/" + month + "/" + year;
                    arrExportResult[i].BirthDate = bDate;
                    sheet.setCell(i+1, 3, arrExportResult[i].BirthDate);
                    sheet.setCell(i+1, 4, arrExportResult[i].CollegeId);
                    sheet.setCell(i+1, 5, arrExportResult[i].QualificationId);
                    sheet.setCell(i+1, 6, arrExportResult[i].EmailId);
                    sheet.setCell(i+1, 7, arrExportResult[i].Mobile);
                    sheet.setCell(i+1, 8, arrExportResult[i].PositionName);
                    sheet.setCell(i+1, 9, arrExportResult[i].TechForTraining);
                    sheet.setCell(i+1, 10, arrExportResult[i].UserName);
                    sheet.setCell(i+1, 11, arrExportResult[i].Password);
                    var date:String = arrExportResult[i].CreatedDate.date.toString();
                    var month:String = (arrExportResult[i].CreatedDate.month + 1).toString();
                    var year:String = arrExportResult[i].CreatedDate.fullYear.toString();
                    var hour:String = arrExportResult[i].CreatedDate.hours.toString();
                    var min:String = arrExportResult[i].CreatedDate.minutes.toString();
                    var sec:String = arrExportResult[i].CreatedDate.seconds.toString();
                    var cDate:String = date + "/" + month + "/" + year + " " + hour + ":" + min + ":" + sec;
                    arrExportResult[i].CreatedDate = cDate;
                    sheet.setCell(i+1, 12, arrExportResult[i].CreatedDate);
                    sheet.setCell(i+1, 13, arrExportResult[i].Percentage);
                    sheet.setCell(i+1, 14, arrExportResult[i].IsActive);
                }

                dataGridResult.dataProvider = arrExportResult;

                xlsFile.sheets.addItem(sheet);      
                bytes = xlsFile.saveToByteArray();                  
            }
            else
            {
                arrExportResult = new Array();
                dataGridResult.dataProvider = arrExportResult;
                btnExportToExcel.enabled = false;
                xlsFile = new ExcelFile();
                var sheet:Sheet = new Sheet();
                Alert.show("No Records Found",parentApplication.alertTitle);
            }
        }
凉薄对峙 2024-08-16 04:39:31

as3xls 看起来读起来不错,但编写 Excel 文件则是另一回事了。它无法编写多表工作簿,[大多数时候]无法读取自己的文件,当 Excel 可以读取 as3xls 输出的内容时,您必须进行多次保存才能清除所有垃圾。真是无赖。我正在使用 AIR 2.0 的 NativeProcess 调用 Python 脚本来进行编写,我想我必须先将 datagrid/ArrayCollection 导出到 CSV...似乎还有很长的路要走。不敢相信没有更好的 ActionScript 选项来处理 Excel。这任务真的有那么罕见吗?

as3xls seems to read fine but writing Excel files is another story. It can't write multisheet workbooks, it [most of the time] can't read it's own files, and when Excel can read what as3xls spits out you have to do multiple saves to get all the garbage out. A real bummer. I'm working on using AIR 2.0's NativeProcess to call a Python script to do the writing and I guess I'll have to export the datagrid/ArrayCollection to CSV first... seems like a long way around. Can't believe there's not a better ActionScript option for mucking with Excel. Is it really that rare of a task?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文