BCB运作发生 IsBound() @ d:\bcb\emuvcl\untilcls.h/4139

网友分享于:2015-09-23 16:51 发表在 C++ Builder
BCB运行发生 IsBound() @ d:\bcb\emuvcl\untilcls.h/4139
//专为DeclareAndBackDayRep提供批量导出
bool CustomExcelExport::ExportForDeclareAndBackDayRep(AnsiString& modeDir,XMLMode* pMode, TClientDataSet *pcds,TDateTime dtime,AnsiString& errmsg)
{
        Variant excelApp, workBook, workBook1, workBookDot, sheet, range;
        try
        { //调用Excel
                excelApp = Variant::CreateObject("Excel.Application");
                excelApp.OlePropertySet("Visible",(Variant)false); //the Excel Application is Visible
        }
        catch(Exception & E)
        {
            excelApp.OleFunction("Quit");
            errmsg=E.Message.c_str();
            return false;
        }
        catch(...)
        {
             excelApp.OleFunction("Quit");
             errmsg="程序不能调用Excel的功能,可能是本机未安装该软件。";
             return false;
        }

         try
        { //打开文档
            excelApp.OlePropertyGet("ErrorCheckingOptions").OlePropertySet("BackgroundChecking", false);
            /*打开模板*/
            AnsiString  dotName=modeDir+"\\"+pMode->GetReportMode();//模板地址=模板文件夹+模板文件名
            
            workBook = excelApp.OlePropertyGet("Workbooks").OleFunction("Add", dotName.c_str());
            excelApp.OlePropertySet("DisplayAlerts", false);
            /*生成需要保存的地址*/
            AnsiString saveFilePath=FormatModelSaveFile(pMode,dtime);
            workBook.OleProcedure("SaveAs", saveFilePath.c_str());
            sheet = workBook.OlePropertyGet("Sheets",1);
            sheet.OlePropertySet("Name", "Sheet1");

           ...省略部分赋值代码

           range = sheet.OlePropertyGet("UsedRange");
           AnsiString fundcodeandname=pMode->GetFundCode()+" "+pMode->GetFundname();
           if(!ReplaceCellValue(range,"[基金名称]",fundcodeandname,errmsg))
           {           
                workBook.OleProcedure("Close"); //关闭表格
                excelApp.OleFunction("Quit");
                return false;
           }
           AnsiString fulldate=Now().FormatString("YYYYMMDD");
           if(!ReplaceCellValue(range,"[清算日期]",fulldate,errmsg))
           {
                workBook.OleProcedure("Close"); //关闭表格
                excelApp.OleFunction("Quit");
                return false;
           }
           if(!ReplaceCellValue(range,"[制表日期]",fulldate,errmsg))
           {
                workBook.OleProcedure("Close"); //关闭表格
                excelApp.OleFunction("Quit");
                return false;
           }
           if(!ReplaceCellValue(range,"[基金净值]",fundValue,errmsg))
           {
                workBook.OleProcedure("Close"); //关闭表格
                excelApp.OleFunction("Quit");
                return false;
           }
 
           workBook.OleProcedure("Save");
           workBook.OleProcedure("Close"); //关闭表格
           
        }
        catch(Exception & E)
        {
             errmsg= E.Message.c_str();   
           workBook.OleProcedure("Save");
             workBook.OleProcedure("Close"); //关闭表格
             excelApp.OleFunction("Quit");
             return false;
        }
        catch(...)
        {
            errmsg= "导出到EXCEL失败。\r\n请确认本机已安装该EXCEL及关闭其它程序再试一次。"; 
           workBook.OleProcedure("Save");
            workBook.OleProcedure("Close"); //关闭表格
            excelApp.OleFunction("Quit");
            return false;
        }        
        excelApp.OleFunction("Quit");
        return true;
}

部分机器发生,一部分机器没有这个问题
------解决思路----------------------
workBook = excelApp.OlePropertyGet("Workbooks").OleFunction("Add", dotName.c_str());
改成:
workBook = excelApp.OlePropertyGet("Workbooks").OleFunction("Add", WideString(dotName));
推荐分类: C++ C语言 C++ Builder VB PB Ruby/Rails perl/python Erlang Go swift Verilog 编程 其他开发语言
推荐标签: php websocket input navicat finereport
相关文章
最新发表
热门推荐