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 C++>Excel Spreadsheets to PDF

Converting Excel Spreadsheets to PDF

// This example was designed for using in Microsoft Visual C++ from 
// Microsoft Visual Studio 2003 or above.
// 1. Microsoft Excel 97 or above should be installed and activated on your PC.
// 2. Before using this example, please read this article from Microsoft Excel 2003 knowledge base:
//    http://support.microsoft.com/kb/320369/en-us/
// 3. Universal Document Converter 5.2 or above should be installed, too.
// 4. You must initialize the COM before you call any COM method.
// Please insert "::CoInitialize(0);" in your application initialization
// and "::CoUninitialize();" before closing it.
// 5. Import Office libraries for 32-bit version of Windows.
// For 64-bit version please change "C:\\Program Files\\" to
// "C:\\Program Files (x86)\\" in all pathes.

#pragma message("Import MSO.DLL")
// MS Office 2000 -> "C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE10\\MSO.DLL"
// MS Office 2003 -> "C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE11\\MSO.DLL"
// MS Office 2007 -> "C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE12\\MSO.DLL"
#import "C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE12\\MSO.DLL" \
	rename_namespace("MSO"), auto_rename

#pragma message("Import VBE6EXT.OLB")
#import "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA6\\VBE6EXT.OLB" \

#pragma message("Import MS Excel API")
// MS Office 2000 -> "C:\\Program Files\\Microsoft Office\\OFFICE\\Excel9.OLB"
// MS Office 2003 -> "C:\\Program Files\\Microsoft Office\\OFFICE11\\Excel.EXE"
// MS Office 2007 -> "C:\\Program Files\\Microsoft Office\\OFFICE12\\Excel.EXE"
#import "C:\\Program Files\\Microsoft Office\\OFFICE12\\Excel.EXE"\
    rename_namespace("MSEXCEL"), auto_rename

// 6. Import Universal Document Converter software API:
#import "progid:udc.apiwrapper" rename_namespace("UDC")

static COleVariant vTrue( (short)TRUE ), vFalse( (short)FALSE ), vOpt( (long)DISP_E_PARAMNOTFOUND, VT_ERROR );

void PrintExcelToPDF( CString sFilePath )
  UDC::IUDCPtr pUDC(__uuidof(UDC::APIWrapper));
  UDC::IUDCPrinterPtr itfPrinter = pUDC->Printers["Universal Document Converter"];
  UDC::IProfilePtr itfProfile = itfPrinter->Profile;

// Use Universal Document Converter API to change settings of converterd document
  itfProfile->PageSetup->ResolutionX = 600;
  itfProfile->PageSetup->ResolutionY = 600;
  itfProfile->FileFormat->ActualFormat = UDC::FMT_PDF;
  itfProfile->FileFormat->PDF->ColorSpace = UDC::CS_TRUECOLOR;
  itfProfile->FileFormat->PDF->Multipage = UDC::MM_MULTI;
  itfProfile->OutputLocation->Mode = UDC::LM_PREDEFINED;
  itfProfile->OutputLocation->FolderPath = L"C:\\Out";
  itfProfile->OutputLocation->FileName = L"&[DocName(0)] -- &[Date(0)] -- &[Time(0)].&[ImageType]";
  itfProfile->OutputLocation->OverwriteExistingFile = FALSE;

  itfProfile->PostProcessing->Mode = UDC::PP_OPEN_FOLDER;

// Run Microsoft Excel as COM-server
  MSEXCEL::_ApplicationPtr itfXLApp(L"Excel.Application");
  MSEXCEL::_WorkbookPtr itfXLBook;
  MSEXCEL::_WorksheetPtr itfXLWorksheet;
  MSEXCEL::PageSetupPtr itfXLPageSetup;

// Open the document from a file
  itfXLBook = itfXLApp->Workbooks->Open( (LPCTSTR)sFilePath, vOpt, vTrue );

// Change active worksheet settings and print it
  itfXLWorksheet = itfXLBook->ActiveSheet;
  itfXLPageSetup = itfXLWorksheet->PageSetup;
  itfXLPageSetup->Orientation = MSEXCEL::xlLandscape;
  itfXLWorksheet->PrintOut( vOpt, vOpt, vOpt, vFalse, "Universal Document Converter");

  // Close the spreadsheet without saving changes
  itfXLBook->Close( vFalse );
  // Close Microsoft Excel

© fCoder SIA Acerca de fCoder SIA | Mapa del sitio