LPXLFOPER EXCEL_EXPORT xlStats( LPXLFOPER dataa) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); XlfOper datab( (dataa)); MyArray data( datab.AsArray("data")); double t = (clock()+0.0)/CLOCKS_PER_SEC; MyArray result( Stats( data) ); t = (clock()+0.0)/CLOCKS_PER_SEC-t; CellMatrix resultCells(result); CellMatrix time(1,2); time(0,0) = "time taken"; time(0,1) = t; resultCells.PushBottom(time); return XlfOper(resultCells); EXCEL_END }
LPXLFOPER EXCEL_EXPORT xlEchoInt( double ba) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); int b( static_cast<int>(ba)); double t = (clock()+0.0)/CLOCKS_PER_SEC; double result( EchoInt( b) ); t = (clock()+0.0)/CLOCKS_PER_SEC-t; CellMatrix resultCells(result); CellMatrix time(1,2); time(0,0) = "time taken"; time(0,1) = t; resultCells.PushBottom(time); return XlfOper(resultCells); EXCEL_END }
LPXLFOPER EXCEL_EXPORT xlConcat( XLWSTR str1a, XLWSTR str2a) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); std::wstring str1( voidToWstr(str1a)); std::wstring str2( voidToWstr(str2a)); double t = (clock()+0.0)/CLOCKS_PER_SEC; std::wstring result( Concat( str1, str2) ); t = (clock()+0.0)/CLOCKS_PER_SEC-t; CellMatrix resultCells(result); CellMatrix time(1,2); time(0,0) = "time taken"; time(0,1) = t; resultCells.PushBottom(time); return XlfOper(resultCells); EXCEL_END }
LPXLOPER EXCEL_EXPORT xlPremiaRegionName( LPXLOPER namea, LPXLOPER regiona) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); XlfOper nameb( (namea)); std::string name( nameb.AsString("name")); XlfOper regionb( (regiona)); CellMatrix region( regionb.AsCellMatrix("region")); std::string result( PremiaRegionName( name, region) ); return XlfOper(result); EXCEL_END }
LPXLFOPER EXCEL_EXPORT xlEchoCells( LPXLFOPER Echoeea) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); XlfOper Echoeeb( (Echoeea)); CellMatrix Echoee( Echoeeb.AsCellMatrix("Echoee")); double t = (clock()+0.0)/CLOCKS_PER_SEC; CellMatrix result( EchoCells( Echoee) ); t = (clock()+0.0)/CLOCKS_PER_SEC-t; CellMatrix resultCells(result); CellMatrix time(1,2); time(0,0) = "time taken"; time(0,1) = t; resultCells.PushBottom(time); return XlfOper(resultCells); EXCEL_END }
LPXLFOPER EXCEL_EXPORT xltypeString2( LPXLFOPER inputa) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); reftest input( (inputa)); double t = (clock()+0.0)/CLOCKS_PER_SEC; std::string result( typeString2( input) ); t = (clock()+0.0)/CLOCKS_PER_SEC-t; CellMatrix resultCells(result); CellMatrix time(1,2); time(0,0) = "time taken"; time(0,1) = t; resultCells.PushBottom(time); return XlfOper(resultCells); EXCEL_END }
LPXLFOPER EXCEL_EXPORT xlEchoArgList( LPXLFOPER argsa) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); XlfOper argsb( (argsa)); CellMatrix argsc( argsb.AsCellMatrix("argsc")); ArgumentList args( ArgumentList(argsc,"args")); double t = (clock()+0.0)/CLOCKS_PER_SEC; CellMatrix result( EchoArgList( args) ); t = (clock()+0.0)/CLOCKS_PER_SEC-t; CellMatrix resultCells(result); CellMatrix time(1,2); time(0,0) = "time taken"; time(0,1) = t; resultCells.PushBottom(time); return XlfOper(resultCells); EXCEL_END }
LPXLFOPER EXCEL_EXPORT xlSystemTime( LPXLFOPER ticksPerSeconda) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); XlfOper ticksPerSecondb( (ticksPerSeconda)); CellMatrix ticksPerSecondc( ticksPerSecondb.AsCellMatrix("ticksPerSecondc")); DoubleOrNothing ticksPerSecond( DoubleOrNothing(ticksPerSecondc,"ticksPerSecond")); double t = (clock()+0.0)/CLOCKS_PER_SEC; double result( SystemTime( ticksPerSecond) ); t = (clock()+0.0)/CLOCKS_PER_SEC-t; CellMatrix resultCells(result); CellMatrix time(1,2); time(0,0) = "time taken"; time(0,1) = t; resultCells.PushBottom(time); return XlfOper(resultCells); EXCEL_END }
LPXLFOPER EXCEL_EXPORT xlPayOffEvaluation( LPXLFOPER PayOffTablea, double Spot) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); XlfOper PayOffTableb( (PayOffTablea)); CellMatrix PayOffTablec( PayOffTableb.AsCellMatrix("PayOffTablec")); ArgumentList PayOffTabled( ArgumentList(PayOffTablec,"PayOffTabled")); Wrapper<PayOff> PayOffTable( GetFromFactory<PayOff>(PayOffTabled)); double t = (clock()+0.0)/CLOCKS_PER_SEC; double result( PayOffEvaluation( PayOffTable, Spot) ); t = (clock()+0.0)/CLOCKS_PER_SEC-t; CellMatrix resultCells(result); CellMatrix time(1,2); time(0,0) = "time taken"; time(0,1) = t; resultCells.PushBottom(time); return XlfOper(resultCells); EXCEL_END }
void xlw::XlfCmdDesc::RemoveFromMenuBar() { // first check that the menu exists and then delete this command XlfOper barNum(10); XlfOper menu(menu_); XlfOper menuLocation; int err = XlfExcel::Instance().Call(xlfGetBar, menuLocation, 3, barNum, menu, XlfOper(0)); if (!err && !menuLocation.IsError()) { err = XlfExcel::Instance().Call(xlfDeleteCommand, 0, 3, barNum, menu, XlfOper(text_)); if(err != xlretSuccess) std::cerr << XLW__HERE__ << "Delete Command " << GetName().c_str() << " from " << menu_.c_str() << " failed" << std::endl; // check if the menu is now empty, if it is then delete it // if it is empty then the first item won't exist XlfOper firstItemLocation; err = XlfExcel::Instance().Call(xlfGetBar, firstItemLocation, 3, XlfOper(10), menu, XlfOper(1)); if(!err && firstItemLocation.IsError()) { err = XlfExcel::Instance().Call(xlfDeleteMenu, 0, 2, barNum, menu); if(err != xlretSuccess) std::cerr << XLW__HERE__ << "Delete Menu " << menu_.c_str() << " failed" << std::endl; } } }
LPXLFOPER EXCEL_EXPORT xlHelloWorldAgain( LPXLFOPER namea) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); XlfOper nameb( (namea)); std::string name( nameb.AsString("name")); double t = (clock()+0.0)/CLOCKS_PER_SEC; std::string result( HelloWorldAgain( name) ); t = (clock()+0.0)/CLOCKS_PER_SEC-t; CellMatrix resultCells(result); CellMatrix time(1,2); time(0,0) = "time taken"; time(0,1) = t; resultCells.PushBottom(time); return XlfOper(resultCells); EXCEL_END }
LPXLFOPER EXCEL_EXPORT xlEchoDoubleOrNothing( LPXLFOPER xa, double defaultValue) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); XlfOper xb( (xa)); CellMatrix xc( xb.AsCellMatrix("xc")); DoubleOrNothing x( DoubleOrNothing(xc,"x")); double t = (clock()+0.0)/CLOCKS_PER_SEC; double result( EchoDoubleOrNothing( x, defaultValue) ); t = (clock()+0.0)/CLOCKS_PER_SEC-t; CellMatrix resultCells(result); CellMatrix time(1,2); time(0,0) = "time taken"; time(0,1) = t; resultCells.PushBottom(time); return XlfOper(resultCells); EXCEL_END }
LPXLOPER EXCEL_EXPORT xlOptionPrice_2( LPXLOPER requested_fielda, LPXLOPER model_ida, LPXLOPER option_ida, LPXLOPER method_ida, double it_1a, double it_2a) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); XlfOper requested_fieldb( (requested_fielda)); std::string requested_field( requested_fieldb.AsString("requested_field")); XlfOper model_idb( (model_ida)); std::string model_id( model_idb.AsString("model_id")); XlfOper option_idb( (option_ida)); std::string option_id( option_idb.AsString("option_id")); XlfOper method_idb( (method_ida)); std::string method_id( method_idb.AsString("method_id")); int it_1( static_cast<int>(it_1a)); int it_2( static_cast<int>(it_2a)); CellMatrix result( OptionPrice_2( requested_field, model_id, option_id, method_id, it_1, it_2) ); return XlfOper(result); EXCEL_END }
LPXLFOPER EXCEL_EXPORT xlGetThreadId( ) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); double result( GetThreadId()); return XlfOper(result); EXCEL_END }
LPXLFOPER EXCEL_EXPORT xlEmptyArgFunction( ) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); std::string result( EmptyArgFunction()); return XlfOper(result); EXCEL_END }
int xlw::XlfCmdDesc::Check(bool ERR_CHECK) const { if (menu_.empty()) { std::cerr << XLW__HERE__ << "No menu specified for the command \"" << GetName().c_str() << "\"" << std::endl; return xlretFailed; } int err = XlfExcel::Instance().Call(xlfCheckCommand, 0, 4, XlfOper(10), XlfOper(menu_), XlfOper(text_), XlfOper(ERR_CHECK)); if (err != xlretSuccess) { std::cerr << XLW__HERE__ << "Registration of " << GetAlias().c_str() << " failed" << std::endl; return err; } return xlretSuccess; }
int xlw::XlfFuncDesc::DoUnregister(const std::string& dllName) const { if(funcId_ != InvalidFunctionId) { // slightly pointless as it doesn't work but we're supposed to deregister // the name as well as the function XlfExcel::Instance().Call(xlfSetName, NULL, 1, XlfOper(GetAlias())); XlfOper unreg; int err = XlfExcel::Instance().Call(xlfUnregister, unreg, 1, XlfOper(funcId_)); return err; } else { return xlretSuccess; } }
LPXLFOPER EXCEL_EXPORT xlEchoMatrix( LPXLARRAY Echoeea) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); NEMatrix Echoee( GetMatrix(Echoeea)); MyMatrix result( EchoMatrix( Echoee) ); return XlfOper(result); EXCEL_END }
LPXLOPER EXCEL_EXPORT xlRef( LPXLOPER referenceea) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); XlfOper referenceeb( (referenceea)); CellMatrix referencee( referenceeb.AsCellMatrix("referencee")); std::string result( Ref( referencee) ); return XlfOper(result); EXCEL_END }
LPXLFOPER EXCEL_EXPORT xlContainsDivByZero( LPXLFOPER inputa) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); XlfOper inputb( (inputa)); CellMatrix input( inputb.AsCellMatrix("input")); bool result( ContainsDivByZero( input) ); return XlfOper(result); EXCEL_END }
LPXLFOPER EXCEL_EXPORT xlContainsError( LPXLFOPER input2a) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); XlfOper input2b( (input2a)); CellMatrix input2( input2b.AsCellMatrix("input2")); bool result( ContainsError( input2) ); return XlfOper(result); EXCEL_END }
LPXLFOPER EXCEL_EXPORT xlEchoShort( LPXLFOPER xa) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); XlfOper xb( (xa)); short x( xb.AsShort("x")); short result( EchoShort( x) ); return XlfOper(result); EXCEL_END }
LPXLFOPER EXCEL_EXPORT xlEchoArray( LPXLFOPER Echoeea) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); XlfOper Echoeeb( (Echoeea)); MyArray Echoee( Echoeeb.AsArray("Echoee")); MyArray result( EchoArray( Echoee) ); return XlfOper(result); EXCEL_END }
int XlfCmdDesc::AddToMenuBar(const std::string& menu, const std::string& text) { XLOPER xMenu; LPXLOPER pxMenu; LPXLOPER px; menu_ = menu; text_ = text; // This is a small trick to allocate an array 5 XlfOper // One must first allocate the array with XLOPER // px = pxMenu = (LPXLOPER)new XLOPER[5]; px = pxMenu = new XLOPER[5]; // and then assign the XLOPER to XlfOper specifying false // to tell the Framework that the data is not owned by // Excel and that it should not call xlFree when destroyed XlfOper(px++).Set(text_.c_str()); XlfOper(px++).Set(GetAlias().c_str()); XlfOper(px++).Set(""); XlfOper(px++).Set(GetComment().c_str()); XlfOper(px++).Set(""); xMenu.xltype = xltypeMulti; xMenu.val.array.lparray = pxMenu; xMenu.val.array.rows = 1; xMenu.val.array.columns = 5; int err = XlfExcel::Instance().Call(xlfAddCommand, 0, 3, (LPXLOPER)XlfOper(1.0), (LPXLOPER)XlfOper(menu_.c_str()), (LPXLOPER)&xMenu); if (err != xlretSuccess) std::cerr << XLW__HERE__ << "Add command " << GetName().c_str() << " to " << menu_.c_str() << " failed" << std::endl; delete[] pxMenu; return err; }
LPXLFOPER EXCEL_EXPORT xlCirc( double Diameter) { EXCEL_BEGIN; if (XlfExcel::Instance().IsCalledByFuncWiz()) return XlfOper(true); double t = (clock()+0.0)/CLOCKS_PER_SEC; double result( Circ( Diameter) ); t = (clock()+0.0)/CLOCKS_PER_SEC-t; CellMatrix resultCells(result); CellMatrix time(1,2); time(0,0) = "time taken"; time(0,1) = t; resultCells.PushBottom(time); return XlfOper(resultCells); EXCEL_END }
/*! Registers the command as a macro in excel. \sa XlfExcel, XlfFuncDesc. */ int XlfCmdDesc::DoRegister() const { const std::string& dllname = XlfExcel::Instance().GetName(); if (dllname.empty()) { std::cerr << XLW__HERE__ << "Library name is not initialized" << std::endl; return xlretFailed; } // ERR_LOG("Registering command \"" << alias_.c_str() << "\" from \"" << name_.c_str() << "\" in \"" << dllname.c_str() << "\""); int err = XlfExcel::Instance().Call( xlfRegister, NULL, 7, (LPXLOPER)XlfOper(dllname.c_str()), (LPXLOPER)XlfOper(GetName().c_str()), (LPXLOPER)XlfOper("A"), (LPXLOPER)XlfOper(GetAlias().c_str()), (LPXLOPER)XlfOper(""), (LPXLOPER)XlfOper(2.0), (LPXLOPER)XlfOper("")); return err; }
int xlw::XlfOper4::ConvertToDoubleVector(std::vector<double>& v, DoubleVectorConvPolicy policy) const { if (lpxloper_->xltype == xltypeMissing) { v.resize(0); return xlretSuccess; } if (lpxloper_->xltype & xltypeNum) { // first test if double double d=0.0; int xlret1 = ConvertToDouble(d); if (xlret1 == xlretSuccess) { v.resize(1); v[0] = d; return xlret1; } } if (lpxloper_->xltype & xltypeMulti) { size_t nbRows = lpxloper_->val.array.rows; size_t nbCols = lpxloper_->val.array.columns; bool isUniDimRange = ( nbRows == 1 || nbCols == 1 ); if (policy == UniDimensional && ! isUniDimRange) // not a vector we return a failure return xlretFailed; size_t n = nbRows*nbCols; v.resize(n); for (size_t i = 0; i < nbRows; ++i) { for (size_t j = 0; j < nbCols; ++j) { size_t index; if (policy == RowMajor) // C-like dense matrix storage index = i*nbCols+j; else // Fortran-like dense matrix storage. Does not matter if the policy is UniDimensional index = j*nbRows+i; unsigned long thisType = (*lpxloper_).val.array.lparray[i*nbCols+j].xltype; if (thisType == xltypeNum) { v[index] = (*lpxloper_).val.array.lparray[i*nbCols+j].val.num; } else { v[index] = XlfOper(&(*lpxloper_).val.array.lparray[i*nbCols+j]).AsDouble(); } } } return xlretSuccess; } XlfRef ref; int xlret = ConvertToRef(ref); if (xlret != xlretSuccess) return xlret; int nbRows = ref.GetNbRows(); int nbCols = ref.GetNbCols(); bool isUniDimRange = ( nbRows == 1 || nbCols == 1 ); if (policy == UniDimensional && ! isUniDimRange) // not a vector we return a failure return xlretFailed; size_t n = nbRows*nbCols; v.resize(n); for (int i = 0; i < nbRows; ++i) { for (int j = 0; j < nbCols; ++j) { if (policy == RowMajor) // C-like dense matrix storage xlret = ref.element<XlfOper4>(i,j).ConvertToDouble(v[i*nbCols+j]); else // Fortran-like dense matrix storage. Does not matter if the policy is UniDimensional xlret = ref.element<XlfOper4>(i,j).ConvertToDouble(v[j*nbRows+i]); if (xlret != xlretSuccess) return xlret; } } return xlret; };
void Cell_t::SetFontSize(const XlfOper& ref, double newFontSize) { setFontProperties(ref, XlfOper(), newFontSize); }
void Cell_t::SetFont(const XlfOper& ref, const std::string& newFont) { setFontProperties(ref, newFont, XlfOper()); }
void Notes_t::ClearNote(const XlfOper& cellRef) { CallCommand(xlcNote, XlfOper(), cellRef, "Clear Note"); }