温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》
  • 首页 > 
  • 教程 > 
  • 网络安全 > 
  • 使用Spire组件抛出异常The type initializer for 'spr857' threw an exception

使用Spire组件抛出异常The type initializer for 'spr857' threw an exception

发布时间:2020-09-12 23:49:12 来源:网络 阅读:609 作者:26度出太阳 栏目:网络安全

使用Spire组件抛出异常The type initializer for 'spr857' threw an exception

 

我使用免费的Spire.Xls组件尝试去转换Excel文档到PDF文档,在执行下面第二行代码,也就是做加载文档这步时,抛出了异常“The type initializer for 'spr857' threw an exception”

Workbook workbook = new Workbook();

workbook.LoadFromFile("D:\\sample.xlsx");

workbook.SaveToFile("D:\\sample.pdf", Spire.Xls.FileFormat.PDF);

这个问题困扰了我老半天,在网上也没搜到它的解决方案,后来访问了E-iceblue公司的论坛,才找到了它的解决方案,E-iceblue 公司的技术人员回复的说是:please make sure Spire.pdf.dll file is placed in the same location as Spire.xls.dll.

根据这个意思我尝试了两种方案,都能解决这个问题,在这里分享一下:

方案1,将Spire.Xls包里的Spire.pdf.dll文件拷贝到Spire.Xls.dll相同的目录下。

使用Spire组件抛出异常The type initializer for 'spr857' threw an exception

方案2,将Spire.XLS.dll和Spire.Pdf.dll同时作为Reference导入到项目里。

使用Spire组件抛出异常The type initializer for 'spr857' threw an exception

 

转换出来的结果真是完美极了:

原始的Excel:

使用Spire组件抛出异常The type initializer for 'spr857' threw an exception

转换出来的PDF:

使用Spire组件抛出异常The type initializer for 'spr857' threw an exception

在使用Spire.Xls的同时,我也在尝试使用免费的Spire.Doc去做Word文档到PDF文档转换时,遇到了相同的问题,上面的两个方案也适用在Spire.Doc组件中。


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI