程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python reading table data xlrd

編輯:Python
import re
import lxml
import xlrd
import xlrd # Import and stock in 
import xlwt
path=r' route '
wb=xlrd.open_workbook(path) # Open the file and return a working object .open_workbook You can click in to see the meaning of the parameters in the function , Very detailed , Poor English can be translated by Baidu , The translation results are similar .
writrfile=xlwt.Workbook(encoding='utf-8',)
sheet_num=wb.nsheets # obtain excel Inside sheet The number of 
table = wb.sheets()[0] # By index order 
sheet_names=wb.sheet_names() # Get Excel Everything in it sheet List of names for , Even without sheet Can also be used .
sheet=wb.sheet_by_index(0) # Get a by index sheet, Now is the first to get sheet page , It can also be done through sheet Get the name of ,sheet_by_name('sheet name ')
rows=sheet.nrows # obtain sheet The number of rows on the page , There are a few lines 
columns=sheet.ncols # obtain sheet Number of columns per page , There are several columns 
# Get the data of the first row 
row_data=sheet.row_values(0) # Returns the cell data of a given number of rows for slicing 
# Get the data of the second column 
col_data=sheet.col_values(1)
# Get cell data 
# one_data=sheet.cell(row_index,col_index) # The same is done by indexing ,cell(0,1) Get the cell data of the first row and the second column 
# cell_value=one_data.value # Get cell value 
# cell_type=one_data.ctype # Gets the type of the cell , stay xlrd in , The data types of cells are 6 Kind of ,
# 0 -- empty (empty)
# 1 -- character string (string)
# 2 -- Numbers (number)
# 3 -- date( date )
# 4 -- boolean( Boolean value )
# 5 -- error( error )
print(sheet_num)
print(table)
print(sheet_names)
print(sheet)
print(rows)
print(columns)
print(row_data)
print(col_data)
print(sheet.cell(1,0))
tool=sheet.cell(1,0).value
tool=" Alipay "
sheet.cell(1,0).value=tool
print(tool)
sheet1=writrfile.add_sheet('sheet1',cell_overwrite_ok=True)

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved