Creating Excel files with Python and XlsxWriter(通过 Python和XlsxWriter来创建Excel文件(xlsx格式))

以下所有内容翻译至: https://xlsxwriter.readthedocs.io/

#-------------------------------------------------------------------------------------------------------------------------------

XlsxWriter 是一个用来创建Excel XLSX 文件的Python 模块。

demo:

demo 代码:

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

1############################################################################## 2# 3# A simple example of some of the features of the XlsxWriter Python module. 4# 5# Copyright 2013-2018, John McNamara, jmcnamara@cpan.org # import xlsxwriter #导入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. #用‘A1’等表达方式在单元格中写入简单的文本 worksheet.write('A1', 'Hello') # Text with formatting. #在单元格中写入文本的同时设置格式 worksheet.write('A2', 'World', bold) # Write some numbers, with row/column notation. #用行列号的表达方式(从00开始)在单元格写入数值 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模块,用这个模块可以实现在2007以上版本的exel格式为xlsx的文件中添加多个工作表并且可以插入文本,数字,公式,超链接等。它支持例如格式等很多功能,包含如下:

      100% 和excel xlsx 文件兼容;

  支持所有格式;

  支持合并单元格;

  定义名字;

  图表;

  筛选;

  数据验证和下拉列表;

  条件格式;

  工作表插入PNG/JPEG/GMP/WMF/WMF 图片;

  富文本格式字符串;

  单元格注释;

  文本框组件;

  联合Pndas模块;

  写入大文件时支持记忆优化模式;

它支持Python 2.5,2.6,2.7,3.1,3.2,3.3,3.4,3.5,3.6等版本,Jython和PyPy 只使用标准库。

这个文件解释了怎么使用xlsxwrite 模块,阅读下面的章节来了解更多内容,或者直接跳到 Introduction。

  •  Content
  •  Introduction
  •  Getting Started with XlsxWriter
  • ---------------------------------------------------------------------------------
  •  Tutorial 1: Create a simple XLSX file
  •  Tutorial 2: Adding formatting to the XLSX file
  •  Tutorial 3:Writting different types of data to the XLSX file
  • --------------------------------------------------------------------------------
  •  The Workbook Class
  •  The Worksheet Class
  •  The Worbook Class(Page Setup)
  •  The Format Class
  •  The Chart Class
  •  The Chartsheet Class
  •  The Exceptions Class
  •   ------------------------------------------------------------------------------
  •  Working with Cell Notation
  •  Working with Formulas
  •  Working with Dates and Times
  •  Working with Colors 
  •  Working with Charts
  •  Working with Autofilters
  •  Working with Data Validation
  •  Working with Conditional Formatting
  •  Working with Worksheet Tables
  •  Working with Textboxes
  •  Working with Sparklines
  •  Working with Cell Comments
  •  Working with Outlines and Grouping
  •  Working with Memory and Performance
  •  Working with VBA Macros
  •  Working with Python Pandas and XlsxWriter
  • ----------------------------------------------------------------------------------
  •  Examples
  • ----------------------------------------------------------------------------------
  •  Chart Examples
  • ----------------------------------------------------------------------------------
  •  Pandas with XlsxWriter Examples
  • ----------------------------------------------------------------------------------
  •  Alternative modules for handing Excel files
  •  Libraries that use or enhance XlsxWriter
  •  Known Issues and Bugs
  •  Reporting Bugs
  •  Frequently Asked Questions
  •  Changes in XlsxWriter
  •  Author 
  •  License
点赞
收藏

评论区

加载中...

相关推荐

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

python读取excel数据转为json格式

做自动化时需要从excel读取数据;本文实现将excel文件数据读取为json格式,方便自动化调用读取xls文件使用xlrd读取xls文件代码:pythonimportxlrddefreadxls(file):实例化excelbookxlrd.openworkbook(file)下标读取sheetsheetb

vue项目中使用element-ui实现excel表格上传

恰逢项目中要实现excel表格上传,度娘甚久,得此一文,留之。原文:https://blog.csdn.net/qq36718999/article/details/95387542需求vuecli搭建前端项目,并使用elementui实现本地excel表格上传。(1)限制上传文件只能是xls、xlsx格式;(2)限制上传文件大小不能超过2MB

python-docx无法处理 “doc格式” 文件,于是我这样做......

问题引入目前的日常工作中,见的最多的还是对Excel文件和Word文件的处理。对于Excel文件,如果出现xls、xlsx、xlsm混合文件应该怎么处理?对于Word文件,出现doc和docx的混合文件,又该怎么处理。你可能会用VBA,但是不得不说,批量操作这些文件,还是要学Python,操作真的很简单。为了增强文章的可读性,我们分2篇文章讲述这些问题

商业数据分析从入门到入职(2)Excel基础

一、Excel介绍1.Excel简介Excel不仅仅只是存放数据的工具,其功能特别强大,甚至可以做出美观的仪表盘,如下:甚至还可以用Excel作画,可点击查看,如下:Excel存在很多版本,如2003、2007、2010、2016、2019等,一般向下兼容,不同系统的兼容性可能存在问题。文件类型主要包括xls、xlsx等。一个Excel表格

ABAP学习(16):ABAP2XLSX,操作excel

ABAP2XLSX   ABAP2XLS是一个操作EXCEL的开源项目,相比较OLE2和DOI方式操作excel更加方便。   ABAP中搜索ZDEMO\_EXCEL\搜索Program可以查看SAP提供的示例程序,实现多种Excel。1.创建excel   Excel类:zcl\_excel类