bcb使用ole打开excel设置打印属性速度很慢,求解。该怎么处理
bcb使用ole打开excel设置打印属性速度很慢,求解。
设置直到预览窗口打开需要8秒左右的时间,太慢了。
想请教下,有没有什么优化的方法,还是我使用方法不对。
代码
------解决方案--------------------
OLE本身速度就慢,以上代码再优化也快不到哪里了.
------解决方案--------------------
不知道为什么,我们经理做的导出很快,我做的导出有一段等待时间.代码我比较过了,差不多.
很是奇怪.
用他的代码,我这边编绎也会慢.
设置直到预览窗口打开需要8秒左右的时间,太慢了。
想请教下,有没有什么优化的方法,还是我使用方法不对。
代码
- C/C++ code
Variant Ex, wb; try { Ex = Variant::CreateObject("Excel.Application"); } catch(...) { Application->MessageBox(L"电脑中没有安装Excel,无法使用Excel打印", L"错误", MB_ICONSTOP | MB_OK); return; } try { DWORD dwStart = GetTickCount(); Ex.OlePropertyGet("Workbooks").OleProcedure("Open", AnsiString(strExcelPath).c_str(),0,true); Ex.OlePropertySet("DisplayAlerts", false); // wb = Ex.OlePropertyGet("ActiveWorkBook").OlePropertyGet("ActiveSheet"); wb = Ex.OlePropertyGet("ActiveSheet"); wb.OlePropertyGet("PageSetup").OlePropertySet("PrintArea", AnsiString(strArea).c_str()); wb.OlePropertyGet("PageSetup").OlePropertySet("BlackAndWhite", true); wb.OlePropertyGet("PageSetup").OlePropertySet("PaperSize", 9); wb.OlePropertyGet("PageSetup").OlePropertySet("Zoom", false); // 1纵向,2横向 wb.OlePropertyGet("PageSetup").OlePropertySet("Orientation", Orientation); wb.OlePropertyGet("PageSetup").OlePropertySet("CenterHorizontally", true); wb.OlePropertyGet("PageSetup").OlePropertySet("CenterVertically", false); wb.OlePropertyGet("PageSetup").OlePropertySet("FitToPagesWide", 1); wb.OlePropertyGet("PageSetup").OlePropertySet("FitToPagesTall", 1); wb.OlePropertyGet("PageSetup").OlePropertySet("LeftMargin", 0.3); wb.OlePropertyGet("PageSetup").OlePropertySet("RightMargin", 0.3); wb.OlePropertyGet("PageSetup").OlePropertySet("TopMargin", 0.3); wb.OlePropertyGet("PageSetup").OlePropertySet("BottomMargin", 0.3); wb.OlePropertyGet("PageSetup").OlePropertySet("HeaderMargin", 0.3); wb.OlePropertyGet("PageSetup").OlePropertySet("FooterMargin", 0.3); MainFrm->WriteMemoInfo_sb(String(GetTickCount() - dwStart)); Ex.OlePropertySet("Visible", (Variant)true); wb.OleFunction("PrintPreview",true); // wb.OleFunction("PrintOut"); Ex.OleFunction("Quit"); // 退出Excel // quit // Ex.OleFunction("Quit"); } catch(...) { // return; } Ex.OleFunction("Quit");
------解决方案--------------------
OLE本身速度就慢,以上代码再优化也快不到哪里了.
------解决方案--------------------
不知道为什么,我们经理做的导出很快,我做的导出有一段等待时间.代码我比较过了,差不多.
很是奇怪.
用他的代码,我这边编绎也会慢.