anto80
August 5th, 2005, 05:19 AM
Hello all,
I am using Crystal Reports 9 RDC with Visual C++ 6, and i have set the database source for my Report to an Excel file.
Like this :
/* global variables :
IApplicationPtr m_pApplication;
IReportPtr m_pReport;
*/
CString m_strParsingFile = "c:\ExcelFile.xls";
int i;
m_pApplication.CreateInstance("CrystalRuntime.Application.9");
m_pReport = m_pApplication->OpenReport(_bstr_t("c:\report1.rpt"), variant_t((long)1));
/*--- every table logon to the new DB, including 'command' fields ---*/
i = m_pReport->GetDatabase()->GetTables()->GetCount();
while (i >= 1)
{
m_pReport->GetDatabase()->GetTables()->GetItem(i)->SetLogOnInfo(
_bstr_t(m_strParsingFile),
_bstr_t(m_strParsingFile),
vtMissing,
vtMissing);
m_pReport->GetDatabase()->GetTables()->GetItem(i)->Location = _bstr_t(m_strParsingFile);
vBool = m_pReport->GetDatabase()->GetTables()->GetItem(i)->TestConnectivity();
if (vBool == 0)
{
AfxMessageBox("TestConnectivity failed");
}
i--;
}
/*
some other things ....
*/
m_pReport.Release();
m_pReport = NULL;
m_pApplication.Release();
m_pApplication = NULL;
All is working fine (i can access to the values contained in Excel file...) but the problem is that the EXCEL FILE is still locked after releasing the report and the Application.
The excel file becomes unlocked only when my program executable is terminated.
Is there one more thing i have to do so that my Excel file can become usable again (ie: renamed, moved by code...)
Thanks in advance to you all.
I am using Crystal Reports 9 RDC with Visual C++ 6, and i have set the database source for my Report to an Excel file.
Like this :
/* global variables :
IApplicationPtr m_pApplication;
IReportPtr m_pReport;
*/
CString m_strParsingFile = "c:\ExcelFile.xls";
int i;
m_pApplication.CreateInstance("CrystalRuntime.Application.9");
m_pReport = m_pApplication->OpenReport(_bstr_t("c:\report1.rpt"), variant_t((long)1));
/*--- every table logon to the new DB, including 'command' fields ---*/
i = m_pReport->GetDatabase()->GetTables()->GetCount();
while (i >= 1)
{
m_pReport->GetDatabase()->GetTables()->GetItem(i)->SetLogOnInfo(
_bstr_t(m_strParsingFile),
_bstr_t(m_strParsingFile),
vtMissing,
vtMissing);
m_pReport->GetDatabase()->GetTables()->GetItem(i)->Location = _bstr_t(m_strParsingFile);
vBool = m_pReport->GetDatabase()->GetTables()->GetItem(i)->TestConnectivity();
if (vBool == 0)
{
AfxMessageBox("TestConnectivity failed");
}
i--;
}
/*
some other things ....
*/
m_pReport.Release();
m_pReport = NULL;
m_pApplication.Release();
m_pApplication = NULL;
All is working fine (i can access to the values contained in Excel file...) but the problem is that the EXCEL FILE is still locked after releasing the report and the Application.
The excel file becomes unlocked only when my program executable is terminated.
Is there one more thing i have to do so that my Excel file can become usable again (ie: renamed, moved by code...)
Thanks in advance to you all.