用python 写入excel 10行5列的数据
时间: 2024-03-05 22:47:52 浏览: 22
Sure! You can use the `openpyxl` library to write data to an Excel file. Here's an example of how you can write 10 rows and 5 columns of data:
```python
import openpyxl
# Create a new workbook
workbook = openpyxl.Workbook()
# Select the active worksheet
worksheet = workbook.active
# Write 10 rows and 5 columns of data
for row in range(1, 11):
for col in range(1, 6):
worksheet.cell(row=row, column=col, value=f"Row {row}, Col {col}")
# Save the workbook
workbook.save("example.xlsx")
```
This code creates a new workbook, selects the active worksheet, and then writes 10 rows and 5 columns of data to it. The data in each cell is formatted as "Row {row}, Col {col}", where {row} and {col} are replaced with the row and column numbers.
Finally, the code saves the workbook to a file named "example.xlsx". You can modify the data and file name to suit your needs.
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)