python xlsxwriter 条件格式_通过Python和XlsxWriter创建Excel文件

本文展示了如何使用XlsxWriter模块在Python中创建Excel文件,并重点介绍了如何设置条件格式。通过示例代码,可以看到如何添加文本、格式、数字、图像以及应用条件格式。
摘要由CSDN通过智能技术生成

XlsxWriter是一个Python的第三方模块,用来创建Excel的xlsx文件。

![](/media//202002/2020-02-04154532644408demo.png)

```python

##############################################################################

#

# A simple example of some of the features of the XlsxWriter Python module.

#

# Copyright 2013-2020, John McNamara, jmcnamara@cpan.org

#

import xlsxwriter

# Create an new Excel file and add a worksheet.

workbook = xlsxwriter.Workbook('demo.xlsx')

worksheet = workbook.add_worksheet()

# Widen the first column to make the text clearer.

worksheet.set_column('A:A', 20)

# Add a bold format to use to highlight cells.

bold = workbook.add_format({'bold': True})

# Write some simple text.

worksheet.write('A1', 'Hello')

# Text with formatting.

worksheet.write('A2', 'World', bold)

# Write some numbers, with row/column notation.

worksheet.write(2, 0, 123)

worksheet.write(3, 0, 123.456)

# Insert an image.

worksheet.insert_image('B5', 'logo.png')

workbook.close()

```

## XlsxWriter

XlsxWriter是一个Python第三方模块,可以将文本、数字、公式和超链接写入Excel 2007以上版本的xlsx文件的多个工作簿中。它还支持格式化等功能,其中包括:

- 100%兼容Excel的xlsx文件;

- 完整的格式;

- 合并单元格;

- 定义名称;

- 图表;

- 自动过滤器;

- 数据验证和下拉列表;

- 条件格式;

- 工作簿的PNG、JPEG、BMP、WMF、EMF等图像;

- 丰富的多格式字符串;

- 单元格注释;

- 文本框;

- 与Pandas模块整合;

- 用于写入大文件的内存优化模式;

它支持Python2.7、3.4+和Pypy,并且仅使用Python的标准库,不依赖任何第三方库。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值