49

简直出神入化,教你用Python控制Excel实现自动化办公

 4 years ago
source link: https://www.tuicool.com/articles/MjeERrJ
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

1.安装

reQV7rN.jpg!web

2.操作一个简单的Excel文档

操作注释及代码:

6fyQNr7.jpg!web

操作完成后,数据存储结果如下:

3meAjmB.jpg!web

3. 操作简单Excel文档并添加数据格式

操作代码如下:附带数据格式的定义

emIBZnu.jpg!web

操作效果如图所示:

nAZjeaz.jpg!web

4.Excel中添加不同类型的数据

操作代码如下:将不同的数据按照指定的格式添加到文件中

RBFbeeN.jpg!web

代码执行结果如下:

JnuQBbN.jpg!web

注意:xlsxwriter中提供了向excel中写入数据的多种方式,如下:

  • write_string()【https://xlsxwriter.readthedocs.io/worksheet.html#write_string】

  • write_number()【https://xlsxwriter.readthedocs.io/worksheet.html#write_number】

  • write_blank()【https://xlsxwriter.readthedocs.io/worksheet.html#write_blank】

  • write_formula()【https://xlsxwriter.readthedocs.io/worksheet.html#write_formula】

  • write_datetime()【https://xlsxwriter.readthedocs.io/worksheet.html#write_datetime】

  • write_boolean()【https://xlsxwriter.readthedocs.io/worksheet.html#write_boolean】

  • write_url()【https://xlsxwriter.readthedocs.io/worksheet.html#write_url】

5.Excel中添加数据图表

操作代码如下:将对应的数据展示图表添加到文件中

bqQ7naq.jpg!web

代码执行结果如下图所示:

nEbMNrQ.jpg!web


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK