This project is read-only.
1
Vote

Invalid XLSX file after simple operation

description

I'm just trying to create a new worksheet in a new workbook.
That created file opens fine with Office, but fails on OOXML.

static void Main(string[] args)
{
string filename = @"c:\sample.xlsx";
using (MemoryStream ms = SpreadsheetReader.Create())
{
    using (SpreadsheetDocument doc = SpreadsheetDocument.Open(ms, true))
    {
        WorksheetPart sheetPart = SpreadsheetWriter.InsertWorksheet(doc, "XYZ");
        WorksheetWriter writer = new WorksheetWriter(doc, sheetPart);

        writer.PasteText("A1", "test");

        SpreadsheetWriter.Save(doc);
    }
    SpreadsheetWriter.StreamToFile(filename, ms);
}

// throws "Specified part does not exist in the package."?
using (SpreadsheetDocument doc = SpreadsheetDocument.Open(filename, false))
{
    ;
}
}

comments