| |

VerySource

 Forgot password?
 Register
Search
View: 706|Reply: 2

A problem with vc reading excel?

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-14 10:00:01
| Show all posts |Read mode
void CMaintestDlg :: OnBtnRt ()
{
// TODO: Add your control notification handler code here
UpdateData (TRUE);
if (! objApp.CreateDispatch ("Excel.Application"))
{
              AfxMessageBox ("Failed to create Excel service!");
               return;
}
Ranch
Ranch
    COleVariant vResult;
        COleVariant
        covTrue ((short) TRUE),
        covFalse ((short) FALSE),
        covOptional ((long) DISP_E_PARAMNOTFOUND, VT_ERROR);
    objBooks.AttachDispatch (objApp.GetWorkbooks (), true);
    objBook.AttachDispatch (objBooks.Open ("e:\\x.xls",
   covOptional, covOptional, covOptional, covOptional, covOptional,
   covOptional, covOptional, covOptional, covOptional, covOptional,
   covOptional, covOptional, covOptional, covOptional));
    // Get Worksheets
    objSheets.AttachDispatch (objBook.GetWorksheets (), true);
    // Get sheet1
    objSheet.AttachDispatch (objSheets.GetItem (_variant_t ("Sheet1")), true);
    // Get all Cells, at this time, objSheet is a collection of cells
     bjRange.AttachDispatch (objSheet.GetCells (), true);
    VARIANT vs = objRange.GetItem (_variant_t ((long) 1), _ variant_t ((long2));
    m_rt1 = vs.dblVal; // m_rt1 is a variable of the dialog class, doule type
Ransom
    UpdateData (FALSE);
    objRange.ReleaseDispatch ();
    objSheet.ReleaseDispatch ();
    objSheets.ReleaseDispatch ();
    objBook.ReleaseDispatch ();
    objBooks.ReleaseDispatch ();
    objApp.ReleaseDispatch ();

After running, m_tr1 does not display the value of the second line and the second cell in sheet1 in the file e:\\x.xls.
Originally it was 303.2, the result showed 3.75064, and then clicked the button again, the displayed number changed again.
Very strange, please enlighten me.
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-17 13:36:01
| Show all posts
should be
"After running, m_tr1 does not display the value of the first cell and the second cell in sheet1 in e:\\x.xls."
Wrong, sorry.
Reply

Use magic Report

1

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-8-8 09:00:01
| Show all posts
double num=atof((char *)_bstr_t(vs));//This sentence must be needed
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list