可以在 Publisher 中生成目录吗?

可以在 Publisher 中生成目录吗?

我已经在大多数页面上输入了大量带有标题的内容。我想根据这些标题创建一个生成的目录。这可行吗?如果可以,我该怎么做?

答案1

我想根据这些标题创建一个生成的目录

您无法自动创建目录 - Publisher 中不提供此功能。

以下说明向您展示如何手动创建目录。看起来您必须复制并粘贴标题...

在 Publisher 中插入目录

只需多做一点工作,就能在 Publisher 中创建目录,而且回报丰厚。首先添加一个文本框,然后使用带前导符的右对齐制表符。前导符是目录中章节或节标题后面的点、破折号或线,用于将这些标题与页码对齐。

使用制表位和前导符创建目录 (TOC)。

  1. 单击“主页”>“绘制文本框”。

  2. 在出版物中,单击希望文本一角出现的位置,然后沿对角线拖动,直到获得所需的框大小。

  3. 键入目录的标题,然后按 ENTER。

  4. 双击要显示页码的水平标尺。

  5. 在“制表符”对话框中,单击“右”,选择“引线”样式,然后单击“确定”。

  6. 现在输入您的目录条目;例如:第 1 章,按 TAB 插入前导符并输入页码。

来源在 Publisher 中插入目录

答案2

来到这里寻找同事问题的快速解决方案,但在其他地方找不到解决方案,因此发布了我自己的解决方案,在装有 Publisher 2010 的 Win7 上使用 PowerShell 版本 5 脚本模拟 TOC。

目录添加在第 2 页和第 3 页之间,其中第 1 页是标题封面,第 2 页是欢迎页。标题始终是文本框形状 1。为了保持对齐样式,目录使用等宽字体。

如果您使用标准发布者页面部分标题,则以下内容可以替代变量 $TOCAdd

$Heading_Geometric_Title_Text = $Publisher.ActiveDocument.Pages($pge).Shapes(1).GroupItems[3].TextFrame.TextRange.Text
$Heading_Geometric_Subtitle_Text = $Publisher.ActiveDocument.Pages($pge).Shapes(1).GroupItems[2].TextFrame.TextRange.Text

$Heading_Brackets_Title_Text = $Publisher.ActiveDocument.Pages($pge).Shapes(1).GroupItems[2].TextFrame.TextRange.Text
$Heading_Brackets_Subtitle_Text = $Publisher.ActiveDocument.Pages($pge).Shapes(1).GroupItems[5].TextFrame.TextRange.Text

$Heading_Pure_Title_Text = $Publisher.ActiveDocument.Pages($pge).Shapes(1).GroupItems[3].TextFrame.TextRange.Text
$Heading_Pure_Subtitle_Text = $Publisher.ActiveDocument.Pages($pge).Shapes(1).GroupItems[2].TextFrame.TextRange.Text

#

# Path to Publisher document
$FileName = "$env:USERPROFILE\Documents\Publication_1.pub"
$Publisher=NEW-Object –comobject Publisher.Application

# Following line sets whether file is opened visible or not.
$Publisher.ActiveWindow.visible = 1

# Open Publisher Document
$Publisher.open($FileName)

# Check how Many Pages in document
$count = $Publisher.ActiveDocument.Pages.Count

# How Many TOC Pages required in document for the amount of titles (assume 17 per page)
    $TOCPages = [math]::Round($count/17)

# New Page Count including TOC required in document
    $countINC = $count += $TOCPages

# Add TOC pages required insert Page(s) after last Pre page 
    $Pre = 2
    IF ($TOCPages -ge 1) {
    ForEach ( $n in 1..$TOCPages){
    $Publisher.ActiveDocument.Pages.Add(1,$Pre)
    }

# Add table on TOC Pages
    ForEach ( $n In 1..$TOCPages){
# Insert New Toc from this page No 
    $n += $Pre

# Insert table on the new TOC page with  NumRows:=17, NumColumns:=3, Left:=50, Top:=70, Width:=600, Height:=300
    $TOCPage = $Publisher.ActiveDocument.Pages($n).Shapes.AddTable( 17, 3, 50, 75, 600, 300)
# Adjust column widths for table (shape)
    $TOCPage.Table.Columns(1).width = 30  #Item No
    $TOCPage.Table.Columns(2).width = 450 #Item
    $TOCPage.Table.Columns(3).width = 70  #Page No

    #Add Text Box Standard Text (type 1) adjust font size then make it Bold
    $TOCTitle = $Publisher.ActiveDocument.Pages($n).Shapes.AddTextbox(1, 360,  26, 150, 25)
    $TOCIndex = ($n -= ($Pre))
    $TOCTitle.TextFrame.TextRange.Text = "Table of Contents $TOCIndex"
    $TOCTitle.TextFrame.TextRange.Font.Size = 14
    $TOCTitle.TextFrame.TextRange.Font.Bold = 1 
    } 
    }
# Identify first page after TOC
    $start = $TOCPages += ($Pre += 1)
# Create TOC Array (Fixed Content First) append to fixed length Char 46 (period)
    $TOCROW1 = 'Title Page'
    $TOCROW2 = 'Welcome to the Catalogue'
    $TOCROW3 = 'Table of Contents'
    $TOCArray = @()
    $TOCRow = "" | Select 'Table of Contents','PageNo'
    $TOCRow.'Table of Contents' = $TOCROW1.PadRight(60,[char]46)
    $TOCRow.PageNo = 1
    $TOCArray = $TOCArray + $TOCRow
    $TOCRow = "" | Select 'Table of Contents','PageNo'
    $TOCRow.'Table of Contents' = $TOCROW2.PadRight(60,[char]46)
    $TOCRow.PageNo = 2
    $TOCArray = $TOCArray + $TOCRow
    $TOCRow = "" | Select 'Table of Contents','PageNo'
    $TOCRow.'Table of Contents' = $TOCROW3.PadRight(60,[char]46)
    $TOCRow.PageNo = 3
    $TOCArray = $TOCArray + $TOCRow

# Use try / catch for page shapes returning error
    try { 
    ForEach ($pge in $Start..$countINC){
    IF ($pge -eq "" ){ Write-Host "Debug"}
    Else{ # Add TOC Array Entries

    $TOCAdd = $Publisher.ActiveDocument.Pages($pge).Shapes(1).TextFrame.TextRange.Text 
    $TOCRow = "" | Select 'Table of Contents','PageNo';
    $TOCRow.'Table of Contents' = $TOCAdd.PadRight(60,[char]46)
    $TOCRow.PageNo = $pge
    $TOCArray = $TOCArray + $TOCRow
    }
 }
}

    catch { }

# Debug uncomment following line to View Output of 'Table of Contents' based on the data added in Array variable 'TOCArray'
#    $TOCArray | Format-Table -Wrap -Property 'Table of Contents','PageNo'

# Add TOC entries to TOC (uses monospaced font to get alignment)
    $n = 2
    $q = -1
    $Item =0
    ForEach ($TOC in 1..$TOCPages) {
     $n++
     $q++
     $Row = 0
     $Offset = ($q * $Range)
     $Range  = 17
     $TOCArray | Select-Object -Skip $Offset -First $Range -Property 'Table of Contents','PageNo'| 
    ForEach-Object { 
      $Row++
      $Item++
      $TOCEntry = $Publisher.ActiveDocument.Pages($n).Shapes(1).Table.Rows($Row).Cells(1);
      $TOCEntry.TextRange.Text = "$Item";
      $TOCEntry.TextRange.Font.Size = 12;
      $TOCEntry.TextRange.Font.Bold = 1;
      $TOCEntry.TextRange.Font.Name = 'Consolas';
      $TOCEntry = $Publisher.ActiveDocument.Pages($n).Shapes(1).Table.Rows($Row).Cells(2);
      $TOCEntry.TextRange.Text = $_.'Table of Contents'.replace("`r","").ToString()
      $TOCEntry.TextRange.Font.Size = 12;
      $TOCEntry.TextRange.Font.Bold = 1;
      $TOCEntry.TextRange.Font.Name = 'Consolas';
      $TOCEntry = $Publisher.ActiveDocument.Pages($n).Shapes(1).Table.Rows($Row).Cells(3);
      #Need to Convert PageNo stored as System.Int32 to String
      $TOCEntry.TextRange.Text = $_.PageNo.ToString()
      $TOCEntry.TextRange.Font.Size = 12;
      $TOCEntry.TextRange.Font.Bold = 1;
      $TOCEntry.TextRange.Font.Name = 'Consolas';
     }
    }
# Save File (and increment versions), then close.
    $v++
    $file = $Publisher.ActiveDocument.Name
    $BaseName = $file.Substring(0, $file.LastIndexOf('.'))
    $strFileName = $BaseName + "_v1" + $v
    $Publisher.ActiveDocument.SaveAs($strFileName)
    $Publisher.ActiveDocument.Close()
    $Publisher.quit()
    [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Publisher)

相关内容