python 写入excel
时间: 2023-09-05 14:14:54 浏览: 265
excel_python写入excel_python读取EXCEL_pythonexcel_
要在Python中写入Excel,可以使用xlwt模块。首先需要导入xlwt模块,并创建一个Excel表格类型的文件。然后在表格中建立一张sheet表单。接下来,可以使用循环将指定值写入sheet的不同单元格中。最后,将文件保存。下面是一个例子代码:
```python
import numpy as np
import xlwt
# 随机生成一个3×4的数组(值不超过10)
data = np.random.randint(10, size=(3, 4))
# 创建excel表格类型文件
book = xlwt.Workbook(encoding='utf-8', style_compression=0)
# 在excel表格类型文件中建立一张sheet表单
sheet = book.add_sheet('sheet1', cell_overwrite_ok=True)
# 将指定值写入sheet
for i in range(data.shape<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [【Python】将数据写入excel文件中](https://blog.csdn.net/qq_40445009/article/details/130396876)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [python实现将数据写入Excel文件中](https://blog.csdn.net/guoxuying/article/details/112470819)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文