Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

management of excel functions with visual c++

Status
Not open for further replies.

intermediate

Programmer
Nov 13, 2000
3
0
0
US
I'm working with visual c++ 6.0 , and I'm trying to use some excel's functions or macros that provides visual c++ 6.0 to access excel's cells ... but If I want use the funtion GetUsedRange doesn't work.
Besides when I select a range of cells with GetRange ..
How can I get each content of each cell? ..
How can I use GetValue,GetCells,GetColumn,GetRow?

Maybe these are many questions, but a lot of information about excel macros is oriented to visual basic and majority of source code is visual basic..
I hope your answer quickly.
Thank you.
 
I`m interesting what tools you use? I have some similar problem - I need make a *.xls converter to *.xml, but I can`t find modules or methods how to do that. Actually I need some modules or methods how to read *.xls files in Visual C++.
Can you help me?
 
Well, I've been trying to read a range of cells, using the function GetRange, and then using GetValue.
First a use GetRange with only one parameter, the cell that I want to get.
Example
_Application m_ExcelOn;


COleVariant vOpt(DISP_E_PARAMNOTFOUND, VT_ERROR);
if (!m_bExcelStarted)
if (m_ExcelOn.CreateDispatch("Excel.Application"))
m_bExcelStarted=true;

Workbooks oBooks = m_ExcelOn.GetWorkbooks();
_Workbook oBook = oBooks.Add(vOpt);
Worksheets oSheets = oBook.GetWorksheets();
_Worksheet oSheet = oSheets.GetItem(COleVariant((short)1));
VARIANT l_cell;
COleVariant l_cell1;
CString var;
oBooks.Open("FileName.xls",vOpt,COleVariant((short)true),vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt);
Range oRange;

oRange = m_ExcelOn.GetRange(COleVariant("A1"),vOpt);
oRange = oSheet.GetUsedRange();
l_cell=oRange.GetValue();
l_cell1.ChangeType(VT_BSTR,(COleVariant *)&l_cell);
var = l_cell1.bstrVal;
AfxMessageBox(var, MB_OK | MB_ICONINFORMATION);

This procedure has a disadvantage, you only can read one cell.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top