web頁面的資料從excel中讀取

來源:互聯網
上載者:User

標籤:odi   讀取   open   pen   index   name   web頁面   int   names   

# -*- coding: utf-8 -*-
import xdrlib ,sys
import xlrd
import datetime
import json
import conf,re
import os


def open_excel(file= ‘file.xlsx‘):
try:
data = xlrd.open_workbook(file)
return data
except Exception,e:
print str(e)

#根據名稱擷取Excel表格中的資料 參數:file:Excel檔案路徑 colnameindex:表頭列名所在行的所以 ,by_name:Sheet1名稱
def excel_table_byname(file= ‘file.xls‘,colnameindex=0,by_name=u‘Sheet1‘):
data = open_excel(file)
table = data.sheet_by_name(by_name)
nrows = table.nrows #行數
colnames = table.row_values(colnameindex) #某一行資料
list =[]
for rownum in range(1,nrows):
row = table.row_values(rownum)
if row:
app = {}
for i in range(len(colnames)):
app[colnames[i]] = row[i]
list.append(app)
return list

def getdate(date,stype=0):
try:
if stype == 1:
d = xlrd.xldate.xldate_as_datetime(date,0)
return d
else:
__s_date = datetime.date (1899, 12, 31).toordinal() - 1
if isinstance(date , float ):
date = int(date )
d = datetime.date.fromordinal(__s_date + date )
return d
except:
return date

web頁面的資料從excel中讀取

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.