Skip to Content

création de la fonction en PL/Python: lecture du fichier excel et importation dans matable

  1. CREATE OR REPLACE FUNCTION lectexcel(param_filename text)
  2. RETURNS SETOF matable AS
  3. $BODY$
  4. import xlrd
  5. book = xlrd.open_workbook(param_filename)
  6. sh = book.sheet_by_index(0)
  7. # on assume que la première ligne contient les en-tête de colonnes
  8. # et on n'en tient pas compte
  9. for rx in range(1,sh.nrows):
  10. yield(sh.cell_value(rowx=rx, colx=0),
  11. sh.cell_value(rowx=rx, colx=1),
  12. sh.cell_value(rowx=rx, colx=2)
  13. )
  14. $BODY$
  15. LANGUAGE 'plpythonu';