共享类¶
Shared classes
长度对象¶
Length objects
python-docx
中的长度值表示为标准化的 Length
值对象。Length
是 int
的子类,具有 int
的所有行为。此外,它还具有内置单位转换属性,例如:
>>> inline_shape.height
914400
>>> inline_shape.height.inches
1.0
长度对象是使用一系列便捷构造函数构造的,允许以最适合上下文的单位表示值。
Length values in python-docx
are expressed as a standardized Length
value object. Length
is a subclass of int
, having all the behavior of an int
. In addition, it has built-in units conversion properties, e.g.:
>>> inline_shape.height
914400
>>> inline_shape.height.inches
1.0
Length objects are constructed using a selection of convenience constructors, allowing values to be expressed in the units most appropriate to the context.
- class docx.shared.Length(emu: int)[源代码]¶
Base class for length constructor classes Inches, Cm, Mm, Px, and Emu.
Behaves as an int count of English Metric Units, 914,400 to the inch, 36,000 to the mm. Provides convenience unit conversion methods in the form of read-only properties. Immutable.
- property cm¶
The equivalent length expressed in centimeters (float).
- property emu¶
The equivalent length expressed in English Metric Units (int).
- property inches¶
The equivalent length expressed in inches (float).
- property mm¶
The equivalent length expressed in millimeters (float).
- property pt¶
Floating point length in points.
- property twips¶
The equivalent length expressed in twips (int).
- class docx.shared.Inches(inches: float)[源代码]¶
Convenience constructor for length in inches, e.g.
width = Inches(0.5)
.
- class docx.shared.Cm(cm: float)[源代码]¶
Convenience constructor for length in centimeters, e.g.
height = Cm(12)
.
- class docx.shared.Mm(mm: float)[源代码]¶
Convenience constructor for length in millimeters, e.g.
width = Mm(240.5)
.
- class docx.shared.Pt(points: float)[源代码]¶
Convenience value class for specifying a length in points.
RGBColor
对象¶
RGBColor
objects
- class docx.shared.RGBColor(r, g, b)[源代码]¶
Immutable value object defining a particular RGB color.
r, g, and b are each an integer in the range 0-255 inclusive. Using the hexidecimal integer notation, e.g. 0x42 may enhance readability where hex RGB values are in use:
>>> lavender = RGBColor(0xff, 0x99, 0xcc)