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
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