实现Notes File-Export功能,已提供基本解决方案,望大家讨论!
在IBM Lotus Notes可使用File-Export导出Notes Document为ms rtf,如下图:我尝试使用Lotus C++ api实现这一功能,部分代码如下:
try
{
session.Init();
session.GetDatabase("RTFCon.nsf", &db,"mycom");
if(!db.IsOpen())
{
db.Open(); // Open the database
}
db.GetDocuments(&docArr);
count = docArr.GetCount();
for (index = 0;index < count;index++)
{
curDoc = docArr[index];
curDoc.Open();
if (curDoc.HasItem("$Body"))
{
curDoc.GetItem("$Body",&rt);
}
rt.GetCursor(&startCursor);
rt.GetEndCursor(&endCursor);
rt.Export("c:\\test.rtf",startCursor,endCursor,"RTF");
}
db.Close(); //
}
catch (LNSTATUS error)
{
char errorBuf[LNERROR_MESSAGE_LENGTH];
LNGetErrorMessage(error, errorBuf);
cout << "Error: " << errorBuf << endl;
}
打开test.rtf如图:
对比发现了少了MainTopic以及下面附件图标等信息,在我的代码中我只获取body的richtext进行export导致部分数据丢失,但是同时又无法以NotesDocument为对象获取richtext进而进行export。
网上找到该代码类似于我所实现的功能,代码如下:
Option Public
Option Explicit
Const APIModule = "NNOTES"
Declare Function MailGetMessageBodyComposite Lib APIModule Alias "MailGetMessageBodyComposite" ( Byval hNT As Long, Byval N As String, Byval D As String, nD As Long) As Integer
Declare Function ExportRTF Lib "nxrtf" Alias "ExportRTF" (Byval sTempFile As String, Byval flags As Long, hmod As Long, Byval altlibrary As String, Byval sRTFFile As String) As Integer
Sub Initialize
Const workdir="c:\temp\"
Const OutputName=workdir & "Message_Body.rtf"
Const tempRTF=workdir & "rtf.cd"
Const tempFONTS=workdir & "fonts.cd"
Const tempBODY=workdir & "body.fcd"
Dim session As New notessession
Dim db As notesdatabase
Dim dc As notesdocumentcollection
Dim doc As notesdocument
Dim rtBody As notesrichtextitem
Dim fileSize As Long
Dim docnum As Integer
Dim process As Integer
Set db=session.Currentdatabase
Set dc=db.Unprocesseddocuments
' Write the Body field out to a file in CD format
Call MailGetMessageBodyComposite(Doc.handle , "Body", tempRTF, fileSize)
' Write the $fonts field out to a file in CD format
Call MailGetMessageBodyComposite(Doc.handle , "$Fonts", tempFONTS, fileSize)
'Join the two into one CD file, stripping off control word from second file.
Call concatenate (tempRTF,tempFONTS,tempBODY)
'Take CD file and call DLL used by client File | Export to create RTF file
Call ExportRTF(tempBODY, 0, 0, "", OutputName )
Kill tempRTF
Kill tempFONTS
Kill tempBODY
Set rtBody=doc.getfirstitem("Body")
Call rtbody.AddNewLine( 1 )
Call rtBody.EmbedObject(EMBED_ATTACHMENT,"",OutputName,"")
Kill OutputName
Call doc.Save(False,False)
Next
End Sub
Sub concatenate (fileIn1 As String, fileIn2 As String, fileOut1 As String)
'Takes two CD record format files and adds them into one file using binary file access
' First two bytes (one word) of file is control character so this is stripped from second file
' there is always even number of bytes in CD-records so we can use Integer so transfer the data
Dim twobytes As Integer
Dim filein As Integer
Dim fileout As Integer
fileout = Freefile
Open fileOut1 For Binary As #fileout
filein = Freefile
Open fileIn1 For Binary As #filein
Do Until Eof (filein)
Get #filein,,twobytes
Put #fileout,, twobytes
Loop
Close #filein
Open fileIn2 For Binary As #filein
Seek #filein, 3
Do Until Eof (filein)
Get #filein,,twobytes
Put #fileout,, twobytes
Loop
Close
End Sub
大概可见是采用分别导出Body,$Font为cd文件进而合并为一个文件,然后采用api进行convert,我并未尝试该代码是否可用以及导出结果是否等同于File-Export。
--------------------编程问答-------------------- [img=http://picasaweb.google.com/workWang/Else/photo#5236100415186189074][/img]
图片太小,补发
[img=http://picasaweb.google.com/workWang/Else/photo#5236100411362709202][/img] --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- 为什么我用这个方法(第一种),无法将引入的gif图片导出来,bmp的图片到出来后也变成了黑白色? --------------------编程问答-------------------- 你的notes 版本是6.5以上的吧?
--------------------编程问答-------------------- 是的 --------------------编程问答-------------------- 对于高版本的lotus存在这个问题,目前我还没有解决办法。
--------------------编程问答-------------------- 如果是多个tif图片用第一种方法能导出来吗
补充:企业软件 , Lotus