Python implements adding new rows at the end of Excel

不言
Release: 2018-05-02 14:42:00
Original
4362 people have browsed it

This article mainly introduces the implementation of adding new rows at the end of Excel in python, which has certain reference value. Now I share it with you. Friends in need can refer to the

example As follows:

import os
import xlrd
import xlwt
from xlutils.copy import copy

def excelwrite(L=None):
	if L is None:
		L = []
	print(L)
	filename = r'wldata.xls'
	workbook = xlrd.open_workbook(filename, formatting_info=True)
	sheet = workbook.sheet_by_index(0)
	rowNum = sheet.nrows
	colNum = sheet.ncols
	newbook = copy(workbook)
	newsheet = newbook.get_sheet(0)
	# 在末尾增加新行
	str = 'hehe'
	newsheet.write(rowNum, 0, str)
	# 覆盖保存
	newbook.save(filename)
Copy after login

Related recommendations:

Search based on file name implemented in Python Data file function example

The above is the detailed content of Python implements adding new rows at the end of Excel. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!