ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Opening Excel with a stream (https://www.excelbanter.com/excel-programming/284709-opening-excel-stream.html)

The One

Opening Excel with a stream
 
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::adOpenStreamUns pecified,"","");

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);



losmac[_2_]

Opening Excel with a stream
 
The only way I know is to open Excel workbook from
commandline.

Shell(ExcelPath & " " & bstrFile & " /cmd " & vopt1 & " "
& vopt2 & " " & voptn)



-----Original Message-----
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::adOpenStreamUns pecified,
"","");

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 One

Opening Excel with a stream
 
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

"losmac" wrote in news:012601c3bd03
:

The only way I know is to open Excel workbook from
commandline.

Shell(ExcelPath & " " & bstrFile & " /cmd " & vopt1 & " "
& vopt2 & " " & voptn)



-----Original Message-----
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::adOpenStreamUns pecified,
"","");

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")lpDis p =

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);


.





All times are GMT +1. The time now is 04:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com