我有同样的问题,我已经部分解决了。列的顺序对于此工作很重要。
如果第一行是标题,则可以轻松地将列作为 SQL 导入,并且可以按任意顺序:
SELECT Col1 AS [DBCol1],
Col2 AS [DBCol2],
Col3 AS [DBCol3],
Col4 AS [DBCol4],
Col5 AS [DBCol5],
Col6 AS [DBCol6]
FROM SheetName$
如果第一行不是标题,则列的顺序很重要。它可以从 SQL 导入为:
SELECT F1 AS [DBCol1],
F2 AS [DBCol2],
F3 AS [DBCol3],
F4 AS [DBCol4],
F5 AS [DBCol5],
F6 AS [DBCol6]
FROM SheetName$
WHERE F2 IS NOT NULL AND F3 IS NOT NULL AND F1 <> 'Col1'
注意列名的不同。我遇到的问题是让第二个导入没有错误。第一个导入使用第一行作为标题,第二个不是。对于第二个工作来说,重要的是您知道空列和标题的第一列是固定名称。您可以尝试使用文件命名约定来更改数据指向的表。
编辑:在从 Excel 导入中找到答案- 标题不在第 1 行
SELECT F1 AS [DBCol1],
F2 AS [DBCol2],
F3 AS [DBCol3],
F4 AS [DBCol4],
F5 AS [DBCol5],
F6 AS [DBCol6]
FROM [SheetName$A3:G65536]
Edit: I finally found the answer that I needed.
First - My entire problem happened because the first row of the spreadsheet was not the header.
The problem I was having had to do with the first column having to be required to be text only. No mixed data types. Any data in that first column had to be forced to be text by pre-pending an apostrophe (') to any numerical cells. This was not necessary if the header row was the first row and the "First row is header" checkbox was checked. Many of the other parts of the solution were required also. The "WHERE" clause was necessary but the array selection (A3:G65536) was not.