问题
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