Quantcast
Channel: Open XML Format SDK forum
Viewing all 1288 articles
Browse latest View live

Stream in memory XLSX file using Openxml returns "Corrupted" file

$
0
0

Creating XLSX file using open xml 2.0 (Tried 2.5 also, but same issue), results in "Corrupted" file.

Same code works well in local machine(IIS express 6.0), in server it fails to return proper file

Server: windows 2003

IIS: 6.0

I have two virtual directory under my website (MyApp & MyTestApp)and both points to same code base, same Application pool and same user id. MyAppTest virtual directory generates excel without any issues but the other files. Verified the configurations on both virtual directory, there is no difference. I cannot switch my application url to MyTestApp.

When I verified the content length I can see few bytes difference(approximately 5 bytes less in MyApp)

When I unzipped the corrupted excel file, there is no data in "Content-Type.xml"

Appreciated if you have any solution/suggestion to fix this issue

Thanks in advance


SmartArt Algorithm

$
0
0

Is there someone could help me ,some problem with SmartArt in office 2007. i konw SmartArt have  snake Algorithm,linear Algorithm and so on,but i can't get the right position of shape's and the right width of shape's,is there some information forget,or some information in Algorithm i can't get?

i would be happy to any answer.Thanks!

[Excel] Add Checkbox with OpenXML SDK and C#

$
0
0

Hi,

how can I add a checkbox to an Excel 2007/2010 document with the OpenXML SDK and C#?

Many thanks

Nico

Open XML SDK v2 Handling Multiple Threads

$
0
0

Hi

I have read a post or two that suggests the open XML sdk is not thread safe but I haven't found any official MS document that states this in fact to the contrary most online docs demonstrate how to use the SDK for serverside creation of office documents. I'm prototyping a windows service that reads MSMQ and dispatches a thread to export some data to excel using open xml sdk v2.  The thread is created by calling BeginInvoke on a delegate and ultimately calls this code:

using

(SpreadsheetDocument workBook =SpreadsheetDocument.Open(exportFileInfo.FullName,true))

{

 

WorkbookHelper workBookHelper =newWorkbookHelper(workBook.WorkbookPart, tableName);

exportRowCount =

this.DataBind(workBookHelper, datasource);

workBook.WorkbookPart.Workbook.Save();

workBook.Close();

 

 

return exportRowCount;

}

If I allow 2 or more threads to run concurrently:

  • The code never finishes when I try to export 10000 rows. (I suspect I'm getting deadlock but not sure how to verify this). 
  • It does work if I try to export 5000 rows or less.

If I comment out the calls to save() and close() the code always finishes no matter how many threads I allow to run.  If I allow just one thread to run the exports always works.

Is there a threading problem in the SDK related to saving and closing workbooks and if so is there a plan to fix it soon?

Other than synchronising the entire block of code above is there a way I can I fix the problem myself?

Regards







 

Insert Images in Header- and Maindocumentpart

$
0
0

Hello all,

I've got a big problem. I developed a little DLL for a template-system with Open XML SDK.

I want to copy a headerpart from one templates header and a maindocumentpart from another template.

Everything works fine. But if the header and the content includes an image, word is crashs and don't open

the document. If i have only an image in the headerpart or only in the maindocumentpart the document in created correctly.

Is there something to consider if i want to have imageparts in two different documentparts (e. g. Headerpart and Maindocumentpart)?

Best Regards,

Manuel

Get Excel checkbox value

$
0
0

I am trying to import a CheckBox value (checked/unchecked) which is technically an Excel Drawing. I've gotten the raw XML using EPPlus and I still cannot find a value for the CheckBox's anywhere. They appear but there doesn't seem to be a value for them in the XML?

Am I missing something? Is it not possible? A CheckBox looks like this...

<mc:AlternateContent xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\"><mc:Choice Requires=\"x14\"><control shapeId=\"1032\" r:id=\"rId36\" name=\"CheckBox7\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\"><controlPr autoLine=\"0\" r:id=\"rId37\"><anchor moveWithCells=\"1\"><from><xdr:col xmlns:xdr=\"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing\">4</xdr:col><xdr:colOff xmlns:xdr=\"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing\">704850</xdr:colOff><xdr:row xmlns:xdr=\"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing\">59</xdr:row><xdr:rowOff xmlns:xdr=\"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing\">114300</xdr:rowOff></from><to><xdr:col xmlns:xdr=\"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing\">4</xdr:col><xdr:colOff xmlns:xdr=\"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing\">1190625</xdr:colOff><xdr:row xmlns:xdr=\"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing\">61</xdr:row><xdr:rowOff xmlns:xdr=\"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing\">47625</xdr:rowOff></to></anchor></controlPr></control></mc:Choice><mc:Fallback><control shapeId=\"1032\" r:id=\"rId36\" name=\"CheckBox7\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" /></mc:Fallback></mc:AlternateContent>

Replace image in word doc using OpenXML

$
0
0

Hi,

I want to fill my Picture Content Control that is located in my word document with this code: (I have passed content control tag and the image stream via document parameter to this function)

       public void FillDocument(Stream stream, XDocument document)
        {                

using (WordprocessingDocument wordDocument =
                WordprocessingDocument.Open(stream, true))
            {
                List<SdtElement> descendants = wordDocument.MainDocumentPart.Document.Descendants<SdtElement>().ToList();

                XDocument doc = document;

                foreach (SdtElement item in descendants)
                {
                    SdtAlias alias = item.Descendants<SdtAlias>().FirstOrDefault();

                    if (alias != null)
                    {
                        Run xRun = item.Descendants<Run>().FirstOrDefault();
                        Text xText = xRun.Descendants<Text>().FirstOrDefault();

                        //Text xText = sdtContentRun.Descendants<Text>().FirstOrDefault();
                        string sdtTitle = alias.Val.Value;


                        //if Sdt Content Control is Picture
                        string imageContent = (from xElement in doc.Descendants("Picture") where xElement.Attribute("Id").Value == sdtTitle select xElement.Value).FirstOrDefault();
                        if (imageContent != null)
                        {
                            MemoryStream result = (MemoryStream)StringToStream(imageContent);

                            SdtProperties p = item.Elements<SdtProperties>().FirstOrDefault();
                            if (p != null)
                            {
                                // Is it a picture content control?
                                SdtContentPicture pict = p.Elements<SdtContentPicture>().FirstOrDefault();
                                // Get the alias.
                                SdtAlias a = p.Elements<SdtAlias>().FirstOrDefault();
                                if (pict != null && a.Val.Value == sdtTitle)
                                {
                                    string embed = null;
                                    Drawing dr = item.Descendants<Drawing>().FirstOrDefault();
                                    if (dr != null)
                                    {
                                        D.Blip blip = dr.Descendants<D.Blip>().FirstOrDefault();
                                        if (blip != null)
                                            embed = blip.Embed;
                                        if (embed != null)
                                        {
                                            IdPartPair idpp = wordDocument.MainDocumentPart.Parts
                                                .Where(pa => pa.RelationshipId == embed).FirstOrDefault();
                                            if (idpp != null)
                                            {
                                                ImagePart ip = (ImagePart)idpp.OpenXmlPart;
                                                ip.FeedData(result);
                                            }
                                        }
                                    }
                                }
                            }



                            continue;
                        }

}

}

It finds the Pictire content control in word document but in this line:

 ImagePart ip = (ImagePart)idpp.OpenXmlPart;

I get this error:

Unable to cast object of type ‘DocumentFormat.OpenXml.Packaging.CustomXmlPart’ to type ‘DocumentFormat.OpenXml.Packaging.ImagePart’.

Could you please guide me?


Fill Picture content control in header of word doc using OpenXML

$
0
0

Hi,

I want to fill my Picture Content Control that is located in the headerof my word document with this code: (I have passed content control tag and the image stream via document parameter to this function)

       public void FillDocument(Stream stream, XDocument document)
        {                

using (WordprocessingDocument wordDocument =
                WordprocessingDocument.Open(stream, true))
            {
                List<SdtElement> descendants = wordDocument.MainDocumentPart.Document.Descendants<SdtElement>().ToList();

foreach (var headerPart in wordDocument.MainDocumentPart.HeaderParts)
                {
                    descendants.AddRange(headerPart.Header.Descendants<SdtElement>().ToList());
                }
                foreach (var footerPart in wordDocument.MainDocumentPart.FooterParts)
                {
                    descendants.AddRange(footerPart.Footer.Descendants<SdtElement>().ToList());
                }

                XDocument doc = document;

                foreach (SdtElement item in descendants)
                {
                    SdtAlias alias = item.Descendants<SdtAlias>().FirstOrDefault();

                    if (alias != null)
                    {                         
                        string sdtTitle = alias.Val.Value;


                        //if Sdt Content Control is Picture
                        string imageContent = (from xElement in doc.Descendants("Picture") where xElement.Attribute("Id").Value == sdtTitle select xElement.Value).FirstOrDefault();
                        if (imageContent != null)
                        {
                            MemoryStream result = (MemoryStream)StringToStream(imageContent);

                            SdtProperties p = item.Elements<SdtProperties>().FirstOrDefault();
                            if (p != null)
                            {
                                // Is it a picture content control?
                                SdtContentPicture pict = p.Elements<SdtContentPicture>().FirstOrDefault();
                                // Get the alias.
                                SdtAlias a = p.Elements<SdtAlias>().FirstOrDefault();
                                if (pict != null && a.Val.Value == sdtTitle)
                                {
                                    string embed = null;
                                    Drawing dr = item.Descendants<Drawing>().FirstOrDefault();
                                    if (dr != null)
                                    {
                                        D.Blip blip = dr.Descendants<D.Blip>().FirstOrDefault();
                                        if (blip != null)
                                            embed = blip.Embed;
                                        if (embed != null)
                                        {
                                            IdPartPair idpp = wordDocument.MainDocumentPart.Parts
                                                .Where(pa => pa.RelationshipId == embed).FirstOrDefault();
                                            if (idpp != null)
                                            {
                                                ImagePart ip = (ImagePart)idpp.OpenXmlPart;
                                                ip.FeedData(result);
                                            }
                                        }
                                    }
                                }
                            }



                            continue;
                        }

}

}

It finds the Pictire content control in word document but in this line:

 ImagePart ip = (ImagePart)idpp.OpenXmlPart;

I get this error:

Unable to cast object of type ‘DocumentFormat.OpenXml.Packaging.CustomXmlPart’ to type ‘DocumentFormat.OpenXml.Packaging.ImagePart’.

Could you please guide me?







How I can Insert a Image into the Header of Word Document using Open XML SDK 2.5

$
0
0

Hi Greetings to all,

Can anyone help me on How I can Insert a Image into the Header of Word Document using Open XML SDK 2.5. i want both doc and docx can be added with the Header which having the Logo image. Looking forward to your suggestions.


RehaanKhan. M

Checking to see if a part exists

$
0
0

I want to know what the best what to check for a part's existence in a document is. I have a scenario where I want to see if a document has an external relationship. If it doesn't have one, then add one. What would be the best way to do this? I tried using getPartById("externalRelationshipID"), but this throws an exception if the part doesn't exist. I'm looking for the equivalent of hasPartWithId(id), but that method doesn't exist.

Edit: It seems like a good way to do this would be to use someDocument.Parts.Contains(), but document.Parts is an enumerable and I can't seem to find the right syntax for using it.  

MS Word | Applying styling to a HTML formatted paragraph using DocumentFormat.OpenXml.dll

$
0
0

Hi,

 

I am using DocumentFormat.OpenXml.dll to create a document file in which we are showing some HTML formatted data. I want to add additional numbering styles (1, 1.1, i, I, A, a) to the added HTML paragraph. However if I try to add this to the paragraph, the property is displayed as null.

 

Could you please help me in applying the styling to the HTML formatted paragraph?

 

The following methods are being used to generate the documents:

 

privateParagraph GetStyledParagraph(RunProperties rps,ParagraphProperties pgps, string text,refWordprocessingDocument myDoc)

        {

           Paragraph pp = null;

            System.Text.RegularExpressions.Regex tagRegex =new System.Text.RegularExpressions.Regex(@"<\s*([^> ]+)[^>]*>.*?<\s*/\s*\1\s*>");

           Run run = new Run();

           if (rps != null)

                run.Append(rps.CloneNode(true));

           if (myDoc != null&& text !=null&&tagRegex.IsMatch(text))//HTML DATA

            {

                pp = GetParaEditor(text, myDoc,"");

 

               if (pgps != null)

                    pp.Append(pgps.CloneNode(true)); //Paragraph property is not getting applied.

                pp.AppendChild<Run>(run);

               return pp;

            }

           else//Normal text

            {

 

                run.AppendChild<Text>(new Word.Text(text) { Space = SpaceProcessingModeValues.Preserve });

               Paragraph pg = new Word.Paragraph();

               if (pgps != null)

                    pg.Append(pgps.CloneNode(true)); //Paragraph property is getting applied.

                pg.AppendChild<Run>(run);

               return pg;

            }

 

        }

 

int icnt = 0;

privateParagraph GetParaEditor(string editorContentBlob,WordprocessingDocument myDoc, string altChnkId)

        {

           XNamespace w = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

           XNamespace r = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";

 

           string html =

            @"<html>

                      < head/>

                      < body>

                       {0}

                      < /body>

               < /html>";

            System.Text.StringBuilder sbu =new System.Text.StringBuilder();

            html = sbu.AppendFormat(html, editorContentBlob).ToString();

           // html =  objEditorContent.ToString();

           string altChunkId = "AltChunkId"+ icnt++;

 

           MainDocumentPart mainPart = myDoc.MainDocumentPart;

           AlternativeFormatImportPart chunk = mainPart.AddAlternativeFormatImportPart(

               "application/xhtml+xml", altChunkId);

           using (Stream chunkStream = chunk.GetStream(FileMode.Create,FileAccess.Write))

           using (StreamWriter stringStream =newStreamWriter(chunkStream))

                stringStream.Write(html);

           XElement altChunk = newXElement(w + "altChunk",

               newXAttribute(r +"id", altChunkId)

            );

 

           AltChunk altChunck = newAltChunk();

            altChunck.Id = altChunkId;

 

           Paragraph paraEditor = newParagraph();

            paraEditor.Append(newRun(altChunck));

           return paraEditor;

        }

 

 

 

Thank you.

 

-Sunil

 


Can't find template for Open XML SDK or Office Tools on Visual Studio

$
0
0

Hi Guys,

I can't get Visual Studio 2015 Community Edition to see Open XML SDK or Office Tools SDK. I've installed Open XML SDK 2.5 and the current version of Office Tools 365. I've opened VS and made a new project, but the template for all of the above is missing. I've tried 'repairing' Visual Studio, and restarting the computer. I've tried clicking 'Modify', but it doesn't allow me to add anything that wasn't previously there.

How do I add these templates to VS?!

Thanks!

Open XML SDK on NuGet?

$
0
0

There is version 2.0 of the SDK on NuGet, but its not clear whether that was published and is maintained by Microsoft. Would it be possible to post the latest version on NuGet?

Thank you!

-Michael

Cell Strin Type - InnerText - return a "" for a empty cell

$
0
0

Hi

I'm reading cells from a spreadsheet and I have a cell whose type is CellValues.String.

To read the value I'm using

String value = cell.InnerText;

The cell (appears) to be empty and I get  a String containing "" - i.e. a string with two double quotes.

Using the debugger, the cell - base information tells me

CellFormula "\"\""

CellValue ""

How can I get it to give me the "Real" value of the cell - i.e. an empty string in this case?

Thanks

How to Change the HyperlinkBase property in a DOCX document using VB.Net and OpenXML

$
0
0

I need to bulk change/set the Hyperlink Base property for a set of documents. I can open the docx using .net and OPEN XML, however I'm having a problem making the next step in getting to and changing the correct property. In the sample below I get the number of characters but am not sure that is the path I should be following. I am using VS2010 and have a reference to DocumentFormat.OpenXml and am using OpenXml 2.5.

Private Sub ListFiles(ByVal lst As ListBox, ByVal pattern As String, ByVal dir_info As DirectoryInfo)
    ' Get the files in this directory.
    Dim fs_infos() As FileInfo = dir_info.GetFiles(pattern)
    For Each fs_info As FileInfo In fs_infos

        Dim xmlProperties As XmlDocument = New XmlDocument
        Dim wordDoc As WordprocessingDocument = WordprocessingDocument.Open(fs_info.FullName, False)
        Dim appPart As ExtendedFilePropertiesPart = wordDoc.ExtendedFilePropertiesPart
        Dim props = wordDoc.PackageProperties
        xmlProperties.Load(appPart.GetStream)
        Dim chars As XmlNodeList = xmlProperties.GetElementsByTagName("Characters")
        MessageBox.Show("Number of characters in the file = " + chars.Item(0).InnerText, "Character Count")

    Next fs_info
    fs_infos = Nothing


End Sub


How to make left address same line with right date?

$
0
0


Hello..

How to make left address same line with right date? Last address sentence must underline, then date not underline..

Example below:

Kampung Tanjung Alir,
22000, Jerteh,
Terengganu.
_____________________________________________________________________________
Pengurus Pemasaran,
Penerbitan Pelangi Sdn. Bhd.,
64 & 66, Jalan Pingai,
80400, Johor Bahru.                                                                                              14 OKTOBER 1998.

Tuan,

Memesan Buku

Merujuk kepada perkara di atas, saya Ummu Atiyah Bt Abd Fatah telah terbaca iklan dalam akhbar....

How to store a number as a number?

$
0
0

I'm writing a small application that fetches data (text and numbers) from a database and output this in a Excel document for presentation. Inserting text as text works fine, but I'm having problems storing numbers as numbers in Excel.

The number seems to still be formatted as text. The cell in Excel gets this little green arrow stating "The number in this cell is formatted as text or preceded by an apostrophe.". To determine if the value from the database is a number i try to parse it to a double:       

          string cellDataStr = row[col.ColumnName].ToString();
          double cellDataD = 0;
          Cell cell = new Cell();

          if (double.TryParse(cellDataStr.Replace(',','.'), NumberStyles.Any, new NumberFormatInfo(), out cellDataD))
          {
            // data was parsed as double;
            cell.DataType = new EnumValue<CellValues>(CellValues.Number);
            cell.CellValue = new CellValue(cellDataD.ToString());
          }
          else
          {
            // data was not parsed as double
            cell.DataType = new EnumValue<CellValues>(CellValues.String);
            cell.CellValue = new CellValue(cellDataStr);
          }

The replacement of ',' and '.' is because ',' is the separator of decimals in my country. 1000 = 1000,00, but double is using '.' so in order to parse it correctly i just replace the character.


How to convert .docx file to html file with formatting using open xml sdk 2.5

$
0
0

HI,

I am trying to convert the document file(.docx) to html file. Currently I am able to do the conversion but html file does not retain the formatting.  I am using open xml sdk 2.0.

For example: If a paragraph contain the text in red color with some text with bold and underline in docx file, the converted html shows all the lines as simple text and lost all the formatting. 

Here is my current code :

        public string ConvertDocxToHtml(string docxFileEncodedData)
        {
            string inputFileName = DateTime.Now.ToString("ddMMyyyyhhmmss") + ".docx";
            string imageDirectoryName = inputFileName.Split('.')[0] + "_files";

            DirectoryInfo imgDirInfo = new DirectoryInfo(HttpContext.Current.Server.MapPath("~/Documents/" + imageDirectoryName));

            int imageCounter = 0;
            byte[] byteArray = Convert.FromBase64String(docxFileEncodedData);//File.ReadAllBytes(docxFile);
            using (MemoryStream memoryStream = new MemoryStream())
            {
                memoryStream.Write(byteArray, 0, byteArray.Length);
                using (WordprocessingDocument doc =
                    WordprocessingDocument.Open(memoryStream, true))
                {
                    HtmlConverterSettings settings = new HtmlConverterSettings()
                    {
                        PageTitle = inputFileName,
                        ConvertFormatting = false,
                    };
                    XElement html = HtmlConverter.ConvertToHtml(doc, settings,
                        imageInfo =>
                        {
                            DirectoryInfo localDirInfo = imgDirInfo;
                            if (!localDirInfo.Exists)
                                localDirInfo.Create();++imageCounter;
                            string extension = imageInfo.ContentType.Split('/')[1].ToLower();
                            ImageFormat imageFormat = null;
                            if (extension == "png")
                            {
                                // Convert the .png file to a .jpeg file.
                                extension = "jpeg";
                                imageFormat = ImageFormat.Jpeg;
                            }
                            else if (extension == "bmp")
                                imageFormat = ImageFormat.Bmp;
                            else if (extension == "jpeg")
                                imageFormat = ImageFormat.Jpeg;
                            else if (extension == "tiff")
                                imageFormat = ImageFormat.Tiff;

                            // If the image format is not one that you expect, ignore it,
                            // and do not return markup for the link.
                            if (imageFormat == null)
                                return null;

                            string imageFileName = "image" + imageCounter.ToString() + "." + extension;
                            try
                            {
                                imageInfo.Bitmap.Save(imgDirInfo.FullName + "/" + imageFileName, imageFormat);
                            }
                            catch (System.Runtime.InteropServices.ExternalException)
                            {
                                return null;
                            }
                            XElement img = new XElement(Xhtml.img,
                                new XAttribute(NoNamespace.src, imageDirectoryName + "/" + imageFileName),
                                imageInfo.ImgStyleAttribute,
                                imageInfo.AltText != null ?
                                    new XAttribute(NoNamespace.alt, imageInfo.AltText) : null);
                            return img;
                        });

                    string htmlFilePath = HttpContext.Current.Server.MapPath("~/Documents/" + inputFileName.Split('.')[0] + ".html");
                    File.WriteAllText(htmlFilePath, html.ToStringNewLineOnAttributes());

                    return ConfigurationManager.AppSettings["ServerUri"].ToString() + "/Documents/" + inputFileName.Split('.')[0] + ".html";
                }
            }

        }

So I just want to know how can I retain the format of docx in html file ?

Thanks

ASP.Net Open office XML Create dropdown list in excel without using Interop

$
0
0

I am using ASP.Net and Open office XML and I have been able to set the headers of the excel file.
However, I want to set the value to cells from say D2 to D1000 in a drop down fashion i.e. that the user can only select from a predefined list of values as in a drop down list. How do I accomplish this? The code for creating the excel is

List<ExcelExport> mpList =newList<ExcelExport>();DataTable dt =ListToDataTable(mpList);string attachment =string.Format("attachment;filename={0}-{1}.xlsx", ddlHealthFacility.SelectedItem.Text+" Excel export "," ");using(ExcelPackage pck =newExcelPackage()){//Create the worksheetExcelWorksheet ws = pck.Workbook.Worksheets.Add("Monthly Plan");
        ws.Cells["A1"].LoadFromDataTable(dt,true);Byte[] fileBytes = pck.GetAsByteArray();Response.Clear();Response.Buffer=true;Response.AddHeader("content-disposition", attachment);Response.Charset="";Response.ContentType="application/vnd.ms-excel";StringWriter sw =newStringWriter();Response.BinaryWrite(fileBytes);Response.End();}

Spreadsheet parsing - Out of Memory Problem

$
0
0

Hi

Using BizTalk - I need take a spread sheet and convert it into an XML format something like

<sheet>

<row>

<column1>value</column1>

<column2>value</column2>

<column3>value</column2>

</row>

<row>

<column1>value</column1>

<column2>value</column2>

<column3>value</column2>

</row>

etc ...

I do not need to modify the spread sheet - just read & parse it. So I've used the following Open XML SDK code to parse the spread sheet (with the generation bits missing)

using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(originalStrm, false))
{
    var wbPart = spreadsheetDocument.WorkbookPart;
    foreach (var sheet in wbPart.Workbook.Descendants<Sheet>())
    {
        var wsheetPart = wbPart.GetPartById(sheet.Id) as WorksheetPart;
        if (wsheetPart == null)
        {
            Console.WriteLine("WorksheetPart Not Found !!");
            return null;
        }

        var ws = wsheetPart.Worksheet;
        foreach (var row in ws.Descendants<Row>())
        {
             foreach (Cell cell in row)
            {

       .... stuff .....

           }
        }
    }
}

For small spread sheets - this works brilliantly. But I have a spread sheet (not mine - I have no control over it) with 2 sheets, one has 1,050,000 rows and the other has 330,000 rows and I get an "out of memory exception" on the line

        var ws = wsheetPart.Worksheet;

My questions.

Can I get around this memory problem?

Is there a better way to parse / walk through a spread sheet?

Thanks. Trefor



Viewing all 1288 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>