T
The One
Hi All,
I am trying to get Excel to open using the contents of a stream that I
have populated from a database. Are there any samples/examples I can
review /
The code looks something like this (although I have removed error
handling for clarity):
ADO::_RecordsetPtr pRS("ADODB.Recordset",false);
_variant_t vRows;
_bstr_t bstrSelect("SELECT * from MyTable where name = 'Mysheet'");
pRS = m_pConn->Execute(bstrSelect, &vRows,0);
ADO::_StreamPtr pStr("ADODB.Stream");
pStr->Type = ADO::adTypeBinary;
pStr->Open
(vtMissing,ADO::adModeUnknown,ADO::adOpenStreamUnspecified,"","");
pStr->Write(pRS->GetFields()->GetItem((_variant_t)"DATA")->GetValue());
This works as I can use the following to open the spreadsheet
_bstr_t bstrFile("C:\Tmp\MySheet.xls");
pStr->SaveToFile(bstrFile,ADO::adSaveCreateNotExist);
LPDISPATCH lpDisp;
m_app.CreateDispatch("Excel.Application")lpDisp = m_app.GetWorkbooks();
ASSERT(lpDisp);
m_books.AttachDispatch(lpDisp);
m_books.Open
(bstrFile,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt);
I am trying to get Excel to open using the contents of a stream that I
have populated from a database. Are there any samples/examples I can
review /
The code looks something like this (although I have removed error
handling for clarity):
ADO::_RecordsetPtr pRS("ADODB.Recordset",false);
_variant_t vRows;
_bstr_t bstrSelect("SELECT * from MyTable where name = 'Mysheet'");
pRS = m_pConn->Execute(bstrSelect, &vRows,0);
ADO::_StreamPtr pStr("ADODB.Stream");
pStr->Type = ADO::adTypeBinary;
pStr->Open
(vtMissing,ADO::adModeUnknown,ADO::adOpenStreamUnspecified,"","");
pStr->Write(pRS->GetFields()->GetItem((_variant_t)"DATA")->GetValue());
This works as I can use the following to open the spreadsheet
_bstr_t bstrFile("C:\Tmp\MySheet.xls");
pStr->SaveToFile(bstrFile,ADO::adSaveCreateNotExist);
LPDISPATCH lpDisp;
m_app.CreateDispatch("Excel.Application")lpDisp = m_app.GetWorkbooks();
ASSERT(lpDisp);
m_books.AttachDispatch(lpDisp);
m_books.Open
(bstrFile,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt);