Convert XLS to tab delimited.

本文介绍了一种使用ADO和Jet OLEDB提供程序读取Excel文件内容的方法,无需实际打开Excel。通过VB.NET代码示例,展示了如何连接到Excel文件,执行SQL查询,将数据导出到文本文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Use ADO and the Jet OLEDB provider, which can read the contents of excel files without actually opening Excel.

Example:

'*******************************
Public Sub ConvertXLSToTab(ByVal xlsFileName As StringByVal tabTextOutputFile As String
        Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & xlsFileName & "';Extended Properties='Excel 12.0;HDR=YES';"
        Dim strSQL As String = "SELECT * FROM [Sheet1$]"
        Dim excelConnection As OleDb.OleDbConnection = New OleDb.OleDbConnection(connectionString)
        excelConnection.Open()
        Dim dbCommand As OleDbCommand = New OleDbCommand(strSQL, excelConnection)
        Dim dataAdapter As OleDbDataAdapter = New OleDbDataAdapter(dbCommand)
        Dim ds As New DataSet
        dataAdapter.Fill(ds, "dTable")
        'DataGridView1.DataSource = ds.Tables("dTable").DefaultView
        Dim strLine As String
        Dim objStreamWriter As StreamWriter
        objStreamWriter = File.CreateText(tabTextOutputFile)
        For Each row As DataRow In ds.Tables("dTable").Rows
            Dim column As DataColumn
            strLine = ""
            For Each column In ds.Tables("dTable").Columns
                If (strLine <> ""Then strLine = strLine & vbTab
                strLine = strLine & row(column).ToString()
            Next column
            objStreamWriter.WriteLine(strLine)
        Next row
        excelConnection.Close()
        objStreamWriter.Close()
    End Sub

转载于:https://www.cnblogs.com/yangbin990/archive/2006/09/25/514477.html

### LabVIEW 中读取分隔符分隔电子表格的 VI 在 LabVIEW 中,`Read Delimited Spreadsheet.vi` 是一个内置的功能模块,专门设计用来处理由特定字符(如逗号、制表符或其他自定义分隔符)分割的数据文件[^1]。此功能允许用户轻松导入 CSV 或其他类似的结构化数据到程序中。 #### 使用 `Read Delimited Spreadsheet.vi` 以下是关于如何配置和使用该 VI 的一些重要细节: - **输入参数** 此 VI 需要指定路径名作为其主要输入之一,表示目标电子表格的位置[^2]。此外,还可以设置选项来控制解析行为,例如分隔符的选择以及是否跳过首行等内容。 - **输出结果** 输出通常是一个二维数组形式的结果集,其中每一行代表原始文档的一行记录,而每列则对应于各个字段值[^3]。 下面提供了一个简单的代码示例展示如何调用这个子VI并显示所得到的数据矩阵: ```labview // Load the Read Delimited Spreadsheet VI from Functions Palette -> File I/O category. // Set Path to your target file (e.g., C:\data.csv). // Optionally configure delimiter and other settings as needed. // Example Code Block Below Demonstrates Basic Usage: Path = "C:/example_data.txt"; // Specify full path here Delimiter = ","; // Define appropriate separator character(s) Call Library Node { // Insert 'Read Delimited Spreadsheet' node into block diagram area Input Parameters { Filename: Path, Separator: Delimiter } } Display Data Matrix On Front Panel; ``` 上述脚本片段展示了加载外部CSV文件并将内容呈现给用户的流程概述[^4]。 #### 常见注意事项 当操作此类工具时需要注意几个方面以确保最佳性能与准确性: - 文件编码可能影响某些特殊字符的表现方式; - 如果存在缺失单元格,则返回阵列可能会填充默认数值零或者空白字符串视具体情况而定; 通过以上介绍可以了解基本应用方法及其特性描述。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值