以下代码来自winforms应用程序,该应用程序在按钮事件上打开业务对象6.5的实例,刷新报表,然后将报表中的数据转储到csv文件中,然后退出业务对象实例。
我第一次运行代码时效果很好,但是如果我再次运行它会在行上出现异常
boApp.LoginAs(userName, Password, false, null);
引发的异常是“无效对象”。
我认为这是因为boApp没有被重新初始化,而且我缺乏关于静态类的知识。
调用方法是:
BO_Control.RefreshBusinessObjects(boReportsFolder, boExportsFolder, boReportName, exportFileName, startDate, endDate);
这是BO_Control类
static class BO_Control
{
static busobj.Application boApp = new busobj.Application();
static busobj.Document testDoc;
public static void RefreshBusinessObjects(string reportFolder, string exportFolder ,string boReportName, string exportFileName, string startDate, string endDate)
{
DateTime BoStart = DateTime.Now;
boApp.LoginAs(userName, Password, false, null);
boApp.Interactive = false;
boApp.Visible = false;
GetData(reportFolder, boReportName, startDate, endDate);
ExportData(exportFolder, exportFileName);
Console.WriteLine("BO_Export took {0} seconds.", DateTime.Now.Subtract(BoStart));
boApp.Quit();
}
static busobj.Document GetData(string reportFolder, string reportName, string startDate, string endDate)
{
Console.WriteLine(reportFolder + reportName);
testDoc = (busobj.Document)boApp.Documents.Open(reportFolder + reportName, true, false, null, null);
//Report Start Date
testDoc.Variables[1].Value = startDate;
//Report End Date
testDoc.Variables[2].Value = endDate;
//Area. Needs to be a semi-colon delimited string
testDoc.Variables[3].Value = "L;B;H;";
testDoc.Refresh();
return testDoc;
}
static void ExportData(string exportFolder, string exportFileName)
{
testDoc.Reports.get_Item(1).ExportAsText(exportFolder + exportFileName);
//2 = DoNotSaveChanges
testDoc.Close(2);
}
}
答案 0 :(得分:0)
我将BOApp的实例化移动到了RefreshBusinessObjects方法中,似乎可以解决这个问题
答案 1 :(得分:0)
我也使用这个登录代码,它可以工作,但是需要点击BO登录diaglog的OK按钮。是否有一些方法可以跳过此单击按钮步骤?