Exporting huge xml to excel using Openxml

可紊 提交于 2019-12-13 09:10:27

问题


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();
        } 
    } 

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


回答1:


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

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

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

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.




回答2:


If the string is long, you can use

public override int GetBytes(
string s,
int charIndex,
int charCount,
byte[] bytes,
int byteIndex
)

to convert piece by piece, even reusing the byte array.



来源:https://stackoverflow.com/questions/11675041/exporting-huge-xml-to-excel-using-openxml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!