Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
FoxPro and Excel
Message
 
 
To
15/06/2001 09:37:32
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00519913
Message ID:
00519930
Views:
14
>I'm trying to open up an excel file and import into a dbf but because there are macros within the excel file, it imports garbage. Can any assist me on how to ahve excel to save the file as a csv file type?

The following will get you started. Once you get the data into a DBF, you can COPY TO whatever format you want.
local lcFileName
lcFileName = upper(getfile("ExcelFiles:XLS","File Name:", "Open"))
if type("lcFileName") <> "C" or right(lcFileName, 4) <> ".XLS" or empty(lcFileName)
   return
endif
local ox, oSheet
ox = createobject("excel.application")
loSheet = OpenXLFile(lcFileName)
ProcessNewItems()
loSheet = .null.
loBook.Close()
loBook = .null.
ox.Quit()
release ox
return


procedure OpenXLFile
*
lparameter tcFileName
local loActiveSheet
loBook = ox.Workbooks.Open(tcFileName)
loActiveSheet = loBook.Sheets(1)
return loActiveSheet


procedure ProcessNewItems
*
local lnI, lnBlanks, lnValue
local lcItem, lcDesc, lcUnits, lcPrice
lnBlanks = 0
for lnI = 1 to 5000
   lnValue = val(transform(loSheet.Cells[lnI, 1].Value))
   if lnValue < 100000   && item_no must be 6 digits and at least '100000'
      lnBlanks = lnBlanks + 1
      if lnBlanks > 10 && if >10 consecutive blank lines found,
                       && probably no more to process
         exit
      endif
      loop
   endif
   lnBlanks = 0
   with loSheet
      lcItem  = alltrim(transform(.Cells[lnI, 1].Value))
      lcDesc  = alltrim(transform(.Cells[lnI, 2].Value, '@!'))
      lcUnits = alltrim(transform(.Cells[lnI, 3].Value, '@!'))
      lcPrice = val(transform(.Cells[lnI, 4].Value))
      insert into Products ;
          ( Item_No, Descript, UnitPrice, Units, ItmPerUnit ) ;
         values ;
          ( lcItem, lcDesc, lcPrice, lcUnits, max(1, val(lcUnits)) )
   endwith
endfor
return
Mark McCasland
Midlothian, TX USA
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform