Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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); |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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); . |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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); . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to calculate IRR from a monthly income stream | Excel Discussion (Misc queries) | |||
stream read error | Excel Discussion (Misc queries) | |||
PV of uneven stream of cash flows | Excel Worksheet Functions | |||
How can I figure present value of a stream of payments? | New Users to Excel | |||
Command Button Code Stream lining | Excel Programming |