xlrd寫入excel
2024-02-15 17:10:43
```python
import xlrd
from xlwt import Workbook
```
```python
workbook = xlrd.open_workbook('my_book.xls')
worksheet = workbook.sheet_by_index()
for rownum in range(worksheet.nrows):
print(worksheet.row_values(rownum))
```
```python
wbk = Workbook()
ws = wbk.add_sheet('Sheet ')
# 微生物發(fā)酵產(chǎn)品開發(fā)的數(shù)據(jù)
data = [['日期', '發(fā)酵罐號(hào)', '菌種名稱', '培養(yǎng)基', 'PH值'],
['--', 'K', '酵母菌', '玉米漿', ''],
['--', 'K', '大腸桿菌', '豆粕', '']]
for i, row in enumerate(data):
for j, cell in enumerate(row):
ws.write(i, j, cell)
wbk.save('my_book.xls')
```
如此就成功地將新的數(shù)據(jù)寫入到了Excel中。