bbg
2005-09-11 23:27:19 UTC
I like to get some help from Excel-automation-experienced guys:
I started from article http://support.microsoft.com/kb/186122/ which shows
how to open, read some contents, close excel file in MFC.
I copied codes from article and pasted to OnInitDialog() with slight
modification. Every time I click button, it opens, reads, displays Excel
file contents in poped-up dialog, then when OK button clicked, it closes
Excel file and application. It seems works and I have two problems here(I am
using VC++6.0, win2000, excel 2000):
1. Too slow.. about 8 seconds after button clicked, 'Server Busy' message
box poped-up. It provides two button 'SwitchTo' and 'Retry'. I always need
to click 'Retry' button to proceed. What am I doing wrong here?
BOOL CMyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// ...............
_Application objApp;
_Workbook objBook;
Workbooks objBooks;
// Instantiate Excel and open an existing workbook.......... it takes
too long???
objApp.CreateDispatch("Excel.Application");
objBooks = objApp.GetWorkbooks();
objBook = objBooks.Open("C:\\Work\\Test.xls",
VOptional, VOptional, VOptional, VOptional,
VOptional, VOptional, VOptional, VOptional,
VOptional, VOptional, VOptional, VOptional);
// read, fill, find, whatever .......
//Close the workbook without saving changes
//and quit Microsoft Excel.
objBook.Close(COleVariant((short)FALSE), VOptional, VOptional);
objApp.Quit();
2. Can I start and quit Excel application in main frame rather than in my
dialog's OnInitDialog() so that multiple parts of my program can play with
Excel file? What I have tried was make _Application objApp, _Workbook
objBook, Workbooks objBooks as global variable and the debugger is giving
errors:
First-chance exception in Medisafe.exe (OLE32.DLL): 0xC0000005:
Access Violation.
Thanks in advance
Bob
I started from article http://support.microsoft.com/kb/186122/ which shows
how to open, read some contents, close excel file in MFC.
I copied codes from article and pasted to OnInitDialog() with slight
modification. Every time I click button, it opens, reads, displays Excel
file contents in poped-up dialog, then when OK button clicked, it closes
Excel file and application. It seems works and I have two problems here(I am
using VC++6.0, win2000, excel 2000):
1. Too slow.. about 8 seconds after button clicked, 'Server Busy' message
box poped-up. It provides two button 'SwitchTo' and 'Retry'. I always need
to click 'Retry' button to proceed. What am I doing wrong here?
BOOL CMyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// ...............
_Application objApp;
_Workbook objBook;
Workbooks objBooks;
// Instantiate Excel and open an existing workbook.......... it takes
too long???
objApp.CreateDispatch("Excel.Application");
objBooks = objApp.GetWorkbooks();
objBook = objBooks.Open("C:\\Work\\Test.xls",
VOptional, VOptional, VOptional, VOptional,
VOptional, VOptional, VOptional, VOptional,
VOptional, VOptional, VOptional, VOptional);
// read, fill, find, whatever .......
//Close the workbook without saving changes
//and quit Microsoft Excel.
objBook.Close(COleVariant((short)FALSE), VOptional, VOptional);
objApp.Quit();
2. Can I start and quit Excel application in main frame rather than in my
dialog's OnInitDialog() so that multiple parts of my program can play with
Excel file? What I have tried was make _Application objApp, _Workbook
objBook, Workbooks objBooks as global variable and the debugger is giving
errors:
First-chance exception in Medisafe.exe (OLE32.DLL): 0xC0000005:
Access Violation.
Thanks in advance
Bob