Share via


Bookmark.ConvertToTable Method

Definition

Converts text within a Bookmark control to a table.

public Microsoft.Office.Interop.Word.Table ConvertToTable (ref object Separator, ref object NumRows, ref object NumColumns, ref object InitialColumnWidth, ref object Format, ref object ApplyBorders, ref object ApplyShading, ref object ApplyFont, ref object ApplyColor, ref object ApplyHeadingRows, ref object ApplyLastRow, ref object ApplyFirstColumn, ref object ApplyLastColumn, ref object AutoFit, ref object AutoFitBehavior, ref object DefaultTableBehavior);
abstract member ConvertToTable : obj * obj * obj * obj * obj * obj * obj * obj * obj * obj * obj * obj * obj * obj * obj * obj -> Microsoft.Office.Interop.Word.Table
Public Function ConvertToTable (Optional ByRef Separator As Object, Optional ByRef NumRows As Object, Optional ByRef NumColumns As Object, Optional ByRef InitialColumnWidth As Object, Optional ByRef Format As Object, Optional ByRef ApplyBorders As Object, Optional ByRef ApplyShading As Object, Optional ByRef ApplyFont As Object, Optional ByRef ApplyColor As Object, Optional ByRef ApplyHeadingRows As Object, Optional ByRef ApplyLastRow As Object, Optional ByRef ApplyFirstColumn As Object, Optional ByRef ApplyLastColumn As Object, Optional ByRef AutoFit As Object, Optional ByRef AutoFitBehavior As Object, Optional ByRef DefaultTableBehavior As Object) As Table

Parameters

Separator
Object

Specifies the character used to separate text into cells. Can be a character or one of the following WdTableFieldSeparator constants: wdSeparateByCommas, wdSeparateByDefaultListSeparator, wdSeparateByParagraphs, or wdSeparateByTabs.If this argument is omitted, the value of the DefaultTableSeparator property is used.

NumRows
Object

The number of rows in the table. If this argument is omitted, Microsoft Office Word sets the number of rows, based on the contents of the Bookmark control.

NumColumns
Object

The number of columns in the table. If this argument is omitted, Word sets the number of columns, based on the contents of the Bookmark control.

InitialColumnWidth
Object

The initial width of each column, in points. If this argument is omitted, Word calculates and adjusts the column width so that the table stretches from margin to margin.

Format
Object

Specifies one of the predefined formats listed in the Table AutoFormat dialog box. Can be one of the WdTableFormat constants.

ApplyBorders
Object

true to apply the border properties of the specified format.

ApplyShading
Object

true to apply the shading properties of the specified format.

ApplyFont
Object

true to apply the font properties of the specified format.

ApplyColor
Object

true to apply the color properties of the specified format.

ApplyHeadingRows
Object

true to apply the heading-row properties of the specified format.

ApplyLastRow
Object

true to apply the last-row properties of the specified format.

ApplyFirstColumn
Object

true to apply the first-column properties of the specified format.

ApplyLastColumn
Object

true to apply the last-column properties of the specified format.

AutoFit
Object

true to decrease the width of the table columns as much as possible without changing the way text wraps in the cells.

AutoFitBehavior
Object

Sets the AutoFit rules for how Word sizes a table. Can be one of the following WdAutoFitBehavior constants: wdAutoFitContent, wdAutoFitFixed, wdAutoFitWindow. If DefaultTableBehavior is wdWord8TableBehavior, this argument is ignored.

DefaultTableBehavior
Object

Sets a value that specifies whether Word automatically resizes cells in a table to fit the contents (AutoFit). Can be one of the following WdDefaultTableBehavior constants: wdWord8TableBehavior, wdWord9TableBehavior.

Returns

A Table.

Examples

The following code example adds a Bookmark control with text to the document and then converts the text in the bookmark to a table.

This example is for a document-level customization.

private void BookmarkConvertToTable()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    Microsoft.Office.Tools.Word.Bookmark bookmark1 =
        this.Controls.AddBookmark(this.Paragraphs[1].Range,
        "bookmark1");
    bookmark1.Text = "1,2,3,4,5,6";

    object Separator = Word.WdTableFieldSeparator.wdSeparateByCommas;
    object Format = Word.WdTableFormat.wdTableFormatClassic1;
    object ApplyBorders = true;
    object AutoFit = true;
    object AutoFitBehavior = Word.WdAutoFitBehavior.wdAutoFitContent;

    Word.Table Table1 = bookmark1.ConvertToTable(ref Separator,
        ref missing, ref missing, ref missing, ref Format,
        ref ApplyBorders, ref missing, ref missing, ref missing,
        ref missing, ref missing, ref missing,
        ref missing, ref AutoFit, ref AutoFitBehavior,
        ref missing);
}
Private Sub BookmarkConvertToTable()

    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Dim Bookmark1 As Microsoft.Office.Tools.Word.Bookmark = _
        Me.Controls.AddBookmark(Me.Paragraphs(1).Range, "Bookmark1")

    Bookmark1.Text = "1,2,3,4,5,6"

    Dim Table1 As Word.Table = Bookmark1.ConvertToTable( _
        Separator:=Word.WdTableFieldSeparator.wdSeparateByCommas, _
        Format:=Word.WdTableFormat.wdTableFormatClassic1, _
        ApplyBorders:=True, AutoFit:=True, AutoFitBehavior:= _
        Word.WdAutoFitBehavior.wdAutoFitContent)

End Sub

Remarks

Optional Parameters

For information on optional parameters, see Optional Parameters in Office Solutions.

Applies to