2011-05-24 74 views
1

我编写了一个VBA脚本来创建&电子邮件的数据表。虽然它确实有效,但它也很难看。我想要做的一件事是调整这些列的大小,使它们不占据整个页面的宽度。如何使用VBA在Lotus中自动调整/调整表格的列大小?

“autosize column”选项会很好,除非我在API中看不到任何地方。另外,我打开手动设置每列的宽度。有人可以告诉我需要添加哪些代码吗?

Dim rtNav As NotesRichTextNavigator 
Dim rtTbl As NotesRichTextTable 
Dim TblHeader_FontStyle As NotesRichTextStyle 
Dim TblBody_BackgroundStyle As NotesRichTextStyle 
Dim TblHeader_BackgroundStyle As NotesColorObject 
Dim TblBody_FontStyle As NotesColorObject 

Sub AppendTable() 
'Define styles 
    Set TblHeader_BackgroundStyle = NtSession.CreateColorObject 
     TblHeader_BackgroundStyle.NotesColor = COLOR_DARK_BLUE 
    Set TblHeader_FontStyle = NtSession.CreateRichTextStyle 
     TblHeader_FontStyle.NotesColor = COLOR_WHITE 
     TblHeader_FontStyle.FontSize = 8 

    Set TblBody_FontStyle = NtSession.CreateColorObject 
     TblBody_FontStyle.NotesColor = COLOR_WHITE 
    Set TblBody_BackgroundStyle = NtSession.CreateRichTextStyle 
     TblBody_BackgroundStyle.NotesColor = COLOR_BLACK 
     TblBody_BackgroundStyle.FontSize = 10 
'----------------------------------------------------- 
'Make table structure 
    NtBod.AppendTable lRowCount:=1, lColumnCount:=5 
    Set rtNav = NtBod.CreateNavigator 
    Set rtTbl = rtNav.GetFirstElement(RTELEM_TYPE_TABLE) 
    rtTbl.Style = TABLESTYLE_TOP 
    Call NtBod.AppendStyle(TblHeader_FontStyle) 
    Call rtTbl.SetColor(TblHeader_BackgroundStyle) 
    rtNav.FindFirstElement (RTELEM_TYPE_TABLECELL) 
'The rest of the procedure to navigate the table and insert the data goes here 

回答

1

AppendTable方法中有一个参数,用于指定每列的样式,包括宽度。

从AppendTable方法的文档:

呼叫 notesRichTextItem。 AppendTable(行%, 列%[,标签] [,LEFTMARGIN &] [,rtpsStyleArray])

参数:
行%整数。表中的行数。

列%整数。表格中的列数。

标签 String类型的数组。可选的。标签文本标签为 表格。数组元素 的数量必须等于行数。 省略此参数会附加 基本表。包含此参数 会附加一个选项卡式表格。

leftMargin &长。可选的。桌子的左边缘以缇为单位。 默认为1440以下 常数是可用的:

  • RULER_ONE_CENTIMETER(567)
  • RULER_ONE_INCH(1440)

rtpsStyleArray阵列型NotesRichTextParagraphStyle的。可选的。 创建一个固定宽度 列和样式属性为 的表格。省略此参数 将创建一个自动宽度表。 数组必须按顺序包含表中每列的 的一个元素。 明确设置第一行左边距 和左边距,其中控制 开始的文字相对于 列的开始,右边的 边距,它控制列的宽度。

+0

这就是我一直在寻找的。我有一段时间没有在这个代码上工作,所以我有点生疏。 – PowerUser 2011-05-24 19:17:56

+0

@PowerUser,很高兴听到它! – 2011-05-24 19:25:15