Python Module_openpyxl_styles 样式处理

目录

  • 目录
  • 前言
  • 系统软件
  • Working with styles
    • Styles can be applied to the following aspects
  • Styles模块
    • Copying styles
    • Basic Font Colors
    • Applying Styles
    • Edit Page Setup
    • Edit Print Options
    • Header Footer

前言

继续搞Python对Excel文件的处理,这次主要解决如何使用Openpyxl模块的Styles来生成一个具有个性化样式的Excel文件。本篇基本算是翻译了部分实用的官方文档内容,推荐小伙伴们最好的学习方法,莫过于阅读官方文档。: )
官当文档传送门:http://openpyxl.readthedocs.org/en/default/styles.html#worksheet-additional-properties

系统软件

  • 系统
    • Windows 8.1
  • 软件
    • Python 3.4.3
    • IPython 4.0.0

Working with styles

使用Excel样式函数
Introduction(简介)
Styles are used to change the look of your data while displayed on screen. They are also used to determine the number format being used for a given cell or range of cells.
Styles是用于改变你的希望显示的数据的样式。也可以用于设置指定的单元格或单元区域的数字格式。

Styles can be applied to the following aspects

  • font to set font size, color, underlining, etc.(能够设定字体的大小、颜色、下划线等属性)
  • fill to set a pattern or color gradient(能够设置单元格的填充样式或颜色渐变)
  • border to set borders on a cell(能够设置单元格的边框)
  • cell alignment(能够设置单元格的对齐)
  • protection(能够设置访问限制)

Styles模块

The following are the default values(下面是函数的参数缺省值)

注意
Styles are shared between objects and once they have been assigned they cannot be changed. This stops unwanted side-effects such as changing the style for lots of cells when instead of only one.
不同的对象之间是可以共享同一个Styles的,并且一旦为对象指定了Styles之后就不可以再次更改。这是为了在更改很多的单元格的Styles而不仅只是更改一个单元格时能够避免不必要的副作用。

Copying styles

Styles can also be copied(Styles可以被复制)

Basic Font Colors

Colors are usually RGB or aRGB hexvalues. The colors module contains some constants
Colors通常是RGB或者是RGB的十六进制表示。Colors模块包含了一些常量

There is also support for legacy indexed colors as well as themes and tints
Colors也支持索引颜色、主题和色彩

Applying Styles

Styles are applied directly to cells
Styles直接应用于单元格

Styles can also applied to columns and rows but note that this applies only to cells created (in Excel) after the file is closed. If you want to apply styles to entire rows and columns then you must apply the style to each cell yourself. This is a restriction of the file format
Styles也可以应用于列和行,但是需要注意的是这种应用只能适用于在关闭文件之后创建的单元格。如果你想应用Style于全部的行和列,你必须为每一个单元格都应用Style。这是由于文件格式的制约

Edit Page Setup

Edit Print Options

Headers and footers use their own formatting language. This is fully supported when writing them.but, due to the complexity and the possibility of nesting, only partially when reading them.

头部和尾部使用它们自身的格式化语言。当你写的时候是完全支持的。但是由于复制性和嵌套的可能性,让你读取的时候可能只能读取到一个部分。

文章知识点与官方知识档案匹配,可进一步学习相关知识Python入门技能树首页概览210539 人正在系统学习中 云物互联

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2016年1月1日
下一篇 2016年1月1日

相关推荐