项目场景:
在实际生产中需要将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)
{
COleVariant covOptional((long)DISP_E_PARAMNOTFOUND,VT_ERROR);
MyBook.ExportAsFixedFormat(0, COleVariant(strFile), 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
|