使用Interop.Excel将excel转换为PDF时,图像不会显示 [英] Images not displayed when using Interop.Excel to convert excel to PDF
问题描述
我正在使用Interop.Excel将excel(xlsx)(2010)转换为PDF,用于应用程序。在我的开发机器上,它工作正常,图像正确显示。但是,如果将Excel转换为PDF,则图像(通过代码和其他模板文档中插入的图像)不会显示在PDF中。 excel文件在查看时很好。以下是我用于转换为PDF的代码:
I'm using Interop.Excel to convert excel (xlsx)(2010) to PDF for an application. On my development machine it works fine and the images are displayed correctly. However on the server when the excel is converted to PDF the images (some inserted via code and others in the template document) are not displayed in the PDF. The excel file is fine when viewed. Here is my code I use to convert to PDF:
Public Shared Function FromExcel(ByVal ExcelFileLocation As String, ByVal PDFFileLocation As String) As Boolean
' Load the new Excel file
' http://msdn.microsoft.com/en-us/library/bb407651(v=office.12).aspx
Dim excelApplication As ApplicationClass = New ApplicationClass()
Dim excelWorkbook As Workbook = Nothing
Dim paramExportFormat As XlFixedFormatType = XlFixedFormatType.xlTypePDF
Dim paramExportQuality As XlFixedFormatQuality = XlFixedFormatQuality.xlQualityStandard
Dim paramOpenAfterPublish As Boolean = False
Dim paramIncludeDocProps As Boolean = True
Dim paramIgnorePrintAreas As Boolean = True
Dim paramFromPage As Object = Type.Missing
Dim paramToPage As Object = Type.Missing
Try
' Open the source workbook.
excelWorkbook = excelApplication.Workbooks.Open(ExcelFileLocation)
' Save it in the target format.
If Not excelWorkbook Is Nothing Then
excelWorkbook.ExportAsFixedFormat(paramExportFormat, _
PDFFileLocation, paramExportQuality, _
paramIncludeDocProps, paramIgnorePrintAreas, _
paramFromPage, paramToPage, paramOpenAfterPublish)
Return True
Else
Return False
End If
Catch ex As Exception
Return False
Finally
' Close the workbook object.
If Not excelWorkbook Is Nothing Then
excelWorkbook.Close(False)
excelWorkbook = Nothing
End If
' Quit Excel and release the ApplicationClass object.
If Not excelApplication Is Nothing Then
excelApplication.Quit()
excelApplication = Nothing
End If
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()
End Try
End Function
这是一个屏幕截图,当它被转换时,PDF的样子。 http://it.hlbsolutions.com/uploads/Untitled-1.jpg
here is a screen shot of what the PDF looks like when it's converted. http://it.hlbsolutions.com/uploads/Untitled-1.jpg
请注意,右上角的图像未显示。任何想法都有帮助。
Notice how the images at the top and bottom right are not being displayed. Any thoughts would be helpful.
谢谢
推荐答案
类似的问题,当填充单元格和改变单选按钮 - 所有的图像将消失。
I had a similar issue when populating cells and changin radio-buttons -- all the images would disappear.
我能够通过切换服务帐户来获取图像不删除到本地系统而不是我最初选择的本地服务。
I was able to get the images to not-delete by switching the service-account to Local System instead of "Local Service" as I had originally selected.
这篇关于使用Interop.Excel将excel转换为PDF时,图像不会显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!