我有这个当前代码,它在excel工作表中键入"AAPL",并返回相应的值。
我想这样做,以便在cout << "Ticker: ";
之后,我可以输入一个股票代码(如AAPL),并使用它作为variant_t ticker = "xxx".
,我尝试使用string
这样做,但我得到一个错误,说不能从'std::string to const _variant_t &'
转换,无论如何要这样做?提前谢谢。
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;
调用ticker.SetString(str.c_str())
应该完成这项工作。
看:http://msdn.microsoft.com/en-us/library/x295h94e%28v=vs.100%29.aspx
工作代码:
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();