スパークラインを含む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