TextFileColumnDataTypes 属性 (Excel)QueryTable.TextFileColumnDataTypes property (Excel)

返回或设置一个有序的常量数组, 这些常量指定应用于要导入到查询表的文本文件中的相应列的数据类型。Returns or sets an ordered array of constants that specify the data types applied to the corresponding columns in the text file that you are importing into a query table. 每一列的默认常量为 xlGeneralThe default constant for each column is xlGeneral. 读/写 VariantRead/write Variant.

语法Syntax

表达式TextFileColumnDataTypesexpression.TextFileColumnDataTypes

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

说明Remarks

使用**XlColumnDataType** 常量指定在数据导入过程中使用的列数据类型或执行的操作。Use the XlColumnDataType constants to specify the column data types used or the actions taken during the data import.

仅当查询表基于文本文件中的数据 ( QueryType 属性设置为xlTextImport) 时, 才使用此属性。Use this property only when your query table is based on data from a text file (with the QueryType property set to xlTextImport).

如果您在数组中指定的元素数多于列数, 则这些值将被忽略。If you specify more elements in the array than there are columns, those values are ignored.

仅当安装并选择中文 (台湾) 语言支持时, 才使用xlEMDFormatUse xlEMDFormat only if Chinese (Taiwan) language support is installed and selected. XlEMDFormat常量指定使用中文 (台湾) 的纪元日期。The xlEMDFormat constant specifies that Chinese (Taiwan) era dates are used.

如果使用用户界面导入数据, 则会将来自 web 查询或文本查询的数据作为一个查询表**** 对象导入, 而将所有其他外部数据作为**ListObject** 对象导入。If you import data by using the user interface, data from a web query or a text query is imported as a QueryTable object, while all other external data is imported as a ListObject object.

如果使用对象模型导入数据, 则必须将来自 web 查询或文本查询的数据作为查询表导入****, 而所有其他外部数据均可作为ListObject或查询表导入。 ****If you import data by using the object model, data from a web query or a text query must be imported as a QueryTable, while all other external data can be imported as either a ListObject or a QueryTable.

TextFileColumnDataTypes 属性仅适用于 QueryTable 对象。The TextFileColumnDataTypes property applies only to QueryTable objects.

示例Example

本示例向第一个工作簿中第一张工作表上的新查询表中导入一个固定宽度的文本文件。This example imports a fixed-width text file into a new query table on the first worksheet in the first workbook. 该文本文件的第一列为五个字符宽度,作为文本导入。The first column in the text file is five characters wide and is imported as text. 第二列为四个字符宽度,被跳过。The second column is four characters wide and is skipped. 该文本文件的剩余部分被导入第三列,并对其应用常规格式。The remainder of the text file is imported into the third column and has the General format applied to it.

Set shFirstQtr = Workbooks(1).Worksheets(1) 
Set qtQtrResults = shFirstQtr.QueryTables _ 
 .Add(Connection := "TEXT;C:\My Documents\19980331.txt", _ 
 Destination := shFirstQtr.Cells(1, 1)) 
With qtQtrResults 
 .TextFileParseType = xlFixedWidth 
 .TextFileFixedColumnWidths = Array(5, 4) 
 .TextFileColumnDataTypes = _ 
 Array(xlTextFormat, xlSkipColumn, xlGeneralFormat) 
 .Refresh 
End With

支持和反馈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.