Adding Sheets

Home Forums SpreadsheetML Adding Sheets

This topic contains 2 replies, has 3 voices, and was last updated by  Ved 4 years, 6 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #7753

    swilli6926
    Participant

    Although this adds multiple sheets, it currupts the excel file.

                using (SpreadsheetDocument document = SpreadsheetDocument.Create(@"C:\Users\Public\Documents\sheets10.xlsx", SpreadsheetDocumentType.Workbook))
                {
                    //// Add a WorkbookPart to the document.
                    WorkbookPart workbookPart = document.AddWorkbookPart();
                    workbookPart.Workbook = new Workbook();
                    //// Add a WorksheetPart to the WorkbookPart.
                    WorksheetPart worksheetPart = workbookPart.AddNewPart<WorksheetPart>();
                    worksheetPart.Worksheet = new Worksheet(new SheetData());
    
                    Sheets sheets = workbookPart.Workbook.AppendChild(new Sheets());
    
                    for (uint i = 0; i < 6; i++)
                    {
                        Sheet sheet = new Sheet() { Id = workbookPart.GetIdOfPart(worksheetPart), SheetId = i, Name = i.ToString() };
                        sheets.Append(sheet);
                    }
    
                    workbookPart.Workbook.Save();
                }

    Can someone advise why this does not work.

    #7818

    openmind
    Participant

    just got into this Open Xml stuff myself. So, not sure of the exact cause here. I will, however, suggest to consider using Aspsoe.Cells, which is based on OpenXml and really makes most of Excel work much easier: we just did that.

    #8108

    Ved
    Participant

    I am also having the issue. Sheets are getting added, but corrupted. Did you managed to get it to work?
    Thanks

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.