Data from the Web page is read from Excel

Source: Internet
Author: User

#-*-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表格中的数据 parameter: File:excel file path Colnameindex: The header column name is the row, so the By_name:sheet1 name
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, a). Toordinal ()-1
If Isinstance (date, float):
date = Int (date)
D = datetime.date.fromordinal (__s_date + date)
Return D
Except
Return date

Data from the Web page is read from Excel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.