Newbie - getting value from excel cel

N

Nita

As the title suggests I have a problem, and also I'm new to the world
of C++. I have previously done some java so have a little idea, but am
having problems still, which is not surprising.

The problem I am having is when trying to access a cell in an excel
spreadsheet, it counts the rows in the spreadsheet fine, so it connects
to it, but when trying to access the data in the cell it gives me a
inft != 0 error, I have no idea what this means and can't seem to find
a simple problem on google. Now I'm takng this code from a working
program and apparently it works, can someone poin me in the right
direction please.

here is the code:

AnsiString fileName, row0rd, col0rd, strVal;
Excel_97::RangePtr DataField;
Variant vValues; int WSNum = 0, rowCount = 1, excelRow;
// Testing fileName = "C:\\test.xls";

try {
EApp->Connect();
EApp->set_Visible(0,false);
EApp->Workbooks->Open((TVariant) fileName,
TNoParam(),(TVariant)TOLEBOOL(true));
EWBook->ConnectTo(EApp->ActiveWorkbook);
// Set the worksheet to 1 for testing to make sure it's connecting to
the excel app
WSNum = 1;
EWSheet->ConnectTo(EWBook->Worksheets->get_Item((TVariant) WSNum));
// Count the rows from the worksheet
rowCount = EWSheet->UsedRange[TDefLCID()]->Rows->Count;
// Iterate throught the rows in the excel file
row0rd = 1;
col0rd = 0;
for(excelRow = 0;excelRow<=rowCount;excelRow++) {
try {
//EWSheet->ConnectTo(EWBook->Worksheets->get_Item((TVariant) WSNum));
DataField = EWSheet->Cells->get_Item((TVariant) row0rd,(TVariant)
col0rd);
vValues = DataField->get_Text();
strVal = vValues;
}
catch(Exception &E) {
// Some error occured
}


The line that it gets the error on, is vValues = DataField->get_Text();

TIA for any help
 
D

deane_gavin

Nita said:
As the title suggests I have a problem, and also I'm new to the world
of C++. I have previously done some java so have a little idea, but am
having problems still, which is not surprising.

The problem I am having is when trying to access a cell in an excel
spreadsheet, it counts the rows in the spreadsheet fine, so it connects
to it, but when trying to access the data in the cell it gives me a
inft != 0 error, I have no idea what this means and can't seem to find
a simple problem on google. Now I'm takng this code from a working
program and apparently it works, can someone poin me in the right
direction please.

here is the code:

AnsiString fileName, row0rd, col0rd, strVal;
Excel_97::RangePtr DataField;
Variant vValues; int WSNum = 0, rowCount = 1, excelRow;
// Testing fileName = "C:\\test.xls";

try {
EApp->Connect();
EApp->set_Visible(0,false);
EApp->Workbooks->Open((TVariant) fileName,
TNoParam(),(TVariant)TOLEBOOL(true));
EWBook->ConnectTo(EApp->ActiveWorkbook);
// Set the worksheet to 1 for testing to make sure it's connecting to
the excel app
WSNum = 1;
EWSheet->ConnectTo(EWBook->Worksheets->get_Item((TVariant) WSNum));
// Count the rows from the worksheet
rowCount = EWSheet->UsedRange[TDefLCID()]->Rows->Count;
// Iterate throught the rows in the excel file
row0rd = 1;
col0rd = 0;
for(excelRow = 0;excelRow<=rowCount;excelRow++) {
try {
//EWSheet->ConnectTo(EWBook->Worksheets->get_Item((TVariant) WSNum));
DataField = EWSheet->Cells->get_Item((TVariant) row0rd,(TVariant)
col0rd);
vValues = DataField->get_Text();
strVal = vValues;
}
catch(Exception &E) {
// Some error occured
}


The line that it gets the error on, is vValues = DataField->get_Text();

TIA for any help

Unfortunately what you have here isn't a C++ language question, so it's
off-topic. You have a problem with whatever third party library you are
using to interface with Excel. You should ask a forum dedicated to that
library if there is one, or perhaps a microsoft or windows programming
group. The purpose of comp.lang.c++ is explained here, along with some
suggestions for other newsgroups.

http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9

Gavin Deane
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top