vc Excel导出PDF

vc Excel导出PDF,第1张

项目场景:

在实际生产中需要将Excel中的sheet转成PDF。



问题描述

查询VBA和C#都有比较简单的函数ExportAsFixedFormat来处理,但是Vc中没有这么方便方法。


主要是由于我的excel9.h中没有这个函数的申明和实现,故而需要将申明和实现放到excel9中。



解决方案: 先处理Excel 在excel9.h中添加申明
void ExportAsFixedFormat(long Type, const VARIANT& Filename, const VARIANT& Quality, const 
VARIANT& IncludeDocProperties, const VARIANT& IgnorePrintAreas, const VARIANT& From, const 
VARIANT& To, const VARIANT& OpenAfterPublish, 

                       const VARIANT& FixedFormatExtClassPtr);


在excel9.cpp中添加实现
void _Workbook::ExportAsFixedFormat(long Type, const VARIANT& Filename, const VARIANT& 
Quality, const VARIANT& IncludeDocProperties, const VARIANT& IgnorePrintAreas, const 
VARIANT& From, const VARIANT& To, const VARIANT& OpenAfterPublish, const VARIANT& 
FixedFormatExtClassPtr)

        {

               static BYTE parms[] =

                       VTS_I4 VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT 
VTS_VARIANT VTS_VARIANT VTS_VARIANT;

               InvokeHelper(0x9bd, DISPATCH_METHOD, VT_EMPTY, NULL, parms,

                       Type, &Filename, &Quality, &IncludeDocProperties, 
&IgnorePrintAreas, &From, &To, &OpenAfterPublish, &FixedFormatExtClassPtr);

        }


在调用函数中处理实现
void CMyExcel::ExcelToPdf(CString strFile)

{

        //导出Book里的所有sheet

        COleVariant covOptional((long)DISP_E_PARAMNOTFOUND,VT_ERROR); 

        MyBook.ExportAsFixedFormat(0, COleVariant(strFile), covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional);

        //只导出当前sheet

        //ExcelSheet.ExportAsFixedFormat(0, COleVariant(ExcalPath), covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional);

}


其它的一些实现也放置在这里

后续有需要再使用


void _Worksheet::ExportAsFixedFormat(long Type, const VARIANT& Filename, const VARIANT& Quality, const VARIANT& IncludeDocProperties, const VARIANT& IgnorePrintAreas, const VARIANT& From, const VARIANT& To, const VARIANT& OpenAfterPublish,



const VARIANT& FixedFormatExtClassPtr)



{



static BYTE parms[] =



VTS_I4 VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT;



InvokeHelper(0x9bd, DISPATCH_METHOD, VT_EMPTY, NULL, parms,



Type, &Filename, &Quality, &IncludeDocProperties, &IgnorePrintAreas, &From, &To, &OpenAfterPublish, &FixedFormatExtClassPtr);



}




void Range::ExportAsFixedFormat(long Type, const VARIANT& Filename, const VARIANT& Quality, const VARIANT& IncludeDocProperties, const VARIANT& IgnorePrintAreas, const VARIANT& From, const VARIANT& To, const VARIANT& OpenAfterPublish,



const VARIANT& FixedFormatExtClassPtr)



{



static BYTE parms[] =



VTS_I4 VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT;



InvokeHelper(0x9bd, DISPATCH_METHOD, VT_EMPTY, NULL, parms,



Type, &Filename, &Quality, &IncludeDocProperties, &IgnorePrintAreas, &From, &To, &OpenAfterPublish, &FixedFormatExtClassPtr);



}



参考资料
https://blog.csdn.net/g710710/article/details/7206573
https://www.cnblogs.com/nxopen2018/p/11055161.html

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/577706.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-11
下一篇 2022-04-11

发表评论

登录后才能评论

评论列表(0条)

保存