0

不确定这个问题的最佳表达方式..

这个问题是在我实施数据集成服务之前提出的,但为了了解知识 - 我有来自 Excel 电子表格的数据,需要输入到数据库中。示例列是;ID、姓名和街道。

在网络表单上有 3 个文本框。用户将从 Excel 电子表格中复制 ID 单元格,然后将其粘贴到网络表单的 ID 文本框中。然后从 Excel 电子表格中复制名称单元格并将其粘贴到网络表单的名称文本框中...等

我正在想办法从 Excel 电子表格中复制一整行并将其粘贴到网络表单上的一个文本框中。

我的第一次尝试是拆分()文本并创建字典。由于街道地址之间存在空格,这不起作用。有什么方法可以将 1 个文本框分成 3 个子字符串并保持街道字段中的完整性和空间?Name 和 Street 的数据类型是 varchar(30)。

'Example input of Textbox1.Text "1 myName Cheesecake Factory Lane"
    Dim words As String = TextBox1.Text
    Dim split As String() = words.Split(New [Char]() {" "c, ","c, "."c, ":"c, CChar(vbTab)})
    Dim rowData As New Dictionary(Of Integer, String)
    Dim i As Integer = 0

    For Each s As String In split

        If s.Trim() <> "" Then
          rowData.Add(i, s)
            i += 1
            ' output text for ID would be rowData.Item(0)
            'out text for Name would be rowData.Item(1)
            'out text for Street would be row.Data.Item(2)
        End If
    Next s
4

1 回答 1

0

Excel places several data formats on the clipboard.

The "Text" format delimits the cells with Tab and the rows with Cr. You would have to depend on the users to highlight the proper cells but you can easily split columns using Tab (or rows with vbcrLf.)

Here is some code to explore formats:

    Dim o As IDataObject = Clipboard.GetDataObject()
    Dim a() As String = o.GetFormats ' see what formats are available
    Dim x As Object = o.GetData("text") ' returns MemoryStreams so this isn't useful as written

    Dim s As String = Clipboard.GetText ' just get delimited text from Excel
于 2013-04-03T21:15:37.050 回答