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

Python (31): using Python to append Excel

編輯:Python


List of articles

  • One 、 Read excel One of the sheet A column of a row of
  • Two 、 Append data to new file

The original document

One 、 Read excel One of the sheet A column of a row of

import xlrd
file = 'demo.xlsx'
sheet_name='Sheet1'
work = xlrd.open_workbook(file)
work_sheet = work.sheet_by_name(sheet_name)
print(work_sheet.cell_value(2, 0)) # Read the first 3 OK, No 1 Column 

Two 、 Append data to new file

# coding: utf-8 
import xlrd
from xlutils.copy import copy
file = 'demo.xlsx'
sheet_name = 'Sheet1'
work = xlrd.open_workbook(file)
work_sheet = work.sheet_by_name(sheet_name)
# Copy the data table 
new_file = copy(work)
ws = new_file.get_sheet(0)
# Write data to new table 
ws.write(4, 0, '4')
ws.write(4, 1, 'Danny')
# preservation 
new_file_name = 'new_demo.xlsx'
new_file.save(new_file_name)


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