ConvertToTable 方法 (Word)Selection.ConvertToTable method (Word)

将范围内的文本转换为表格。Converts text within a range to a table. 作为 对象返回的表。Returns the table as a Table object.


表达式ConvertToTable(分隔符NumRowsNumColumnsInitialColumnWidthFormatApplyBordersApplyShadingApplyFontApplyColorApplyHeadingRowsApplyLastRowApplyFirstColumnApplyLastColumn自动调整AutoFitBehaviorDefaultTableBehavior)expression.ConvertToTable (Separator, NumRows, NumColumns, InitialColumnWidth, Format, ApplyBorders, ApplyShading, ApplyFont, ApplyColor, ApplyHeadingRows, ApplyLastRow, ApplyFirstColumn, ApplyLastColumn, AutoFit, AutoFitBehavior, DefaultTableBehavior)

_表达式_一个代表**Selection** 对象的变量。expression A variable that represents a Selection object.


名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
SeparatorSeparator 可选Optional VariantVariant 指定用于将文本分隔成单元格的字符。Specifies the character used to separate text into cells. 可以是一个字符或以下的 WdTableFieldSeparator 常量之一。Can be a character or one of the following WdTableFieldSeparator constant. 如果省略此参数,则使用 DefaultTableSeparator 属性的值。If this argument is omitted, the value of the DefaultTableSeparator property is used.
NumRowsNumRows 可选Optional VariantVariant 表格中的行数。The number of rows in the table. 如果省略此参数,Microsoft Word 将根据该范围的内容设置行数。If this argument is omitted, Microsoft Word sets the number of rows, based on the contents of the range.
NumColumnsNumColumns 可选Optional VariantVariant 表格中的列数。The number of columns in the table. 如果省略此参数,Word 将根据该范围的内容设置列数。If this argument is omitted, Word sets the number of columns, based on the contents of the range.
InitialColumnWidthInitialColumnWidth 可选Optional VariantVariant 每一列的初始宽度,以磅为单位。The initial width of each column, in points. 如果省略此参数,Word 将计算并调整列宽,以使表格填满页面。If this argument is omitted, Word calculates and adjusts the column width so that the table stretches from margin to margin.
FormatFormat 可选Optional VariantVariant 指定 表格自动套用格式对话框中列出的预定义格式之一。Specifies one of the predefined formats listed in the Table AutoFormat dialog box. 可以是 WdTableFormat 常量之一。Can be one of the WdTableFormat constants.
ApplyBordersApplyBorders 可选Optional VariantVariant 应用指定格式的边框属性。True to apply the border properties of the specified format.
ApplyShadingApplyShading 可选Optional VariantVariant 应用指定格式的底纹属性。True to apply the shading properties of the specified format.
ApplyFontApplyFont 可选Optional VariantVariant 应用指定格式的字体属性。True to apply the font properties of the specified format.
ApplyColorApplyColor 可选Optional VariantVariant 应用指定格式的颜色属性。True to apply the color properties of the specified format.
ApplyHeadingRowsApplyHeadingRows 可选Optional VariantVariant 应用指定格式的标题行的属性。True to apply the heading-row properties of the specified format.
ApplyLastRowApplyLastRow 可选Optional VariantVariant 应用指定格式的最后一行的属性。True to apply the last-row properties of the specified format.
ApplyFirstColumnApplyFirstColumn 可选Optional VariantVariant 应用指定格式的第一列的属性。True to apply the first-column properties of the specified format.
ApplyLastColumnApplyLastColumn 可选Optional VariantVariant 应用指定格式的最后一列的属性。True to apply the last-column properties of the specified format.
AutoFitAutoFit 可选Optional VariantVariant 要减少尽最大可能的表格列的宽度,而无需更改文字换行的单元格中。True to decrease the width of the table columns as much as possible without changing the way text wraps in the cells.
AutoFitBehaviorAutoFitBehavior 可选Optional VariantVariant 设置 Word 调整表格的大小的自动调整规则。Sets the AutoFit rules for how Word sizes a table. 可以是下列的 WdAutoFitBehavior 常量之一。Can be one of the following WdAutoFitBehavior constant. 如果 DefaultTableBehavior 是 wdWord8TableBehavior ,则忽略此参数。If DefaultTableBehavior is wdWord8TableBehavior, this argument is ignored.
DefaultTableBehaviorDefaultTableBehavior 可选Optional VariantVariant 设置一个值,指定是否 Microsoft Word 会自动调整大小以适合内容 (自动调整) 表中的单元格。Sets a value that specifies whether Microsoft Word automatically resizes cells in a table to fit the contents (AutoFit). 可以是一个 WdDefaultTableBehavior 常量。Can be one of the WdDefaultTableBehavior constant.

返回值Return value



以下示例在插入点插入文本,然后将逗号分隔的文本转换为带格式的表格。This example inserts text at the insertion point and then converts the comma-delimited text to a table with formatting.

With Selection 
 .InsertBefore "one, two, three" 
 .InsertAfter "one, two, three" 
End With 
Set myTable = Selection.ConvertToTable( _ 
 Separator:=wdSeparateByCommas, _ 

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.