更改表的第一行的行高度和段落线间距

发布于 2025-01-31 23:31:18 字数 714 浏览 3 评论 0原文

我将一组从Excel复制到Word,并格式化每个表格。

For t = 1 To 6
    With appWD.Selection.Tables(t)
        .TopPadding = 0
        .BottomPadding = 0
        .LeftPadding = 0.11
        .RightPadding = 0
        .Spacing = 0
        .AllowPageBreaks = True
        .AllowAutoFit = True
        .Rows.SetHeight RowHeight:=12, HeightRule:=2
    End With
Next t

为了容纳较大的字体,我需要更改第一行的行高度,并更改段落线间距。

这件代码无法做到这一点。

For t = 1 To 6
    With appWD.Selection.Tables(t).Rows(1)
        .SetHeight RowHeight:=18
        .ParagraphFormat.LineSpacing = 15
    End With
Next t

我正在Mac上运行Excel/Word 2016。

I copied a set of tables from Excel into Word and formatted each one.

For t = 1 To 6
    With appWD.Selection.Tables(t)
        .TopPadding = 0
        .BottomPadding = 0
        .LeftPadding = 0.11
        .RightPadding = 0
        .Spacing = 0
        .AllowPageBreaks = True
        .AllowAutoFit = True
        .Rows.SetHeight RowHeight:=12, HeightRule:=2
    End With
Next t

To accommodate a larger font, I need to change the row height of the first row and also to change the paragraph line spacing.

This piece of code fails to do this.

For t = 1 To 6
    With appWD.Selection.Tables(t).Rows(1)
        .SetHeight RowHeight:=18
        .ParagraphFormat.LineSpacing = 15
    End With
Next t

I'm running Excel/Word 2016 on a Mac.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

二智少女 2025-02-07 23:31:18

使用AppWD.Selection是糟糕的实践。您有一个要处理的开放文档,因此请直接参考。例如:

With wdDoc
  For t = 1 To 6
    With .Tables(t)
      .TopPadding = 0
      .BottomPadding = 0
      .LeftPadding = 0.11
      .RightPadding = 0
      .Spacing = 0
      .AllowPageBreaks = True
      .AllowAutoFit = True
      .Rows.SetHeight RowHeight:=12, HeightRule:=2
      .Rows(1).SetHeight RowHeight:=18, HeightRule:=1
      .Rows(1).Range.ParagraphFormat.LineSpacing = 15
    End With
  Next t
End With

请注意,第1行方法的合适的Heightrule参数包含。还请注意,所有处理都是在单个循环中完成的,而不是您使用的代码两个循环。

Using appWD.Selection is poor practice. You have an open document you want to work on, so reference that directly. For example:

With wdDoc
  For t = 1 To 6
    With .Tables(t)
      .TopPadding = 0
      .BottomPadding = 0
      .LeftPadding = 0.11
      .RightPadding = 0
      .Spacing = 0
      .AllowPageBreaks = True
      .AllowAutoFit = True
      .Rows.SetHeight RowHeight:=12, HeightRule:=2
      .Rows(1).SetHeight RowHeight:=18, HeightRule:=1
      .Rows(1).Range.ParagraphFormat.LineSpacing = 15
    End With
  Next t
End With

Note the the inclusion of the appropriate HeightRule argument for the Row 1 SetHeight method. Note also that all the processing is done in a single loop, rather than the two loops your code used.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文