使用COM Automation时,Excel Sparklines未导出为PDF [英] Excel Sparklines not exported to PDF when using COM Automation
问题描述
我在编程中导出包含迷你图的PDF表格为PDF格式的问题。
I am having a problem programmatically exporting Excel sheets that contain sparklines to PDF format.
当我使用Excel 2010的本机PDF导出手动导出Excel表格为PDF格式设施然后一切工作正常,但现在我使用简单的COM自动化,然后一切导出为PDF除了包含火花线的单元格。
When I manually export the Excel sheet to PDF format using Excel 2010's native PDF Exporting facility then everything works fine, but the moment I do it using simple COM automation then everything is exported to PDF with the exception of cells containing sparklines.
奇怪的是,当我向excel表中添加几个数据条时,数据条附近的迷你图突然导出,但远离数据条的那些不是。
The weird thing is that when I add a few data bars to the excel sheet then the sparklines near the data bars are suddenly exported, but the ones further away from the data bars are not.
I已经在多个不同的机器和操作系统上验证了这些问题。这可能与 StackOverflow 有关的以下问题。
I have verified these problems on multiple different machines and operating systems. This may be related to the following question on StackOverflow.
我使用下面的,非常简单的VB.NET代码。我已经尝试了各种设置和变量,但没有运气。
I am using the following, very straight forward, VB.NET code. I have tried playing around with the various settings and variables, but no luck.
Public Class Form1
Enum XlFixedFormatType
xlTypePDF = 0
xlTypeXPS = 1
End Enum
Enum XlUpdateLinks
xlUpdateLinksUserSetting = 1
xlUpdateLinksNever = 2
xlUpdateLinksAlways = 3
End Enum
Enum XlFixedFormatQuality
xlQualityStandard = 0
xlQualityMinimum = 1
End Enum
Private Sub buttonConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonConvert.Click
Dim pdf As String = Convert("C:\Sparkline.xlsx")
Process.Start(pdf)
End Sub
Public Function Convert(ByVal fileName As String) As String
Dim outPutFilename As String, printObject As Object = Nothing
Dim app As Object '** In reality this is a Microsoft.Office.Interop.Excel.Application
Dim doc As Object '** In reality this is a Microsoft.Office.Interop.Excel.Workbook
app = CreateObject("Excel.Application")
'** Open the _document
doc = app.Workbooks.Open(fileName:=fileName, _
UpdateLinks:=XlUpdateLinks.xlUpdateLinksNever, _
ReadOnly:=True, _
AddToMru:=False, _
IgnoreReadOnlyRecommended:=True, _
CorruptLoad:=True, _
Editable:=False)
'** Set visible sheets depending on selected range
printObject = app.ActiveWorkbook.ActiveSheet
'** Write the file under the same name, but with different extension
outPutFilename = System.IO.Path.ChangeExtension(fileName, "pdf")
printObject.ExportAsFixedFormat(Type:=XlFixedFormatType.xlTypePDF, _
fileName:=outPutFilename, _
quality:=XlFixedFormatQuality.xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False)
doc.Close(False)
app.Quit()
'** Return the name of the converted file
Return outPutFilename
End Function
End Class
推荐答案
我一直在与Microsoft支持联系,他们已经承认这是一个错误。
I have been in contact with Microsoft Support and they have acknowledged it is a bug. The product team is looking at it for inclusion in a future service pack.
在此之前,使应用程序可见,然后再执行导出操作将解决问题。如果您不希望用户看到它,那么您可以将窗口关闭屏幕。
Until then, making the Application Visible before carrying out the export will solve the problem. If you don't want the user to see it then you can position the window off screen.
这篇关于使用COM Automation时,Excel Sparklines未导出为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!