VC printing word excel text file method

  • 2020-04-02 02:56:19
  • OfStack

This article illustrates how to print word and excel text files in VC. Share with you for your reference. The specific implementation method is as follows:

1. Vc printing Excel:

There is a lot of information about how to open an excel with a VC, usually using the OLE Avtive Control/ hypothesis when you open an excel file and get its
Workbook handle, the corresponding interface is:

COleVariant covTrue((short)true);
COleVariant covFalse((short)FALSE);
COleVariant covOptional( (long)DISP_E_PARAMNOTFOUND, VT_ERROR);
_workbook objbook;
.....
objBook.PrintOut( covOptional,
    covOptional,
    COleVariant(long(1)),     //Print copies
    covFalse,
    covOptional,
    covOptional,
    covOptional
    ,covOptional
);

For the specific meanings of other parameters, please refer to MSDN.

2. VC prints word

The print interface of Word is:

_Document::PrintOut( covFalse, 
  covOptional,
  covOptional,
  covOptional,
  covOptional,
  covOptional,
  covOptional,
  COleVariant((long)1),  //Print pages
  covOptional,
  covOptional,
  covOptional,
  covOptional,
  covOptional,
  covOptional,
  covOptional,
  covOptional,
  covOptional,
  covOptional
);

The meaning of the parameter can be seen in MSDN.

3. VC printing Excel:

Call the print function of the shell:

ShellExecute(NULL,"print","c://temp//test.txt",NULL,NULL,SW_HIDE);

It is important to note that a printer is already installed on the machine. The printout is sent to the default printer. In addition, shellExcute can be used to print excel and word, just replace the corresponding file names.
ShellExecute(NULL,"print","c://temp//test.xls",NULL,NULL,SW_HIDE);
ShellExecute(NULL,"print","c://temp//test.doc",NULL,NULL,SW_HIDE);

Hope that this article described the VC programming for you to help.


Related articles: