XLL+ Class Library (6.3)

CXlOper::SetLongFormula() Example

CopyC++
// Function:    SetLongFormula 
// Purpose:     Paste a long formula to the current cell 
 
//{{XLP_SRC(SetLongFormula) 
    // NOTE - the FunctionWizard will add and remove mapping code here. 
    //    DO NOT EDIT what you see in these blocks of generated code!
IMPLEMENT_XLLFN3(SetLongFormula, SetLongFormula_4, SetLongFormula_12, "A", "A", 
    L"SetLongFormula", 0, L"", 0, L"14", 0, L"Paste a long formula to the curr"
    L"ent cell", 0, L"", 0, 0, L"{SetLongFormula,,,Paste a long formula to the"
    L" current cell,14,2,132,A,{},{},3,,0,0}", 2)
BOOL SetLongFormula_Impl();

extern "C" __declspec(dllexport)
BOOL SetLongFormula_12()
{
    XLL_FIX_STATE;
    return SetLongFormula_Impl();
}
extern "C" __declspec(dllexport)
BOOL SetLongFormula_4()
{
    XLL_FIX_STATE;
    return SetLongFormula_Impl();
}

BOOL SetLongFormula_Impl()
{
    // End of generated code 
//}}XLP_SRC 
 
    // Build a long formula: 
    // ="abcde..."&"abcde..."&... 
 
    int nChars = 200;
    int nRepeats = 4;

    char achVal1[1024];
    int i;
    for (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 = "=" + strVal2;

    // Report length of formula
    CString strMsg;
    strMsg.Format("Formula Length = %d", strFormula.GetLength());
    CXllApp::XlMessageBox(strMsg, XlMessageBoxTypeInformation);

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

Uses

CXlOper::SetLongFormula