oExcel = CreateObject("Excel.Application") oWorkbook = oExcel.Workbooks.Open(lcXlsFile) *oExcel.Visible = .T. oSheet = oWorkbook.ActiveSheet lnHeaderRow = 1 lnLastCol = oSheet.UsedRange.Columns.Count lnItemCol = 0 lnPriceCol = 0 FOR lnCol=1 TO lnLastCol lcHeader = oSheet.Cells(lnHeaderRow, lnCol).Value DO CASE CASE UPPER(ALLTRIM(lcHeader)) == "ITEM" lnItemCol = lnCol CASE UPPER(ALLTRIM(lcHeader)) == "PRICE" lnPriceCol = lnCol ENDCASE ENDFOR IF lnPriceCol = 0 OR lnItemCol = 0 MESSAGEBOX("Wrong spreadsheet") RETURN .F. ENDIF CREATE CURSOR Items (Item C(6), Price N(10,2)) lnLastRow = oSheet.UsedRange.Rows.Count FOR lnRow = lnHeaderRow + 1 TO lnLastRow lvItemValue = oSheet.Cells(lnRow, lnItemCol).Value DO CASE CASE VARTYPE(lvItemValue) == "N" lcItem = PADL(INT(lvItemValue), 6, "0") CASE VARTYPE(lvItemValue) == "C" lcItem = lvItemValue OTHERWISE * Wrong type, do something LOOP && Ignore the row ENDCASE lvPriceValue = oSheet.Cells(lnRow, lnPriceCol ).Value DO CASE CASE VARTYPE(lvPriceValue) == "C" lnPrice = CAST(lvPriceValue AS N(10,2)) CASE VARTYPE(lvPriceValue) == "N" lnPrice = lvPriceValue OTHERWISE * Wrong type, do something LOOP && Ignore the row ENDCASE INSERT INTO Items VALUES (lcItem, lnPrice) ENDFOR ...
> >LOCAL oExcel, lcItem, lnCost >lcFile = "HITACHI.XLS" > >oExcel = CREATEOBJECT("Excel.Application",) >oExcel.Workbooks.Open(lcFile) >oExcel.Workbooks(1).Sheets(1).Select() >oExcel.Cells.Select >mnLastRow = oExcel.activesheet.UsedRange.ROWS.COUNT >rr = oExcel.activesheet.UsedRange.ROWS.COUNT >mcLastRow = ALLTRIM(STR(mnLastRow)) > >lcItem = oExcel.Cells(rr,??).value && oExcel.Cells(rr,08).value >lnCost = oExcel.Cells(rr,??).value && oExcel.Cells(rr,12).value > >