 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
siraj Guest
|
Posted: Fri Oct 29, 2004 4:07 pm Post subject: Excel automation problems. |
|
|
Hi!
I have and application in c++ builder 5 with access 2000 as the database. I
need to export data to excel from access.
In my application, I can not only read the access database but can also
create access database. I have imported the" microsoft ADO ext 2.6 library
for dll and security" and use ADOX_Catalog component derived from it to
create access.
On my form I have
DBchart,DBGrid,Listbox,button,ADOQuery,ADOX_Catalog,Session components.
For exporting to excel (method 1)
-----------------------
1) I used the following code
my_excel = Variant::CreateObject("excel.application");
my_excel.OlePropertySet("Visible",(Variant)true);
Variant all_workbooks;
Variant my_workbook;
Variant my_worksheet;
Variant all_worksheets;
//-- Get workbooks collection
all_workbooks = my_excel.OlePropertyGet("Workbooks");
//-- Set number of worksheets to 1
my_excel.OlePropertySet("SheetsInNewWorkbook",(Variant)10);
//-- Create a new workbook
my_workbook = all_workbooks.OleFunction("Add");
Procedure SaveAs("SaveAs");
................................
When I compile, I get the error "Ambiguity between Procedure and
System::Procedure."
This error came up only after I added the ADOX_Catalog control to
the form. Do not know how to solve it.
2) If I remove the line "Procedure SaveAs("SaveAs");" and the code
below it, the project compiles. But I have an access violation when
the line "my_excel.OlePropertySet("Visible",(Variant)true);" is executed.
I was able to createObject of excel application but cannot see it.
what can be the reason???
If I replace the line
"my_excel.OlePropertySet("Visible",(Variant)true);" with
PropertySet Visible("Visible");
my_excel.Exec(Visible << value);
There is no access violation. Do not know why???.
I cannot solve the problem of "Ambiguity between Procedure and
System::Procedure."
So I went for method 2.
For exporting to excel (method 2)
-----------------------------------
I used TExcelApplication,TExcelWorkbook,TExcelWorksheet,TExcelChart.
The Process "Excel.exe" remains in the task manager even the excel
application is disconnected.
I tried to make it work for more than 3 days. but no breakthrough.
Please help.
Regrads,
Siraj
|
|
| Back to top |
|
 |
Max Wright Guest
|
Posted: Fri Oct 29, 2004 11:25 pm Post subject: Re: Excel automation problems. |
|
|
In message <41826aa9 (AT) newsgroups (DOT) borland.com>, siraj
<siraj.sm (AT) omnisens (DOT) ch> writes
| Quote: | Hi!
I have and application in c++ builder 5 with access 2000 as the database. I
need to export data to excel from access.
In my application, I can not only read the access database but can also
create access database. I have imported the" microsoft ADO ext 2.6 library
for dll and security" and use ADOX_Catalog component derived from it to
create access.
On my form I have
DBchart,DBGrid,Listbox,button,ADOQuery,ADOX_Catalog,Session components.
For exporting to excel (method 1)
-----------------------
1) I used the following code
my_excel = Variant::CreateObject("excel.application");
my_excel.OlePropertySet("Visible",(Variant)true);
Variant all_workbooks;
Variant my_workbook;
Variant my_worksheet;
Variant all_worksheets;
//-- Get workbooks collection
all_workbooks = my_excel.OlePropertyGet("Workbooks");
//-- Set number of worksheets to 1
my_excel.OlePropertySet("SheetsInNewWorkbook",(Variant)10);
//-- Create a new workbook
my_workbook = all_workbooks.OleFunction("Add");
Procedure SaveAs("SaveAs");
................................
When I compile, I get the error "Ambiguity between Procedure and
System::Procedure."
This error came up only after I added the ADOX_Catalog control to
the form. Do not know how to solve it.
2) If I remove the line "Procedure SaveAs("SaveAs");" and the code
below it, the project compiles. But I have an access violation when
the line "my_excel.OlePropertySet("Visible",(Variant)true);" is executed.
I was able to createObject of excel application but cannot see it.
what can be the reason???
If I replace the line
"my_excel.OlePropertySet("Visible",(Variant)true);" with
PropertySet Visible("Visible");
my_excel.Exec(Visible << value);
There is no access violation. Do not know why???.
I cannot solve the problem of "Ambiguity between Procedure and
System::Procedure."
So I went for method 2.
For exporting to excel (method 2)
-----------------------------------
I used TExcelApplication,TExcelWorkbook,TExcelWorksheet,TExcelChart.
The Process "Excel.exe" remains in the task manager even the excel
application is disconnected.
I tried to make it work for more than 3 days. but no breakthrough.
Please help.
Regrads,
Siraj
Hi Siraj - |
This kind of code works fine for me with Excel (Builder 4):
#include
#include <comobj.hpp>
// global variable:
Variant XL;
// then, in procedures:
XL = XL.CreateObject("Excel.Application");
XL.OlePropertyGet("Workbooks").OleProcedure("Open", oldfnm);
XL.OlePropertySet("Visible", true);
// make some changes and save under different name
XL.OlePropertyGet("ActiveWorkbook").OleProcedure("SaveAs", newfnm);
oldfnm and newfnm are plain C char strings. I don't know what you are
trying to do with your "SaveAs" line - it doesn't look like a C++
statement to me!
I've heard that Excel doesn't always shut down correctly. I find that
XL.OleProcedure("Quit");
does indeed leave Excel still running in the background, presumably
because XL still holds a reference to the automation object. To
completely remove Excel I do
XL.Clear();
or simply quit my application.
I have no idea whether this is the best way to automate Excel, but it
seems to work!
- Max Wright
|
|
| Back to top |
|
 |
Kasper Larsen Guest
|
Posted: Tue Nov 02, 2004 8:21 pm Post subject: Re: Excel automation problems. |
|
|
"siraj" <siraj.sm (AT) omnisens (DOT) ch> skrev i en meddelelse
news:41826aa9 (AT) newsgroups (DOT) borland.com...
| Quote: | Hi!
I have and application in c++ builder 5 with access 2000 as the database.
I
need to export data to excel from access.
In my application, I can not only read the access database but can also
create access database. I have imported the" microsoft ADO ext 2.6 library
for dll and security" and use ADOX_Catalog component derived from it to
create access.
On my form I have
DBchart,DBGrid,Listbox,button,ADOQuery,ADOX_Catalog,Session components.
For exporting to excel (method 1)
-----------------------
I have collected some of the best samples of Excel integration at : |
http://www.seedwiki.com/page.cfm?doc=Borland%20C%20Plus%20Plus%20Builder%20and%20MS%20Excel&wikiid=4861
Kasper
|
|
| Back to top |
|
 |
siraj Guest
|
Posted: Thu Nov 04, 2004 5:24 pm Post subject: Re: Excel automation problems. |
|
|
Thanks Max Wright, You helped in solving the termination of excel
application.
I have problems making controls imported from "microsoft ADO ext 2.6 library
for dll and security" and the OLE Automation of excel work together on the
same application.
OLE automation of excel works only if the application does not have controls
imported from "microsoft ADO ext 2.6 library
for dll and security" . when both of them are present in the application,
when I compile, I get the error
"Ambiguity between Procedure and System::Procedure."
To solve this problem, i have created a dll that contains excel automation
functions. From my application,I call the functions in this dll
to export data to excel. I do not know if it is the perfect solution.
siraj
"Max Wright" <maxwright (AT) wys-systems (DOT) demon.co.uk> a écrit dans le message de
news:T0J74YPNFtgBFwPu (AT) wys-systems (DOT) demon.co.uk...
| Quote: | In message <41826aa9 (AT) newsgroups (DOT) borland.com>, siraj
[email]siraj.sm (AT) omnisens (DOT) ch[/email]> writes
Hi!
I have and application in c++ builder 5 with access 2000 as the database.
I
need to export data to excel from access.
In my application, I can not only read the access database but can also
create access database. I have imported the" microsoft ADO ext 2.6
library
for dll and security" and use ADOX_Catalog component derived from it to
create access.
On my form I have
DBchart,DBGrid,Listbox,button,ADOQuery,ADOX_Catalog,Session components.
For exporting to excel (method 1)
-----------------------
1) I used the following code
my_excel = Variant::CreateObject("excel.application");
my_excel.OlePropertySet("Visible",(Variant)true);
Variant all_workbooks;
Variant my_workbook;
Variant my_worksheet;
Variant all_worksheets;
//-- Get workbooks collection
all_workbooks = my_excel.OlePropertyGet("Workbooks");
//-- Set number of worksheets to 1
my_excel.OlePropertySet("SheetsInNewWorkbook",(Variant)10);
//-- Create a new workbook
my_workbook = all_workbooks.OleFunction("Add");
Procedure SaveAs("SaveAs");
................................
When I compile, I get the error "Ambiguity between Procedure and
System::Procedure."
This error came up only after I added the ADOX_Catalog control to
the form. Do not know how to solve it.
2) If I remove the line "Procedure SaveAs("SaveAs");" and the code
below it, the project compiles. But I have an access violation when
the line "my_excel.OlePropertySet("Visible",(Variant)true);" is
executed.
I was able to createObject of excel application but cannot see
it.
what can be the reason???
If I replace the line
"my_excel.OlePropertySet("Visible",(Variant)true);" with
PropertySet Visible("Visible");
my_excel.Exec(Visible << value);
There is no access violation. Do not know why???.
I cannot solve the problem of "Ambiguity between Procedure and
System::Procedure."
So I went for method 2.
For exporting to excel (method 2)
-----------------------------------
I used TExcelApplication,TExcelWorkbook,TExcelWorksheet,TExcelChart.
The Process "Excel.exe" remains in the task manager even the excel
application is disconnected.
I tried to make it work for more than 3 days. but no breakthrough.
Please help.
Regrads,
Siraj
Hi Siraj -
This kind of code works fine for me with Excel (Builder 4):
#include
#include
// global variable:
Variant XL;
// then, in procedures:
XL = XL.CreateObject("Excel.Application");
XL.OlePropertyGet("Workbooks").OleProcedure("Open", oldfnm);
XL.OlePropertySet("Visible", true);
// make some changes and save under different name
XL.OlePropertyGet("ActiveWorkbook").OleProcedure("SaveAs", newfnm);
oldfnm and newfnm are plain C char strings. I don't know what you are
trying to do with your "SaveAs" line - it doesn't look like a C++
statement to me!
I've heard that Excel doesn't always shut down correctly. I find that
XL.OleProcedure("Quit");
does indeed leave Excel still running in the background, presumably
because XL still holds a reference to the automation object. To
completely remove Excel I do
XL.Clear();
or simply quit my application.
I have no idea whether this is the best way to automate Excel, but it
seems to work!
- Max Wright
|
|
|
| Back to top |
|
 |
Max Wright Guest
|
Posted: Sat Nov 06, 2004 9:47 am Post subject: Re: Excel automation problems. |
|
|
Hi Siraj
Not having used the ADO controls myself I can't offer any advice. And
perhaps you have already found the solution. But what I don't
understand is why you are using the
Procedure SaveAs("SaveAs");
type of syntax (which I've never seen before) rather than something
along the lines of
XL.OlePropertyGet("ActiveWorkbook").OleProcedure("SaveAs", newfnm);
- presumably if you do that you won't get the naming conflicts you're
reporting.
- Max Wright
In message <418a65e8 (AT) newsgroups (DOT) borland.com>, siraj
<siraj.sm (AT) omnisens (DOT) ch> writes
| Quote: | Thanks Max Wright, You helped in solving the termination of excel
application.
I have problems making controls imported from "microsoft ADO ext 2.6 library
for dll and security" and the OLE Automation of excel work together on the
same application.
OLE automation of excel works only if the application does not have controls
imported from "microsoft ADO ext 2.6 library
for dll and security" . when both of them are present in the application,
when I compile, I get the error
"Ambiguity between Procedure and System::Procedure."
To solve this problem, i have created a dll that contains excel automation
functions. From my application,I call the functions in this dll
to export data to excel. I do not know if it is the perfect solution.
siraj
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|