SET SAFETY OFF
CLOSE DATABASES ALL
Sheet2dbf("Test.xls", "my_Sheet", "new")
RETURN
*---------------------------
* 從Excel表格中建立數據表並導入數據
* 參數:tcBook -- Excel 工作簿名(須帶擴展名)
* tcSheet -- 工作表名
* tcTable -- 建立的數據庫名
* 說明:
* 1.在實際工作中,從Excel導入數據的需求,一般是一次性的,同樣的數據不應反復追加到數據庫中,故此處不檢驗數據的重覆。
* 2.建立的數據表結構佔用第1、2行,分別是字段名和數據類型(格式與CREATE TABLE語句對應)。
* 3.數據以{end}字樣結束(程序中應增加空行處理)。
* 4.日期型數據的處理,本例程並非適用一切環境,應根據實際環境調試。
*---------------------------
PROCEDURE Sheet2dbf(tcBook AS Character, tcSheet AS Character, tcTable AS Character)
LOCAL loExcel AS Object
LOCAL laColumns[1,3]
LOCAL lnFields AS Integer, lnIndex AS Integer, lcText AS Character, lnRow AS Integer, lnCol AS Integer
LOCAL lcType AS Character
LOCAL lcYear AS Character, lcMonth AS Character, lcDay AS Character
loExcel = CREATEOBJECT("Excel.Application")
WITH loExcel
.WorkBooks.Open(FULLPATH(tcBook))
.WorkSheets(tcSheet).Activate
lcText = ""
lnIndex = 1
DO WHILE !EMPTY(ALLTRIM(.Cells(1, lnIndex).Text))
DIMENSION laColumns[lnIndex,3]
laColumns[lnIndex,1] = ALLTRIM(.Cells(1, lnIndex).Text)
laColumns[lnIndex,2] = ALLTRIM(.Cells(2, lnIndex).Text)
laColumns[lnIndex,3] = lnIndex
lcText = lcText + laColumns[lnIndex,1] + " " + laColumns[lnIndex,2] + ", "
lnIndex = lnIndex + 1
ENDDO
lcText = LEFT(lcText, LEN(lcText) - 2)
CREATE TABLE (tcTable) (&lcText)
lnFields = ALEN(laColumns,1)
lnRow = 3
DO WHILE UPPER(.Cells(lnRow,1).Text) != "{END}"
SELECT (tcTable)
APPEND BLANK
FOR lnCol = 1 TO lnFields
lcType = UPPER(LEFT(laColumns[lnCol,2],1))
DO CASE
CASE INLIST(lcType, "C", "M")
REPLACE (laColumns[lnCol,1]) WITH .Cells(lnRow, laColumns[lnCol,3]).Text
CASE INLIST(lcType, "N", "B", "F", "I")
REPLACE (laColumns[lnCol,1]) WITH .Cells(lnRow, laColumns[lnCol,3]).Value
CASE lcType == "D"
cText = ALLTRIM(.Cells(lnRow, laColumns[lnCol,3]).Text)
lcYear = LEFT(cText, 4)
lcMonth = SUBSTR(cText, 6, 2)
lcDay = RIGHT(cText, 2)
cText = "{^" + lcYear + "-" + lcMonth + "-" + lcDay + "}"
REPLACE (laColumns[lnCol,1]) WITH &cText
CASE lcType == "L"
REPLACE (laColumns[lnCol,1]) WITH (.Cells(lnRow, laColumns[lnCol,3]).Text != "0")
ENDCASE
NEXT
lnRow = lnRow + 1
ENDDO
USE IN (tcTable)
.Quit
ENDWITH
RELEASE loExcel
ENDPROC
以上是Tony Deng先生的一段代码,不知道对你有没有帮助