Excel Programming: SetItem and SetValue Does Not Work

L

Landon

I use Visual C++ MFC 4.2.

I am developing an Excel file automation process.

I need to update the value of the cells.

I have succeeded in getting the old value of that cell but when I tried to
update with the new value, it did not work.

What cause it? I have tried both SetItem and SetValue:
Worksheets sheets = book.GetSheets();
_Worksheet sheet = sheets.GetItem( COleVariant( ( short )1 ) );

LPDISPATCH lpDisp = sheet.GetRange( COleVariant( "A1" ), COleVariant( "A1"
) );
ExcelRange range;
range.AttachDispatch( lpDisp );
VARIANT varRet = range.GetText();
TRACE( CString( varRet.bstrVal ) + "\n" );
lpDisp = sheet.GetRange( COleVariant( "A1" ), COleVariant( "A1" ) );
range.AttachDispatch( lpDisp );
range.SetValue( COleVariant( "XYZ" ) );
range.SetItem( COleVariant( ( short )1 ), COleVariant( "A" ),
COleVariant( "ABC" ) );
range.ReleaseDispatch();

How to solve this?

Thank you very much.
 

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

Top