简体   繁体   English

是否有任何第三方工具可以将XML数据导入Excel?

[英]Are there any third-party tools which allow importing XML data into Excel?

We are currently working on an application that has been using COM Interop in C# to import data into an Excel workbook. 我们当前正在开发一个使用C#中的COM Interop将数据导入Excel工作簿的应用程序。 This data is fairly complex and lengthy, so we have been using the Import from XML feature in Excel. 这些数据相当复杂且冗长,因此我们一直在Excel中使用“从XML导入”功能。 Because of the issues with running Excel on a server, we are now looking into moving to a 3rd-party solution for our workbook creation, such as SpreadsheetGear or Aspose. 由于在服务器上运行Excel存在问题,因此我们现在正在考虑迁移到用于创建工作簿的第三方解决方案,例如SpreadsheetGear或Aspose。

SpreadsheetGear and Aspose do not support XML Import. SpreadsheetGear和Aspose不支持XML导入。 Does anyone know of another 3rd-party, server-friendly tool that does? 有谁知道另一个第三方友好的服务器友好工具吗?

--Edit-- The data is coming from an DB2 database that we are putting into C# classes and then serializing into XML. -编辑-数据来自DB2数据库,我们将其放入C#类中,然后序列化为XML。 We are then importing the XML into around 30 tables and other cells. 然后,我们将XML导入大约30个表和其他单元格中。 Then we copy and paste the tables to an output sheet and reuse the originals to import more. 然后,我们将表格复制并粘贴到输出表中,然后重复使用原始表以导入更多表。

--Edit-- The output is a form with multiple tables and fields on one sheet. -编辑-输出是一张纸上具有多个表和字段的表单。 Part of what the XML map helps with is keeping track of the locations of the cells, without having to massively hard-code cell-coordinates into the code. XML映射所提供的部分帮助是跟踪单元的位置,而不必将单元坐标大量地硬编码到代码中。

You could look at SSIS. 您可以看一下SSIS。 This has the facility where you can set XML as a datasource and a spreadsheet as a destination. 这具有将XML设置为数据源和将电子表格设置为目标的便利。 (Or vice-versa). (或相反亦然)。

EPPlus is a pretty good library but i'm not sur you can import XML directly, but you can import csv file directly, there are example in the samples. EPPlus是一个非常不错的库,但我不知道您可以直接导入XML,但可以直接导入csv文件,示例中有示例。

It would still be fairly easy to implement. 实施起来还是很容易的。

Although I have not found a 3rd party tool that allows this functionality, Aspose.Cells has a "Smart Marker" feature that allows you to designate specific cells in a way similar to an XML map. 尽管我尚未找到允许该功能的第三方工具,但Aspose.Cells具有“智能标记”功能,可让您以类似于XML映射的方式指定特定的单元。 I believe this may be the solution I have been looking for. 我相信这可能是我一直在寻找的解决方案。

Load the XML into a dataset then use EPPlus to take the datatable out of excel and create an excel file from it: 将XML加载到数据集中,然后使用EPPlus从excel中取出数据表并从中创建一个excel文件:

DataSet ds = new DataSet();
            DataTable dt = ds.Tables[0];
            using (ExcelPackage pck = new ExcelPackage())
            {
                //Create the worksheet
                ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Calls");

                //Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
                ws.Cells["A1"].LoadFromDataTable(dt, true);

                Byte[] bin = pck.GetAsByteArray();

                string file = filePath;
                File.WriteAllBytes(file, bin);

            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM