none
How to append an existing xlsx file using openxml in SAX approach? RRS feed

  • Question

  •  I was working in open xml SAX (Simple API for XML) approach. I got stuck while appending rows into the existing sheet. Is anybody know please share your thoughts.

    I am the below code

        document = SpreadsheetDocument.Open(metadataFileName, true);
                    workbookpart = document.WorkbookPart;
                    IEnumerable<Sheet> sheets = document.WorkbookPart.Workbook.GetFirstChild<Sheets>().Elements<Sheet>();
                    string relationshipId = sheets.FirstOrDefault().Id.Value;
                    sheetName = sheets.FirstOrDefault().Name.Value;
                    worksheetPart = (WorksheetPart)document.WorkbookPart.GetPartById(relationshipId);
                    workSheet = worksheetPart.Worksheet;
                    rows = worksheetPart.Worksheet.Descendants<SheetData>().FirstOrDefault().Descendants<Row>();
                    rowIndex = rows.Count() + 1;
                    sheetData = worksheetPart.Worksheet.Descendants<SheetData>().FirstOrDefault();     
                  
                    writer = OpenXmlWriter.Create(worksheetPart);
                    writer.WriteStartElement(workSheet);
                    writer.WriteStartElement(sheetData);


    Friday, June 1, 2012 6:54 AM

All replies

  • Hi Cartikn,

    Thanks for posting in the MSDN Forum.

    Do you use Open Xml SDK? I think you use it based on the snippet you provided. Is it right? I don't see any relationship between your code and SAX. If you only want to find a way to append data to known sheet I will provide you some snippet to approach it. If I have misunderstand anything, please feel free to clarify.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, June 4, 2012 1:39 AM
    Moderator
  • Thanks tom for this reply. I had misunderstood and had fixed the issue.
    Thursday, December 27, 2012 1:33 PM