It's not elegant, and the problem with excel and office files is the macros. If macros exist, then a messagebox opens and asks if you want to enable macros, but only if you set the activate (true). Otherwise it just will not create the object for security reasons.
Also, you have to create the filename for the object.. i.e. is the object a worksheet, word document, visio drawing. To figure out the possibilities and add to the select case, you need to get a sampling and open the document, right click on it to get the object type string and then create another select case statement in this agent, with the appropriate filename and extension.
Embedded objects don't recognize images.. i.e. .jpg, .gif unless they are attached, and not embedded.
When an OLE object is embedded, the only thing Notes (or other applications) store is the program that created it, so it can open the program. It does not save the original filename. Therefore the program must be installed for this code to work, and the saved files are generically named: Word Document, Excel Worksheet, Visio Drawing.. not much help if you want to associate the object with a particular email thread. You could possible create the name from the email properties.. i.e. username, subject.
But what you're going to get is disconnected and out of context files. For example, how would I know if Excelworksheet 2005-11-9.xls is the Acme Quote Request? If it were me, I would simply print the email threads to PDF. Acrobat does this rather well, and you get indexing and context, plus bookmarks.
---------
Another way is to install DAMO on the current Notes Server, and have the users use Outlook to access their Notes Email Database and then copy those to Exchange, or use a Microsoft Exchange migration tool to move the emails to Exchange.
----------------------
Agent Information
Name: Detach and Remove Embedded
Last Modification: 12/10/2006 07:17:06 PM
Comment: [Not Assigned]
Shared Agent: Yes
Type: LotusScript
State: Enabled
Trigger: Manually From Actions Menu
Acts On: Selected documents
LotusScript Code:
Код:
Option Public
Option Declare
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim collection As NotesDocumentCollection
Set db = session.currentdatabase
Set collection = db.UnprocessedDocuments
Dim detachfolder As String
Dim fileExt As String
Dim filename As String
Dim thisName As String
Dim oleobj As Variant
detachfolder = "c:\Temp"
Dim rtitem As Variant
Dim filecount As Integer
Dim Processed As Integer
FileCount = 0
If collection.Count < 1 Then
Msgbox "Sorry, there were no documents selected",,"Nothing Selected"
Exit Sub
End If
Set doc = collection.GetFirstDocument
While Not doc Is Nothing
Filename = ""
Set rtitem = doc.GetFirstItem( "Body" )
If ( rtitem.Type = RICHTEXT ) Then
Forall o In rtitem.EmbeddedObjects
If o.Type = EMBED_ATTACHMENT Then
thisName = o.Name
Filename = detachFolder + "\" + o.name + "_" + Cstr(fileCount + 1)
Print "Processing: " + filename
If okToSave(filename) Then
Call o.ExtractFile (Filename )
Call o.Remove
rtItem.addnewline(1)
rtItem.appendText "Embedded file removed to: " + Filename
rtItem.addnewline(1)
rtItem.appendText "Removed on: " + Format(Now) + " by " + session.commonusername
If doc.HasItem("FileExportError") Then
doc.RemoveItem("FileExportError")
End If
Call doc.Save( True, False, False )
fileCount = fileCount + 1
Else
Msgbox "Problem saving: " + filename,,"Unable to Save"
doc.FileExportError = "PROCESS MANUALLY"
doc.save True, False, False
End If
End If
If o.Type = EMBED_OBJECT Then
thisName = o.name
Select Case Lcase(o.name)
Case Lcase("Microsoft Office Excel Worksheet")
Filename =DetachFolder + "\ExcelWorksheet" + Format(doc.Created, "yyyy-mm-dd") + "_" + Cstr(fileCount +1) + ".xls"
Case Lcase("Microsoft Word Document")
Filename =DetachFolder + "\WordDocument" + Format(doc.Created, "yyyy-mm-dd") + "_" + Cstr(fileCount +1) + ".doc"
Case Lcase("Microsoft Visio Drawing")
Filename =DetachFolder + "\Visio Drawing" + Format(doc.Created, "yyyy-mm-dd") + "_" + Cstr(fileCount +1) + ".vsd"
Case Else
Filename =DetachFolder + "\Unknown File" + Format(doc.Created, "yyyy-mm-dd") + "_" + Cstr(fileCount +1) + ".rtf"
End Select
Print "Processing: " + filename
If Len(filename)> 1 Then
If okToSave(filename) Then
On Error Goto Handle_Error
Set oleObj = o.Activate (False)
If Not oleObj Is Nothing Then
Call oleObj.SaveAs(fileName)
Msgbox "File Saved as: " + filename,,o.name
Call oleObj.Close
fileCount = fileCount + 1
rtItem.addnewline(1)
rtItem.appendText "Embedded File saved to: " + FileName
rtItem.addnewline(1)
rtItem.appendText "Saved to Disk on: " + Format(Now) + " by " + session.commonusername
If doc.HasItem("FileExportError") Then
doc.RemoveItem("FileExportError")
End If
Call doc.Save( True, False, False )
Else
Msgbox "Unable to open File: " + filename + " you may have to process this manually",,"File Save Failed"
doc.FileExportError = "PROCESS MANUALLY"
doc.save True, False, False
End If
Else
Msgbox "Problem saving: " + filename,,"Unable to Save"
End If
End If
End If
End Forall
End If
Processed = Processed + filecount
fileCount = 0
Set doc = collection.GetNextDocument(doc)
Wend
Msgbox "Finished processing: " + Cstr(Processed) + " files" + Chr(13) + _
"Please check: " + detachFolder + " for the files",,"Finished"
Exit Sub
Handle_Error:
On Error Goto 0
Msgbox "Sorry, there was an error processing this request: " + thisName + _
" Error: " + Error$ + "-" + Str(Err),,"Error processing File"
Resume Next
Exit Sub
End Sub
Sub Terminate
End Sub
Function okToSave(strPath As String) As Boolean
Dim tmpFile As String
Dim result As Boolean
result = False
If strPath="" Then Exit Function
On Error Goto NoFile_Error
tmpFile = Dir$(strPath)
If Len(tmpFile)<>0 Then result = True
OktoSave = False
If result Then
Dim ans As Integer
ans = Msgbox ("The File: " + strPath + " already exists. Did you want to overwrite it?",36,"File already exists")
If ans = 6 Then
Kill strPath
OktoSave = True
Exit Function
End If
Else
OKToSave = True
End If
Exit Function
NoFile_Error:
Err = 0
result = False
Exit Function
И еще:
If you open the notes document, and right click on the OLE object and select properties, a properties dialog box will pop up. The "I" tab will show you the exact object origin, i.e. "Microsoft Office Excel Worksheet".
The code I posted resolves three common OLE types, with a fourth case else, which it labels as "unknown":
Select Case Lcase(o.name)
Case Lcase("Microsoft Office Excel Worksheet")
Filename =DetachFolder + "\ExcelWorksheet" + Format(doc.Created, "yyyy-mm-dd") + "_" + Cstr(fileCount +1) + ".xls"
Case Lcase("Microsoft Word Document")
Filename =DetachFolder + "\WordDocument" + Format(doc.Created, "yyyy-mm-dd") + "_" + Cstr(fileCount +1) + ".doc"
Case Lcase("Microsoft Visio Drawing")
Filename =DetachFolder + "\Visio Drawing" + Format(doc.Created, "yyyy-mm-dd") + "_" + Cstr(fileCount +1) + ".vsd"
'THIS IS WHEN THE OBJECT NAME DOESN'T MEET THE ABOVE NAMES... IT SAVES TO A RICH TEXT FILE.
Case Else
Filename =DetachFolder + "\Unknown File" + Format(doc.Created, "yyyy-mm-dd") + "_" + Cstr(fileCount +1) + ".rtf"
End Select
-------
What this means is that the embedded object didn't match the exact wordage of what I initially trapped for:
Microsoft Office Excel Worksheet,
Microsoft Word Document,
Microsoft Visio Drawing
And since it had SOME information in the OLE properties, it resolved it to "unknown file.rtf" which would associate it on your system as a Microsoft word document.
You need to open the document and right click on those two objects, get the object names and add the appropriate "case" statement to the code with the appropriate filename. for instance:
If the object properties for the OLE file is: "Excel Worksheet" then add:
Case Lcase("Microsoft Office Excel Worksheet")
Filename =DetachFolder + "\ExcelWorksheet" + Format(doc.Created, "yyyy-mm-dd") + "_" + Cstr(fileCount +1) + ".xls"
Case Lcase("Microsoft Word Document")
Filename =DetachFolder + "\WordDocument" + Format(doc.Created, "yyyy-mm-dd") + "_" + Cstr(fileCount +1) + ".doc"
Case Lcase("Microsoft Visio Drawing")
Filename =DetachFolder + "\Visio Drawing" + Format(doc.Created, "yyyy-mm-dd") + "_" + Cstr(fileCount +1) + ".vsd"
Case lcase("Excel Worksheet")
Filename =DetachFolder + "\ExcelWorksheet" + Format(doc.Created, "yyyy-mm-dd") + "_" + Cstr(fileCount +1) + ".xls"
---------------
Or
----------
Case Lcase("Microsoft Office Excel Worksheet"),lcase("Excel Worksheet")
Filename =DetachFolder + "\ExcelWorksheet" + Format(doc.Created, "yyyy-mm-dd") + "_" + Cstr(fileCount +1) + ".xls"
---------------
The Object property name may vary according to the software version release, and you may have other embedded documents from other programs. I added the case else statement so you can track them down and add them to your code during testing until you finally roll it out on the real thing.
Your final version may include several dozen object names. But give me a few hours, and perhaps I can create another agent that will poll all the types in the view for you.
End Function
Жаль так со встроенным PDF так не получится, но такого я еще не встречал.