def importFromExcel( dbid,excelFilename,lastColumn = 'j',lastDataRow = 0,worksheetNumber = 1,fieldNameRow = 1,firstDataRow = 2,firstColumn = 'a')
      num_recs_imported = 0
      if require 'win32ole'
         if FileTest.readable?( excelFilename )
            getSchema( dbid )

            excel = WIN32OLE::new( 'Excel.Application' )
            workbook = excel.Workbooks.Open( excelFilename )
            worksheet = workbook.Worksheets( worksheetNumber )
            worksheet.Select

            fieldNames = nil
            rows = nil
            skipFirstRow = nil

            if fieldNameRow > 0
               fieldNames = worksheet.Range("#{firstColumn}#{fieldNameRow}:#{lastColumn}#{fieldNameRow}")['Value']
               skipFirstRow = true
            end

            if lastDataRow <= 0
               lastDataRow = 1
               while worksheet.Range("#{firstColumn}#{lastDataRow}")['Value']
                  lastDataRow += 1  
               end
            end
      
            if firstDataRow > 0 and lastDataRow >= firstDataRow
               rows = worksheet.Range("#{firstColumn}#{firstDataRow}:#{lastColumn}#{lastDataRow}")['Value']
            end
      
            workbook.Close
            excel.Quit

            csvData = ""
            targetFieldIDs = []

            if fieldNames and fieldNames.length > 0
                 fieldNames.each{ |fieldNameRow|
                  fieldNameRow.each{ |fieldName|
                     if fieldName
                        fieldName.gsub!( ",", ";" ) #strip commas
                        csvData << "#{fieldName},"
                             targetFieldIDs << lookupFieldIDByName( fieldName )
                     else
                        csvData << ","
                     end
                  }
                  csvData[-1] = "\n"
               }
            end

            rows.each{ |row|
               row.each{ |cell|
                 if cell
                     cell = cell.to_s
                     cell.gsub!( ",", ";" ) #strip commas
                     csvData << "#{cell},"
                 else
                     csvData << ","
                 end
               }
               csvData[-1] = "\n"
             }

             clist = targetFieldIDs.join( '.' )
             num_recs_imported = importFromCSV( dbid, formatImportCSV( csvData ), clist, skipFirstRow )
         else
            raise "importFromExcel: '#{excelFilename}' is not a readable file."
         end
      end
      num_recs_imported
   end
def importFromExcel( dbid,excelFilename,lastColumn = 'j',lastDataRow = 0,worksheetNumber = 1,fieldNameRow = 1,firstDataRow = 2,firstColumn = 'a')
      num_recs_imported = 0
      if require 'win32ole'
         if FileTest.readable?( excelFilename )
            getSchema( dbid )

            excel = WIN32OLE::new( 'Excel.Application' )
            workbook = excel.Workbooks.Open( excelFilename )
            worksheet = workbook.Worksheets( worksheetNumber )
            worksheet.Select

            fieldNames = nil
            rows = nil
            skipFirstRow = nil

            if fieldNameRow > 0
               fieldNames = worksheet.Range("#{firstColumn}#{fieldNameRow}:#{lastColumn}#{fieldNameRow}")['Value']
               skipFirstRow = true
            end

            if lastDataRow <= 0
               lastDataRow = 1
               while worksheet.Range("#{firstColumn}#{lastDataRow}")['Value']
                  lastDataRow += 1  
               end
            end
      
            if firstDataRow > 0 and lastDataRow >= firstDataRow
               rows = worksheet.Range("#{firstColumn}#{firstDataRow}:#{lastColumn}#{lastDataRow}")['Value']
            end
      
            workbook.Close
            excel.Quit

            csvData = ""
            targetFieldIDs = []

            if fieldNames and fieldNames.length > 0
                 fieldNames.each{ |fieldNameRow|
                  fieldNameRow.each{ |fieldName|
                     if fieldName
                        fieldName.gsub!( ",", ";" ) #strip commas
                        csvData << "#{fieldName},"
                             targetFieldIDs << lookupFieldIDByName( fieldName )
                     else
                        csvData << ","
                     end
                  }
                  csvData[-1] = "\n"
               }
            end

            rows.each{ |row|
               row.each{ |cell|
                 if cell
                     cell = cell.to_s
                     cell.gsub!( ",", ";" ) #strip commas
                     csvData << "#{cell},"
                 else
                     csvData << ","
                 end
               }
               csvData[-1] = "\n"
             }

             clist = targetFieldIDs.join( '.' )
             num_recs_imported = importFromCSV( dbid, formatImportCSV( csvData ), clist, skipFirstRow )
         else
            raise "importFromExcel: '#{excelFilename}' is not a readable file."
         end
      end
      num_recs_imported
   end
Import data directly from an Excel file into a table
 The field names are expected to be on line 1 by default.
 By default, data will be read starting from row 2 and ending on the first empty row.
 Commas in field values will be converted to semi-colons.
 e.g. importFromExcel( @dbid, "my_spreadsheet.xls", 'h' )