0

I am working on an application in C# with visual studio that manipulates xlsx spread sheets. Everything is working fine with open XML v2.5 and spreadsheet light, however the save function throws this error:

Could not load type 'DocumentFormat.OpenXml.Spreadsheet.SmartTags' from assembly

Just in case, here is the code I am trying to run. Its a button click event for a form with two text boxes, which are used to retrieve some values and save others:

        SLDocument sl = new SLDocument("example.xlsx", "Sheet1");
        int rowNum = Convert.ToInt32(barcodeNum.Text);
        string cellAddr = "C" + barcodeNum.Text; 
        string cellEnvelope = "B" + barcodeNum.Text;
        string cellOutDate = "E" + barcodeNum.Text;
        int envelopeNumber = Convert.ToInt32(envelopeNum.Text);
        string address = sl.GetCellValueAsString(cellAddr);
        MessageBox.Show(address);
        sl.SetCellValue(cellEnvelope, envelopeNum.Text);
        sl.SetCellValue(cellOutDate, DateTime.Now);
        sl.SaveAs("Example.xls");

I looked it up and I guess something broke in open XML version 2.5. I want to use version 2.0 or earlier. When I search a nuget package the only one that is available is the most recent version. How can I install a legacy version? Is there a way to get my code to work with version 2.5? Thank you.

1 Answer 1

6

I think you want to use

Install-Package DocumentFormat.OpenXml -Version 1.0.0

DocumentFormat.OpenXml 1.0.0 is the Microsoft OpenXML SDK 2.0, the url is here. Next time you might look into ClosedXml, it's just a wrapper for openxml but I found it a lot easier to use.

4
  • ➕1 for ClosedXml, i have had nothing but problems with Spreadsheetlight but ClosedXml just worked. Aug 12, 2015 at 15:57
  • @ChrisMarisic, please can you review your statement? ClosedXml, i have had nothing but problems with Spreadsheetlight but ClosedXml just worked
    – Nasenbaer
    Dec 28, 2020 at 16:43
  • @Nasenbaer wat? Dec 29, 2020 at 16:56
  • @ChrisMarisic I dont see your comparison between "ClosedXml" and "ClosedXml", can you specify?
    – Nasenbaer
    Dec 29, 2020 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.