Newbie - getting value from excel cel

Discussion in 'C++' started by Nita, Dec 22, 2005.

  1. Nita

    Nita Guest

    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
     
    Nita, Dec 22, 2005
    #1
    1. Advertising

  2. Nita

    Guest

    Nita wrote:
    > 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
     
    , Dec 22, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=

    dynamicly add link button to calendar cel

    =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=, May 11, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    6,343
    Karl Seguin
    May 13, 2005
  2. =?Utf-8?B?Q2hyaXM=?=
    Replies:
    1
    Views:
    8,098
    Chris Botha
    Sep 1, 2005
  3. =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=

    Problem with Excel reports ::::Excel 2003 Migration To Excel 2007

    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=, Oct 5, 2007, in forum: ASP .Net
    Replies:
    15
    Views:
    1,604
    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=
    Oct 24, 2007
  4. Tim Fröglich

    Getting ID, calling url, search for value, return value

    Tim Fröglich, Jan 7, 2006, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    155
    Josh Twist
    Jan 10, 2006
  5. Diego Virasoro
    Replies:
    7
    Views:
    100
    Choi, Junegunn
    Feb 16, 2009
Loading...

Share This Page