`
minglelui
  • 浏览: 83648 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

读取RTF域中的Table

阅读更多

This code is designed to create a non-tabbed table of two rows and five columns in a rich text field to display information. I've added in static text but it could be used to display information from a document as well.

I've implemented this as an agent, as the code this came from was used in this way, but it could be a button, query open etc. You can use the same classes to create a tabbed table, but this tip doesn't do that. This code works with R6 and above only.

  
  Code: Sub Initialize
 Dim sess As New NotesSession
 Dim ws As New NotesUIWorkspace
 Dim dbCurr As NotesDatabase
 Dim docProcess As NotesDocument
 Dim dcProcess As NotesDocumentCollection
 
 Dim rtiItem As NotesRichTextItem
 
 Dim rtnav As NotesRichTextNavigator
 Dim rtt As NotesRichTextTable
 Dim rtsTableHeader As NotesRichTextStyle
 Dim rtsTableRow As NotesRichTextStyle
 
 Dim sData(4) As String
 Dim sHeaders(4) As String
 Dim sPrefix As String
 Dim iCtr As Integer
 Dim iRow As Integer
 Dim iCol As Integer
 
 'We declare an array of paragraph 
styles to pass in when creating the 
table
 Dim rtpsCols(4) As 
NotesRichTextParagraphStyle
 
 Set dbCurr = sess.CurrentDatabase
 Set dcProcess = 
dbCurr.UnprocessedDocuments
 
 If dcProcess.Count > 0 Then
  
  'These are display headers for the table
  sHeaders(0) = "Header 1"
  sHeaders(1) = "Header 2"
  sHeaders(2) = "Header 3"
  sHeaders(3) = "Header 4"
  sHeaders(4) = "Header 5"
  'An array of data for the Columns
  sData(0) = "Col 1"
  sData(1) = "Col 2"
  sData(2) = "Col 3"
  sData(3) = "Col 4"
  sData(4) = "Col 5"
  
  'Set up the text styles we want to 
use for displaying the text
  Set rtsTableHeader = 
sess.CreateRichTextStyle
  rtsTableHeader.FontSize = 10 
  rtsTableHeader.Bold = True
  Set rtsTableRow= 
sess.CreateRichTextStyle
  rtsTableRow.FontSize = 8
  rtsTableRow.Bold = False
  
  'Set up the paragraph styles for the table
  'The column widths are set 
by setting the left margin to 0 then 
the right margin to 
  'what the column width should be
  Set rtpsCols(0) = 
sess.CreateRichTextParagraphStyle
  'This column in left aligned
  rtpsCols(0).Alignment = 0
  rtpsCols(0).Firstlineleftmargin = 0
  rtpsCols(0).Leftmargin = 0
  rtpsCols(0).RightMargin = 
RULER_ONE_CENTIMETER * 7.51
  
  'This column is centre aligned
  Set rtpsCols(1) = 
sess.CreateRichTextParagraphStyle
  rtpsCols(1).Alignment =3
  rtpsCols(1).Firstlineleftmargin = 0
  rtpsCols(1).Leftmargin = 0
  rtpsCols(1).RightMargin = 
RULER_ONE_CENTIMETER * 1.43  
  Set rtpsCols(2) = 
sess.CreateRichTextParagraphStyle
  rtpsCols(2).Alignment =3  
  rtpsCols(2).Firstlineleftmargin = 0
  rtpsCols(2).Leftmargin = 0
  rtpsCols(2).RightMargin = 
RULER_ONE_CENTIMETER * 2.18  
  Set rtpsCols(3) = 
sess.CreateRichTextParagraphStyle
  rtpsCols(3).Alignment =3
  rtpsCols(3).Firstlineleftmargin = 0
  rtpsCols(3).Leftmargin = 0
  rtpsCols(3).RightMargin = 
RULER_ONE_CENTIMETER * 1.68
  
  Set rtpsCols(4) = 
sess.CreateRichTextParagraphStyle
  rtpsCols(4).Alignment =0
  rtpsCols(4).Firstlineleftmargin = 0
  rtpsCols(4).Leftmargin = 0
  rtpsCols(4).RightMargin =
 RULER_ONE_CENTIMETER * 10.73
  
  Set docProcess = dcProcess.GetFirstDocument
  While Not docProcess Is Nothing
   
   'I've used good old Body as my rich text field
   Set rtiItem = docProcess.GetFirstItem("Body")
   'The styles only have about three fonts that can be 
used by default
   'Arial isn't one of them so we have to 'Get' it from 
the rich text item
   'I don't really understand this but that's how it 
works...
   rtsTableHeader.NotesFont = rtiItem.GetNotesFont
("Arial", True)
   rtsTableRow.NotesFont = rtiItem.GetNotesFont("Arial", 
True)
   
   'We create the table, with 1 row, 5 columns, "" for the 
title, so it's not a tabbed table
   '1440 is the margin in twips, which is an inch, or 
2.54*567(which is a cm in twips)
   'rtpsCols is the array of rich text paragraph styles we 
set up earlier
   Call rtiItem.AppendTable(1,5,"",1440, rtpsCols)
   Call docProcess.Save(True,False)
   
   'In order to get the table elements we have to use a 
couple of methods
   'One is to get the table as a rich text table element
   'The other is just to get navigate to the columns so we 
can insert text
   
   'This element enables us to navigate through the rich 
text field
   Set rtnav = rtiItem.CreateNavigator
   
   'Get the table as a rich text table element so we can 
add rows
   Set rtt = rtnav.GetFirstElement(RTELEM_TYPE_TABLE)
   
   'Once you set a style the rich text field has that 
style until we say otherwise
   Call rtiItem.AppendStyle(rtsTableHeader)
   
   'This navigates us to the first table cell
   Call rtnav.FindFirstElement
(RTELEM_TYPE_TABLECELL) 
   For iCol = 1 To 5 Step 1
    'Add in our text then get the next cell
    Call rtiItem.BeginInsert(rtnav)
    Call rtiItem.AppendText(sHeaders(iCol-1))
    Call rtiItem.EndInsert
    Call rtnav.FindNextElement
(RTELEM_TYPE_TABLECELL)
   Next
   'Now we change the style to our row style
   Call rtiItem.AppendStyle(rtsTableRow)
   'Add a row, then go to the first cell in that row, 
which will be the next cell
   Call rtt.AddRow
   Call rtnav.FindNextElement
(RTELEM_TYPE_TABLECELL)
   For iCtr=0 To 4
    'Add in our text then get the next cell
    Call rtiItem.BeginInsert(rtnav)
    Call rtiItem.AppendText(sData(iCtr))
    Call rtiItem.EndInsert
    Call rtnav.FindNextElement
(RTELEM_TYPE_TABLECELL)
   Next
   Call rtt.AddRow
   Call rtnav.FindNextElement
(RTELEM_TYPE_TABLECELL)
   For iCtr=0 To 4
    Call rtiItem.BeginInsert(rtnav)
    Call rtiItem.AppendText(sData(iCtr))
    Call rtiItem.EndInsert
    Call rtnav.FindNextElement
(RTELEM_TYPE_TABLECELL)
   Next
   
   Call docProcess.Save(True,False)
   Set docProcess = 
dcProcess.GetNextDocument(docProcess)
  Wend
 End If
 
End Sub
分享到:
评论

相关推荐

    利用C#及RichTextBox简单实现Word域功能

    该方案允许将含有域的RTF内容存储在SQL Server数据库中。这不仅可以简化数据管理,还方便了多用户的协作编辑。数据库中包含两个表:`Table1`用于存储域对应的值,如姓名、性别等;`Table2`则用来保存RTF编码,以及...

    Word 2002 RTF Specification Final

    规格中提到的RTF读取器约定主要包括: - **兼容性**:确保读取器能够正确地解析来自不同版本的RTF文档。 - **错误处理**:定义了当遇到未知控制词或其他格式错误时,读取器应如何响应。 #### 正式语法 正式语法部分...

    PHPWord纯PHP库读写MicrosoftWord文档

    $table = $section->addTable(array('cellMargin' => 50)); for ($i = 0; $i ; $i++) { for ($j = 0; $j ; $j++) { $table->addRow(500); $table->addCell(1000)->addText("单元格($i,$j)"); } } ``` 5. **...

    RTFtoHTML.zip

    1. **解析RTF文件**:首先,程序需要读取RTF文件并理解其内部结构。RTF文件以特定的控制字符和组开始,这些控制字符指示了文本的格式信息。解析器会识别这些控制字符并将其映射到HTML相应的标签。 2. **转换格式...

    itext jar包

    而iText-rtf-2.1.7.jar则增加了对Rich Text Format (RTF)的支持,允许用户生成或读取RTF格式的文档,RTF是一种跨平台的文本格式,可以兼容多种文字处理软件,如Microsoft Word。 在压缩包的文件名称列表中,我们...

    delphi操作excel模块,图片,表格,读写删除

    为了轻松地创建多字体格式的单元,单元可以以RTF格式读写 VBA宏 可以读写文件中的宏,使用XLSReadWriteII可以为控件比如:按钮、组合框等添加宏 导入及导出 从下列导入数据… Open Office Calc文档 CSV文件...

    Java 生成word所需要包(完全,已经测试可用)

    通过iText rtf,Java开发者可以生成或读取RTF文档,这在需要与使用Microsoft Word的用户进行数据交换时非常有用。例如,你可以将程序生成的数据转换为具有格式化的RTF文件,然后让用户在他们熟悉的Word环境中查看或...

    Rich Text Format.docx

    富文本格式(Rich Text Format,简称RTF)是一种通用的文档格式,...它可以帮助创建出在多种环境中都能保持一致显示效果的文档,并且通过API接口,开发者可以方便地读取、写入和操作RTF数据,以实现更复杂的应用需求。

    Itext生成Word依赖.rar 亲测可用,最新

    RTF是一种跨平台的文本格式,可以被大多数文字处理软件(包括Microsoft Word)读取和写入。通过这个组件,Itext能够将内容转换为RTF格式,从而生成可由Word打开的文档。 使用Itext生成Word文档的基本步骤如下: 1....

    mysql或者Oracle通过表注释生成word数据库文档

    在MySQL中,可以通过`COMMENT ON TABLE`或`ALTER TABLE ... COMMENT`语句添加表注释;在Oracle中,可以使用`COMMENT ON TABLE`命令来实现相同功能。 生成Word文档的过程可能涉及到编程和数据库查询。可以使用Java...

    Itext导出Word文档的例子

    `itext-rtf-2.1.7.jar`是Itext的RTF(Rich Text Format)模块,它允许我们生成RTF格式的文档,RTF是一种通用的格式,可以被多种文字处理软件,包括Microsoft Word,所读取和写入。通过使用这个库,我们可以间接地将...

    Aspose Word使用总结

    首先,你需要在Word中创建一个模板文件(如Template.doc),并使用“插入→文档部件→域”插入MergeField来绑定数据。例如,你可以插入字段如“UserName”,“Gender”,“BirthDay”,“Address”等。 接下来,...

    C# axrichtextbox

    在`AxRichTextBox`中插入表格,我们可以使用`Range`对象的`InsertTable`方法。例如,以下代码会插入一个3行4列的表格: ```csharp AxRichTextBox1.Rtf = "{\\rtf1\\ansi\\deflang1033{\\fonttbl{\\f0\\fnil\\...

    xlsreadwriteII 4.0.0.52

    为了轻松地创建多字体格式的单元,单元可以以RTF格式读写 VBA宏 可以读写文件中的宏,使用XLSReadWriteII可以为控件比如:按钮、组合框等添加宏 导入及导出 从下列导入数据… Open Office Calc文档 CSV文件以及...

    itextpdf-5.4.3.jar java 转pdf 工具类 jar

    首先,`itextpdf-5.4.3.jar`是iText库的一个特定版本,它提供了Java程序员用来创建、编辑和读取PDF文档的API。这个库包含了丰富的功能,例如添加文本、图像、表格、链接,甚至复杂的表单和数字签名。 要开始使用...

    TX Text Control ActiveX 15.1 SP3

    TX Text Control ActiveX是一个字处理控件,能够读取,编写和创建行业标准的文档格式,如MS Word DOCX,DOC,RTF,HTML和XML,它还能够导出所有文档到打印就绪的Adobe PDF文档,而且不用第三方软件。TX Text Control...

    XLSReadWriteII v5.10.25 Cracked for XE2-XE4 (Win32)

    为了轻松地创建多字体格式的单元,单元可以以RTF格式读写 VBA宏 可以读写文件中的宏,使用XLSReadWriteII可以为控件比如:按钮、组合框等添加宏 导入及导出 从下列导入数据… •Open Office Calc文档 •CSV...

    ResourceBuilder.zip

    在提取资源方面,ResourceBuilder能够从已编译的EXE或DLL文件中读取并导出资源,这对于调试、分析或复用已有资源具有极大价值。开发者可以快速查找并导出特定的资源,无需深入了解二进制文件格式,极大地节省了时间...

Global site tag (gtag.js) - Google Analytics