Universal Document Converter
Información general
Soporte técnico
Acerca de fCoder SIA

      Búsqueda en el sitio

      Conversiones populares
Adobe PDF a JPEG
Word Document a PDF
Hojas de cálculo Excel a PDF
PowerPoint a JPEG
Diseño Visio a PDF
Diseño AutoCAD a TIFF
Página web a JPEG
Convertir de cálculo Excel a PDF
Convertir DjVu a PDF
Convertir una página web a PDF

      Tutorial de vídeo
Ver el tutorial

Página principal>Developer Solutions>Examples>Visual Basic 6>Excel Spreadsheets to PDF

Converting Excel Spreadsheets to PDF

' 1) Microsoft Excel 97 or above should be installed and activated on your PC.
' 2) Universal Document Converter 5.2 or above should be installed, too.
' 3) Open your project in Microsoft Visual Basic 6.0.
' 4) In Visual Basic main menu press "Project->References".
' 5) In the list of references check "Universal Document Converter Type Library".
' 6) Before using this example, please read this article from Microsoft Excel 2003 knowledge base:
'    http://support.microsoft.com/kb/320369/en-us/

Private Sub PrintExcelToPDF(strFilePath As String)

  Dim objUDC As IUDC
  Dim itfPrinter As IUDCPrinter
  Dim itfProfile As IProfile
  Dim ExcelApp As Object
  Dim ExcelBook As Object
  Dim ExcelWorksheet As Object
  Dim ExcelPageSetup As Object

  Set objUDC = New UDC.APIWrapper
  Set itfPrinter = objUDC.Printers("Universal Document Converter")
  Set itfProfile = itfPrinter.Profile

' Use Universal Document Converter API to change settings of converterd document
  itfProfile.PageSetup.FormName = "A2"
  itfProfile.PageSetup.ResolutionX = 200
  itfProfile.PageSetup.ResolutionY = 200
  itfProfile.PageSetup.Orientation = PO_LANDSCAPE
  itfProfile.FileFormat.ActualFormat = FMT_PDF
  itfProfile.FileFormat.PDF.ColorSpace = CS_TRUECOLOR
  itfProfile.FileFormat.PDF.Multipage = MM_MULTI
  itfProfile.Adjustments.Crop.Mode = CRP_AUTO
  itfProfile.OutputLocation.Mode = LM_PREDEFINED
  itfProfile.OutputLocation.FolderPath = "C:\Out"
  itfProfile.OutputLocation.FileName = "&[DocName(0)] -- &[Date(0)] -- &[Time(0)].&[ImageType]"
  itfProfile.OutputLocation.OverwriteExistingFile = False
' Run Microsoft Excle as COM-server
  On Error Resume Next
  Set ExcelApp = CreateObject("Excel.Application")

' Open spreadsheet from file
  Err = 0 ' Clear GetLastError() value
  Set ExcelBook = ExcelApp.Workbooks.Open(strFilePath, , True)

  If Err = 0 Then
  ' Change active worksheet settings and print it
    Set ExcelWorksheet = ExcelBook.ActiveSheet
    Set ExcelPageSetup = ExcelWorksheet.PageSetup
    ExcelPageSetup.Orientation = 2 ' Landscape
    Call ExcelWorksheet.PrintOut(, , , False, "Universal Document Converter")

  ' Close the spreadsheet
    Call ExcelBook.Close(False)
    Set ExcelBook = Nothing

  End If

' Close Microsoft Excel
  Call ExcelApp.Quit
  Set ExcelApp = Nothing

End Sub

© 2001-2017 fCoder SIA Acerca de fCoder SIA | Mapa del sitio