最近,在我工作的公司,我需要将excel的大量订单导入我们的数据库,以便处理和发货。其中许多excel文档有数百列。我正在寻找一种干净的方法来将包含订单数据的多个行和列转换为SQL查询转储。
Here is what I'm working with.
每个订单都是由OrderID
标识的单行,每个产品的数量都在与ProductID
对应的单元格中定义。
我使用以下公式将每个单元格(如果已填充)转换为SQL查询的值:
=CONCATENATE(IF(ISBLANK(B3),"",("("&B3&", "&B$1&", "&$A3&"), ")))
每个填充单元格的结果如下:
(1, 22, 1),
我希望能够做到的是,每个单元将每个单元格(如果已填充)连接成一个长字符串,而不会有数百个列填充相同的公式。像这样:
(5, 12, 23), (5, 13, 23), (100, 7, 23), (50, 1, 23), (100, 3, 23),
感谢。
答案 0 :(得分:0)
试试这个 -
VBA代码
Function InsStr(Product As Range, Order As String, Qty As Range)
Dim tmpString As String: tmpString = ""
Dim tmpCount As Integer: tmpCount = 1
For Each cell In Qty
If cell <> "" Then
If tmpCount > 1 Then tmpString = tmpString & ","
tmpString = tmpString & "(" & cell & "," & Product(tmpCount) & "," & Order & ")"
End If
tmpCount = tmpCount + 1
Next cell
InsStr = tmpString
End Function
并将公式用作=InsStr(B1:X1,A3,B3:X3)