We use the olecontrol.insertFile (...) method to populate an olecontrol object with a file system document - for example, "foo.xlsx".
How can we now extract the document out of the olecontrol, and write it back into a file system document?
We know we cannot do the following, at least for complex documents such as XLSX spreadsheets:
blob blob_objectData
int i_rc, i_file
long l_rc
i_rc = ole_1.insertFile ("C:\temp\foo1.xlsx")
blob_objectData = ole_1.objectdata
i_file = fileOpen ("C:\temp\foo2.xlsx", StreamMode!, Write!, LockWrite!, Replace!)
l_rc = filewriteEx (i_file, blob_objectData)
i_rc = fileClose (i_file)
Basically we are looking for something that is conceptually an "olecontrol.extractFile (...)" method. Does anyone have a suggestion on how to do this?
The real-world problem we are trying to solve is as follows: Application users embed document files such as spreadsheets in our database. How can we automate exporting these database-stored documents back into document files without having to activate each one interactively and performing a "Save As..."?
Thanks!
You may also want to try a binary compare of an original file to the ole_1.objectdata version, so you can see if there's any way to strip off the header before writing the file out (by using blobmid or similar).
I think we tried a binary compare and it was not so clear cut how to strip off the "OLE stuff", but I will look again.
I wish this all were easier (i.e. opposite of ole_1.insertfile (...)), but it appears not to be.
That said - I found one product out there that may do the trick: http://www.yohz.com/sbv_details.htm
Thanks!
We are trying your suggestion with incomplete success, and hope you can help further.
If we "insertfile" an XLSX spreadsheet into an OLE control ole_1, and then do the following:
oleobject obj_oleobj
obj_oleobj = ole_1.object
// 51 = (without macro's in 2007-2016, xlsx)
b_rc = obj_oleobj.saveas ("c:\temp\bla.xlsx", 51)
We get a file "c:\temp\bla.xlsx" that, when double-clicked, starts up Excel, but shows as blank. A lighter excel viewer will show us the spreadsheet contents.
What we are actually doing, however, is after "insertfile" an XLSX spreadsheet into ole_1, we write ole_1.objectdata into a blob database column.
Later, we selectblob the database value into blob_foo, and then:
oleobject obj_oleobj
ole_1.objectdata = blob_foo
obj_oleobj = ole_1.object
// 51 = xlOpenXMLWorkbook (without macro's in 2007-2016, xlsx)
b_rc = obj_oleobj.saveas ("c:\temp\bla.xlsx", 51)
However the "saveas" verb now produces an error.
Any insights you have would be appreciated into:
1) Why the first code block produced a XLSX file that seemed to be accepted by Excel but did not display
2) Why the second code block did not behave the same as the first. (is "obj_oleobj = ole_1.object" OK and usable for automation verbs?).
Thanks,
Dan.