|
-
May 29th, 2013, 04:10 PM
#13
Re: COleVariant in WinAPI (afxdisp.h)
ok.. so everything works.
the Excel gets open and the cells get filled in .. and all by using OLE Auto.
btw you won't believe how slow this is!!!! and it seems OLE Auto does not have formatting option. you can only create a "raw" excel.
here is the final function (without a need of use libs form MFC or ATL) which sets the cell value for the given row and column (int).
Code:
HRESULT CMSExcel::SetExcelValueByCoordins(LPCTSTR text, int rzad, int kolumna, bool bAutoFit, int nAlignment)
{
if(!m_pEApp) return E_FAIL;
if(!m_pActiveBook) return E_FAIL;
IDispatch *pXLApp;
{
VARIANT result;
VariantInit(&result);
OLEMethod(DISPATCH_PROPERTYGET, &result, m_pActiveBook, L"Application", 0);
pXLApp= result.pdispVal;
}
IDispatch* pCells;
{
VARIANT result;
VariantInit(&result);
VARIANT row, col;
row.vt =VT_I4;
row.lVal =rzad;
col.vt =VT_I4;
col.lVal =kolumna;
m_hr=OLEMethod(DISPATCH_PROPERTYGET, &result, pXLApp, L"Cells", 2,col,row);
pCells = result.pdispVal;
}
{
_variant_t value(text);
VARIANT result;
m_hr=OLEMethod(DISPATCH_PROPERTYPUT, NULL, pCells, L"Value", 1, value);
}
if(bAutoFit)
{
IDispatch* pEntireColumn;
{
VARIANT result;
VariantInit(&result);
m_hr=OLEMethod(DISPATCH_PROPERTYGET, &result, pCells, L"EntireColumn",0);
pEntireColumn= result.pdispVal;
}
{
m_hr=OLEMethod(DISPATCH_METHOD, NULL, pEntireColumn, L"AutoFit", 0);
}
pEntireColumn->Release();
}
{
VARIANT x;
x.vt = VT_I4;
x.lVal = nAlignment;
m_hr=OLEMethod(DISPATCH_PROPERTYPUT, NULL, pCells, L"HorizontalAlignment", 1, x);
}
pCells->Release();
pXLApp->Release();
return m_hr;
}
int rzad - row
int kolumna - column
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|