You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Spreadsheet Light v3.5.0与DocumentFormat.OpenXml v3.0.0时为何触发System.InvalidProgramException?

问题原因与解决方案

原因

SpreadsheetLight 3.5.0依赖DocumentFormat.OpenXml 2.x系列版本,而DocumentFormat.OpenXml 3.0.0属于重大版本更新,包含API破坏性变更,导致SpreadsheetLight调用旧版API时出现反射绑定失败的MissingMethodException。

解决方案

  1. 降级DocumentFormat.OpenXml
    直接将项目中的DocumentFormat.OpenXml版本回退到v2.20.0(已验证可正常运行),修改项目文件:

    <PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" />
    
  2. 等待SpreadsheetLight适配
    等待SpreadsheetLight发布兼容DocumentFormat.OpenXml 3.0.0的新版本,届时升级SpreadsheetLight即可解决兼容性问题。


问题场景确认

  • 触发异常的极简代码:
    using SpreadsheetLight;
    
    var template = new SLDocument();
    
  • 异常截图:
    Exception and call stack
  • 项目配置:
    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net7.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
      </PropertyGroup>
      <ItemGroup>
        <PackageReference Include="DocumentFormat.OpenXml" Version="3.0.0" />
        <PackageReference Include="SpreadsheetLight" Version="3.5.0" />
      </ItemGroup>
    </Project>
    

内容的提问来源于stack exchange,提问作者Dave Moran

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 05:45:28