使用Openxml将巨大的xml导出到excel [英] Exporting huge xml to excel using Openxml

查看:160
本文介绍了使用Openxml将巨大的xml导出到excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用openxml sdk 2.0..it向excel写入大量已转换的xml数据,这给了我一个很大的例外.我认为Open xml不支持将大量数据写入excel..i能够写入50000行.这是我的代码::

I tried to write a big transformed xml data to excel using openxml sdk 2.0..its given me a big exception.i think the Open xml is not supportive to write the bulk data to excel..i was able to write 50000 rows. this is my code::

 public void AddPartXml(OpenXmlPart part, string xml)
     { 
        using (Stream stream = part.GetStream())
        {
          byte[] buffer = (new UTF8Encoding()).GetBytes(xml);
          stream.Write(buffer, 0,buffer.Length);
          stream.Dispose();
        } 
    } 

是否有可能我们可以将数据分块写入exe,而不是一次写入.

Is there any possibility that we can write data to exce in chunk instead of writing in one shot.

推荐答案

我们是否有可能将数据写入块中 而不是一shot而就.

Is there any possibility that we can write data to exce in chunk instead of writing in one shot.

否,但是您可以将OpenXML库与XmlTextWriter结合使用来解决此类问题.

No, but you can use the OpenXML libraries in conjunction with XmlTextWriter to get around issues like this.

在我的免费C#导出到Excel"库中查看源代码.

Have a look at the source code in my free C# "Export to Excel" library which does this.

http://www.mikesknowledgebase.com/pages/CSharp/ExportToExcel.htm

当试图为要在内存中写入的整个Excel .xlsx文件构建图像"时,我遇到了相同的问题.最终,您的应用程序将耗尽内存,然后崩溃.

I had the same issue when trying to build up "an image" of the entire Excel .xlsx file which I wanted to write in memory. Eventually, your application will just run out of memory, and crash.

这篇关于使用Openxml将巨大的xml导出到excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆