I have this current code, which types "AAPL" into an excel sheet, and the returns the corresponding value.
I would like to make it so that after cout << "Ticker: ";
i can type in a ticker symbol (such as AAPL) and use this as the variant_t ticker = "xxx".
I tried doing so by using string
but i get an error that says cannot convert from 'std::string to const _variant_t &'
Is there anyway to do this? Thanks in advance.
XL->Workbooks->Open(L"F:\\xxx\\Desktop\\fxxxx.xlsx");
Excel::RangePtr pRange = pSheet->Cells;
cout << "Ticker: ";
variant_t ticker = "AAPL";
pRange->Item[2][1] = ticker;
double value = pRange->Item[2][2];
cout << "\n Value = " << value << endl;
Call ticker.SetString(str.c_str())
should do the job.
See: http://msdn.microsoft.com/en-us/library/x295h94e%28v=vs.100%29.aspx
Here is the working code:
XL->Workbooks->Open(L"F:\\xx\\Desktop\\xxz.xlsx"); //Open databse
Excel::_WorksheetPtr pSheet = XL->ActiveSheet; //Point to Active Sheet
Excel::RangePtr pRange = pSheet->Cells; //Point to Active Cells
cout << " Ticker: "; //Prompt Ticker
string tick; //Define string "tick" to store ticker
cin >> tick; //Store ticker
variant_t ticker; //Define variant to be used for ticker
ticker.SetString(tick.c_str()); //Convert string to variant
pRange->Item[2][1] = ticker; //Write ticker to cell
double bi = pRange->Item[2][2]; //Read Beta, store as "bi"
cout << "\n Beta = " << bi << endl; //Return Value
XL->Application->Quit();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With