c# vb.net excel sql-server-2005 ssis

c# - Código para convertir Excel a PDF utilizando VB.NET



sql-server-2005 ssis (0)

Tengo el código VB para convertir .xlsx a .pdf en SCRIPT TASK. Cuando ejecuto la tarea, se ejecuta correctamente sin errores. Pero el archivo de Excel no está convirtiendo al formato pdf.

He agregado la referencia de Microsoft.Office.Interop.Excel a la tarea. Por favor mira el siguiente código. No podría saber cuál es el error en esto.

Por favor ayuda. Gracias por adelantado.

Imports Excel = Microsoft.Office.Interop.Excel Imports System.IO Imports System.Data.SqlClient Imports System.Text Imports Microsoft.Office.Interop.Excel Imports Microsoft.SqlServer.Dts.Runtime <System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _ <System.CLSCompliantAttribute(False)> _ Partial Public Class ScriptMain Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase Enum ScriptResults Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure End Enum Public Sub Main() Dim oApplication As ApplicationClass = New ApplicationClass() Dim oWorkbook As Workbook = Nothing Dim PDFFile As String = "D:/Convert XL to PDF/Test.pdf" Dim pFormatType As XlFixedFormatType = XlFixedFormatType.xlTypePDF Dim pQuality As XlFixedFormatQuality = XlFixedFormatQuality.xlQualityMinimum Dim pIncludeDocProperties As Boolean = True Dim pIgnorePrintAreas As Boolean = True Dim pFrom As Object = Type.Missing Dim pTo As Object = Type.Missing Dim pOpenAfterPublish As Boolean = False Try oWorkbook = oApplication.Workbooks.Open("D:/Convert XL to PDF/convert.xlsx") Dim oWorksheet As Excel.Worksheet oWorksheet = oApplication.Worksheets(1) oWorksheet.PageSetup.FitToPagesWide = 1 oWorksheet.PageSetup.FitToPagesTall = 1 oWorksheet.PageSetup.Zoom = False If Not oWorkbook Is Nothing Then oWorkbook.ExportAsFixedFormat(pFormatType, PDFFile, pQuality, _ pIncludeDocProperties, _ pIgnorePrintAreas, _ pFrom, pTo, pOpenAfterPublish) End If Catch ex As Exception End Try If Not oWorkbook Is Nothing Then oWorkbook.Close(False) oWorkbook = Nothing End If If Not oApplication Is Nothing Then oApplication.Quit() oApplication = Nothing End If GC.Collect() GC.WaitForPendingFinalizers() Dts.TaskResult = ScriptResults.Success End Sub End Class