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

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

使用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相同的目录下。

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

 

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

原始的Excel

转换出来的PDF

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

目录
相关文章
|
28天前
|
Java Maven Spring
SpringBoot运行出现 Lookup method resolution failed; nested exception is java.lang.IllegalStateException
SpringBoot运行出现 Lookup method resolution failed; nested exception is java.lang.IllegalStateException
39 0
|
6月前
|
Java 编译器 数据库连接
如何使用 try-with-resources 代替try-catch-finally?
如何使用 try-with-resources 代替try-catch-finally?
|
6月前
|
Java
【Java异常】java.lang.IllegalStateException: Ambiguous mapping. Cannot map ‘xxx‘ method
【Java异常】java.lang.IllegalStateException: Ambiguous mapping. Cannot map ‘xxx‘ method
58 0
|
6月前
|
Java Spring
BeanCreationException: Error creating bean with name ‘configurationPropertiesBeans‘ defined in class
BeanCreationException: Error creating bean with name ‘configurationPropertiesBeans‘ defined in class
103 0
|
9月前
|
消息中间件 Java RocketMQ
【Java】Error creating bean with name ‘functionBindingRegistrar‘ defined in class path resource的一种解决方式
【Java】Error creating bean with name ‘functionBindingRegistrar‘ defined in class path resource的一种解决方式
51 0
|
11月前
|
Android开发
An error has occurred while drawing:java.lang.IllegalStateException: The display list is not valid.
An error has occurred while drawing:java.lang.IllegalStateException: The display list is not valid.
45 0
|
Java Android开发
Bad method handle type 7异常解决
在利用androidx版本写demo时,在添加了一些依赖后,遇到了`java.lang.ClassNotFoundException`bug,这就很奇怪了,我就添加rxjava3的依赖,就给我报这个错误。
单方法对象(Single-method Object)
单方法对象(Single-method Object)
74 2
报错解决:java.lang.Exception: Method testGetNickNameById should have no parameters
报错解决:java.lang.Exception: Method testGetNickNameById should have no parameters
260 0
|
Java Spring
Spring源码(二-2)-lookup-method、replaced-method标签
lookup-method 通常称为获取器注入,spring in action 中对它的描述是,一种特殊的方法注入,它是把一个方法声明为返回某种类型的 bean,而实际要返回的 bean 是在配置文件里面配置的。
534 1