EDN Admin
Well-known member
Hi,
My application should write data into template excel file and save it under a new name in excel format. Problem is, it will be used on PCs with different versions of Excel (2000 - 2010). What is the procedure? Is it possible to do?
First application was builded in MFC, and now is imported to C++ Microsoft Visual Studio 2010.
Next code (old one) is depend of the instaled Excel version ...
// Microsoft Office 2000<br/>
#import "C
rogram FilesMicrosoft OfficeOfficeMSO9.DLL"<br/>
#import "C
rogram FilesCommon FilesMicrosoft SharedVBAVBA6VBE6EXT.OLB"<br/>
#import "C
rogram FilesMicrosoft OfficeOfficeEXCEL9.OLB" rename("DialogBox","_DialogBox") rename("RGB","_RGB") exclude("IFont","IPicture")
HRESULT hr = ::OleInitialize(NULL); <br/>
_ASSERT(SUCCEEDED(hr)); <br/>
CString strTmpl = _T("templete.xlt");
Excel::_WorkbookPtr ptrWrkBook = ptrExclApp->Workbooks->Open(strTmpl.AllocSysString()); <br/>
Excel::_WorksheetPtr data = ptrWrkBook->Sheets->Item[1];<br/>
<br/>
GetDlgItemText(IDC_ACT_SN, str);<br/>
COleVariant oleVar(str);<br/>
data->Cells->Item[7][6]=oleVar;
...
COleVariant cesta(fileName);<br/>
ptrWrkBook->SaveAs(cesta, Excel::XlFileFormat::xlExcel9795, "", "", false, false, Excel::XlSaveAsAccessMode::xlExclusive );<br/>
ptrExclApp->Quit();
::OleUninitialize();
Thanks ...
View the full article
My application should write data into template excel file and save it under a new name in excel format. Problem is, it will be used on PCs with different versions of Excel (2000 - 2010). What is the procedure? Is it possible to do?
First application was builded in MFC, and now is imported to C++ Microsoft Visual Studio 2010.
Next code (old one) is depend of the instaled Excel version ...
// Microsoft Office 2000<br/>
#import "C

#import "C

#import "C

HRESULT hr = ::OleInitialize(NULL); <br/>
_ASSERT(SUCCEEDED(hr)); <br/>
CString strTmpl = _T("templete.xlt");
Excel::_WorkbookPtr ptrWrkBook = ptrExclApp->Workbooks->Open(strTmpl.AllocSysString()); <br/>
Excel::_WorksheetPtr data = ptrWrkBook->Sheets->Item[1];<br/>
<br/>
GetDlgItemText(IDC_ACT_SN, str);<br/>
COleVariant oleVar(str);<br/>
data->Cells->Item[7][6]=oleVar;
...
COleVariant cesta(fileName);<br/>
ptrWrkBook->SaveAs(cesta, Excel::XlFileFormat::xlExcel9795, "", "", false, false, Excel::XlSaveAsAccessMode::xlExclusive );<br/>
ptrExclApp->Quit();
::OleUninitialize();
Thanks ...
View the full article