XLL+ Class Library

CXlOper::SetLongFormulaIntl() Example

// Function:    SetLongFormulaIntl
// Purpose:     Paste a long formula to the current cell

//{{XLP_SRC(SetLongFormulaIntl)
    // NOTE - the FunctionWizard will add and remove mapping code here.
    //    DO NOT EDIT what you see in these blocks of generated code!
IMPLEMENT_XLLFN2(SetLongFormulaIntl, "A", "SetLongFormulaIntl", "", 
    "User Defined", "Paste a long formula to the current cell", 
    "", "appscope=1\0", 2)

extern "C" __declspec( dllexport )
BOOL SetLongFormulaIntl()
{
    XLL_FIX_STATE;
//}}XLP_SRC

    // Build a long formula:
    // =LEFT("abcde..."&"abcde..."&...,200)

    // Note that "LEFT" is in always in English, and that the 
    // argument separator is always a comma (US English settings).

    int nChars = 200;
    int nRepeats = 4;

    char achVal1[1024];
    for (int i = 0; i < nChars; i++)
        achVal1[i] = 'A' + (i % 26);
    achVal1[i] = 0;
    CString strVal2 = "";
    for (i = 0; i < nRepeats; i++)
        strVal2 += ((i > 0) ? "&" : "") + CString("\"") + achVal1 + "\"";
    CString strFormula = "=LEFT(" + strVal2 + ", 200)";
    
    // Report formula length
    CString strMsg;
    strMsg.Format("Formula length = %d", strFormula.GetLength());
    CXllApp::XlMessageBox(strMsg, XlMessageBoxTypeInformation);

    CXlOper xloActive;
    if (xloActive.GetActiveCell()
     && xloActive.SetLongFormula(strFormula))
    {
        return TRUE;
    }
    else
    {
        CXllApp::XlMessageBox("Failed to set long formula", XlMessageBoxTypeExclamation);
        return FALSE;
    }
}

Uses

CXlOper::SetLongFormulaIntl