1
我在編程上將包含迷你圖的Excel工作表導出爲PDF格式時出現問題。使用COM自動化時,Excel迷你圖不會導出爲PDF
當我使用Excel 2010的本機PDF導出工具手動將Excel工作表導出爲PDF格式時,一切正常,但是使用簡單的COM自動化工作時,所有內容都會導出爲PDF格式,但包含小數點的單元格除外。
奇怪的是,當我向Excel表格中添加一些數據條時,數據條附近的迷你圖突然被導出,但距離數據條更遠的那些條不是。
我已在多個不同的機器和操作系統上驗證了這些問題。這可能與StackOverflow上的以下問題有關。
我正在使用以下非常直截了當的VB.NET代碼。我試着玩各種設置和變量,但沒有運氣。
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