简体   繁体   中英

How can I add an earlier version of open XML to my C# project?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM