|
..using VB6, i have data saved in a column of an excel file that am trying to extract. the code i have written returns only zeroes, cant figure out what the problem...any suggestion would be appreciated!
#include "stdafx.h"
#include "stdio.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
_variant_t raw_data[10];
Excel::_ApplicationPtr pApplication;
HRESULT hr = S_OK;
OleInitialize(NULL);
if ( FAILED( hr=pApplication.CreateInstance ("Excel.Application") ))
{
return 1;
}
_variant_t varOption( (long) DISP_E_PARAMNOTFOUND, VT_ERROR );
Excel::_WorkbookPtr pBook;
pBook = pApplication->Workbooks->Open("C:\\Myexcel",varOption, varOption, varOption, varOption,varOption, varOption, varOption, varOption, varOption, varOption, varOption, varOption );
Excel::_WorksheetPtr pSheet = pBook->Sheets->Item[(long) 1]; // grabs first worksheet
Excel::RangePtr pRange = pSheet->GetRange( _bstr_t( "B2"), _bstr_t("B2")); //loads column headers
int iColumn = 2;
_variant_t vItem = pRange->Item[(long) 1][(long) iColumn ];
_bstr_t bstrText( vItem );
// Load the rows
pRange = pSheet->GetRange( _bstr_t("B2"), _bstr_t("B12") );
for ( int iRow = 1;iRow < 10; ++iRow )
{
_variant_t vItem = pRange->Item[(long) iRow ][ (long) iColumn];
_bstr_t bstrText( vItem );
raw_data[iRow] = vItem;
cout << (long) raw_data[iRow];
}
// Don't save any inadvertant changes to the .xls file.
pBook->Close( VARIANT_FALSE );
// Need to quit, otherwise Excel remains active and locks the .xls file.
pApplication->Quit( );
return 0;
}
|
|
|
|
|
Whether this line is returning zero?
pBook = pApplication->Workbooks->Open("C:\\Myexcel",varOption, varOption, varOption, varOption,varOption, varOption, varOption, varOption, varOption, varOption, varOption, varOption );
Величие не Бога может быть недооценена.
|
|
|
|
|
The line is not, i put in a check to ensure that it wasnt null
|
|
|
|
|
i think the problem relies here
variant_t vItem = pRange->Item[(long) 1][(long) iColumn ];
_bstr_t bstrText( vItem );
Item property on Excel::Range returns another Excel::Range. So try 'Text 'property on the returned Range, as below..
_variant_t vItem = pRange->Item[(long)iRow][(long)iColumn];
Excel::RangePtr pSelRange = vItem.pdispVal;
_variant_t vItemText = pSelRange->Text();
cout<<vItemText.bstrVal;
|
|
|
|
|
I tried that line but i get error on the
Excel::RangePtr pSelRange = vItem.pdispVal; //new Range
am fairly new to C++, is there any kind of header that needs to be added in
other to execute that line?
the error is : error C2064: term does not evaluate to a function
|
|
|
|
|
which compiler do you use? Can't you attach the returned IDispatch* value (vItem.pdispVal) to new RangePtr object? I mean, isn't there any function some thing like pSelRange->AttachDispatch(vItem.pdispVal) ..?
|
|
|
|
|
Thanks all, i was able to discover what the problem was, i was setting icolumn to 2 instead of 1.............
|
|
|
|
|
buki86 wrote: _variant_t raw_data[10];
Shouldn't this be 11 ?
buki86 wrote: _variant_t vItem = pRange->Item[(long) 1][(long) iColumn ];
Since the range is only one cell, both the row and column will be 1 .
buki86 wrote: pRange = pSheet->GetRange( _bstr_t("B2"), _bstr_t("B12") );
for ( int iRow = 1;iRow < 10; ++iRow )
The range you are defining has 11 rows. The loop will run 9 times. Is that intentional?
Try something like:
for (int iRow = 0; iRow < 11; ++iRow)
{
_variant_t vItem = pRange.GetItem(COleVariant(iRow + 1L), COleVariant(1L));
_bstr_t bstrText(vItem);
raw_data[iRow] = vItem;
cout << (long) raw_data[iRow];
}
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
how do i declare COleVariant? my compiler sees it as an undeclared
identifier....
|
|
|
|
|
It's in afxdisp.h .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Hi guys i would like to know how to do this i want to make my editing CEdit control know if it lost focus by a mouse click a keyboard hit, a popup window, etc
Thx
|
|
|
|
|
i don't think that's possible. any window can grab focus any time it wants, just by calling SetFocus, and it doesn't need to tell anyone why.
|
|
|
|
|
Your CEdit will receive a WM_KILLFOCUS ,
and you could implement a reaction for the message...
virtual void BeHappy() = 0;
|
|
|
|
|
Ok guys thanks i will have to do something else for this requirement.
|
|
|
|
|
Hi,
I am trying to follow some assembler code
in my program However it would be nice
if the C/C++ source statements will laid
out before the generated assembler code
I guess the compiler optimizes the code
and moves things around
would using the above #pragma get me
code where I code see what assembler code
is generated by the C/C+ source
|
|
|
|
|
Hi,
Yes the #pragma optimize directive can be used to disable compiler optimizations around a particular portion of code. You will also need to use the /FAs compiler switch to see both source and assembly.
/FA, /Fa (Listing File)[^]
Best Wishes,
-David Delaune
|
|
|
|
|
Or you could just use the debug version of the compiled code? That would be just as valid as turning off optimisations selectively…
Why are you looking at the assembly language, BTW? If it's to debug a problem, then you have to look at the optimised code, painful as it might be...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
CodeProject MVP for 2010 - who'd'a thunk it!
|
|
|
|
|
I just like to look at the paramters and return
code ax register etc optimized code is to difficult
|
|
|
|
|
ForNow wrote: However it would be nice
if the C/C++ source statements will laid
out before the generated assembler code
Such as what the /E and /P compiler switches do?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Sorry for delayed response
was observing passover
/P and /E are for pre-processor
|
|
|
|
|
Sorry. I meant /FAs.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
if I use backspace and delete keys to edit code in VC6, VC6 shutdowns at once (without asking for saving file), so I can't work now.
I test other edit programs, such as word, notepad and this forum, all are fine.
do you know why?
======================================
I got solution and post here for others.
some h and cpp files are edited by another editor, they look good in VC6, but actually have different format - I think it is \r\n, when VC tries to save the file after modification, VC crashes.
I use notepad modified related h and cpp files, now my project is fine.
-- Modified Tuesday, March 30, 2010 5:38 AM
|
|
|
|
|
Other than the usual "real programmers never use the delete and backspace keys" answer , have a look at the .suo file (heck that probably did not even exists for VC6 !) or maybe the keyboard settings/preferences.
Do it crap out with other projects or just that one ? i.e. create a new project from scratch and see if you can edit the files.
Or maybe your VC6 is telling you it wants to retire and urge you (and/or your organization) to upgrade to a more recent IDE.
Watched code never compiles.
|
|
|
|
|
try deleting your .NCB file.
|
|
|
|
|
1. other VC6 projects are fine, problem comes only from this one.
2. there is no .suo file.
3. no help after deleting .ncb file.
how to change keyboard settings for specified project?
any comments?
|
|
|
|