对应sql:
from openpyxl import Workbook
from faker import Faker
# 创建一个Workbook对象
workbook = Workbook()
# 获取默认的活动工作表
sheet = workbook.active
# 创建一个Faker对象
fake = Faker()
# 写入表头
header = ['Name', 'Address', 'Email']
sheet.append(header)
# 生成虚拟数据并写入Excel文件
for _ in range(10):
name = fake.name()
address = fake.address()
email = fake.email()
row = [name, address, email]
sheet.append(row)
# 保存Excel文件
workbook.save('fake_data.xlsx')
请确保在运行此示例之前已安装openpyxl和faker库。可以使用以下命令通过pip安装它们:
pip install openpyxl
pip install faker