Opening Excel with a stream

  • Thread starter Thread starter The One
  • Start date Start date
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);
 
The only way I know is to open Excel workbook from
commandline.

Shell(ExcelPath & " " & bstrFile & " /cmd " & vopt1 & " "
& vopt2 & " " & voptn)
 
Thanks for the suggestion but that is not really what I want. I already
have the file loaded into a stream from a database and I do not want to
have to create a temporary file and then load it. This will mean I have
to delete the temporary file etc and we all know that leads to messy tmp
directories full of orphaned files.

TIA
John The One
 
Back
Top