excel - 使用 Interop.Excel 将 Excel 转换为 PDF 时不显示图像

标签 excel pdf interop

我正在使用 Interop.Excel 将 Excel (xlsx)(2010) 转换为 PDF 以供应用程序使用。在我的开发机器上它工作正常并且图像显示正确。但是,在服务器上,当 Excel 转换为 PDF 时,图像(一些通过代码插入,另一些在模板文档中插入)不会显示在 PDF 中。 excel文件查看起来没问题。这是我用来转换为 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

请注意右上角和右下角的图像没有显示。任何想法都会有帮助。

谢谢

最佳答案

在填充单元格和更改单选按钮时,我遇到了类似的问题 - 所有图像都会消失。

通过将服务帐户切换到本地系统而不是我最初选择的“本地服务”,我能够使图像不被删除。

More details at this SO question.

关于excel - 使用 Interop.Excel 将 Excel 转换为 PDF 时不显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6585147/

相关文章:

java - 如何使用 XSSFWorkbook 将 Activity 单元格移动到 apache poi 范围内的左上角单元格?

java - 如何正确加密合并的pdf文档

php - 如何在 mPDF 中设置自定义页面大小?

c++ - 将 c++ dll 导入 vb.net 时,float*(图像类型)的等效数据类型是什么?

vba - 仅用一个 'Enter' 激活用户窗体

c# - Excel Interop - 如何使用格式搜索单元格?

java - 使用 PDFBox 从 Java 编辑 PDF

.net - 将标准 C++ 嵌入到 .NET 应用程序中

go - 在 C 和 Golang 中共享结构定义的最佳方式是什么

vba - 删除重复项(大量数据,非常慢)