0
# Constants and Enumerations
1
2
Complete Excel constants coverage with 254 constant classes providing access to all Excel enumerations and built-in values. These constants match Excel's native constants and provide type-safe access to Excel's enumerated values.
3
4
## Capabilities
5
6
### Excel Constants Overview
7
8
xlwings provides comprehensive access to Excel's built-in constants through 254 constant classes, covering every aspect of Excel functionality from chart types to file formats.
9
10
```python { .api }
11
# Available in xlwings.constants module
12
# Import pattern:
13
from xlwings.constants import (
14
ChartType, XlChartType,
15
Direction, InsertShiftDirection,
16
FileFormat, XlFileFormat,
17
RGBColor, ColorIndex,
18
HAlign, VAlign,
19
# ... and 240+ other constant classes
20
)
21
22
# Top-level namespace constant
23
from xlwings import ObjectHandleIcons # Available directly
24
```
25
26
### Chart and Visualization Constants
27
28
Constants for chart types, formatting, and visualization elements.
29
30
```python { .api }
31
# Chart type constants
32
class ChartType:
33
xlArea = -4098
34
xlAreaStacked = 76
35
xlAreaStacked100 = 77
36
xlBarClustered = 57
37
xlBarOfPie = 71
38
xlBarStacked = 58
39
xlBarStacked100 = 59
40
xlBubble = 15
41
xlBubble3DEffect = 87
42
xlColumnClustered = 51
43
xlColumnStacked = 52
44
xlColumnStacked100 = 53
45
xlConeBarClustered = 102
46
xlConeCol = 105
47
xlCylinderBarClustered = 95
48
xlDoughnut = -4120
49
xlDoughnutExploded = 80
50
xlLine = 4
51
xlLineMarkers = 65
52
xlLineMarkersStacked = 66
53
xlLineMarkersStacked100 = 67
54
xlLineStacked = 63
55
xlLineStacked100 = 64
56
xlPie = 5
57
xlPieExploded = 69
58
xlPieOfPie = 68
59
xlRadar = -4151
60
xlRadarFilled = 82
61
xlRadarMarkers = 81
62
xlRegionMap = 140
63
xlStockHLC = 88
64
xlStockOHLC = 89
65
xlStockVHLC = 90
66
xlStockVOHLC = 91
67
xlSurface = 83
68
xlSurfaceTopView = 85
69
xlSurfaceTopViewWireframe = 86
70
xlSurfaceWireframe = 84
71
xlXYScatter = -4169
72
xlXYScatterLines = 74
73
xlXYScatterLinesNoMarkers = 75
74
xlXYScatterSmooth = 72
75
xlXYScatterSmoothNoMarkers = 73
76
77
# Color constants
78
class RGBColor:
79
rgbAliceBlue = 16775408
80
rgbAntiqueWhite = 14150650
81
rgbAqua = 16776960
82
rgbAquamarine = 13959039
83
rgbAzure = 16777200
84
rgbBeige = 14480885
85
rgbBisque = 12903679
86
rgbBlack = 0
87
rgbBlanchedAlmond = 13495295
88
rgbBlue = 16711680
89
rgbBlueViolet = 14822282
90
rgbBrown = 2763429
91
rgbBurlyWood = 8894686
92
# ... many more color constants
93
94
class ColorIndex:
95
xlColorIndexAutomatic = -4105
96
xlColorIndexNone = -4142
97
```
98
99
### File Operations Constants
100
101
Constants for file formats, save options, and import/export operations.
102
103
```python { .api }
104
class FileFormat:
105
xlAddIn = 18
106
xlCSV = 6
107
xlCSVMac = 22
108
xlCSVWindows = 23
109
xlDBF2 = 7
110
xlDBF3 = 8
111
xlDBF4 = 11
112
xlDIF = 9
113
xlExcel12 = 50
114
xlExcel2 = 16
115
xlExcel3 = 29
116
xlExcel4 = 33
117
xlExcel4Workbook = 35
118
xlExcel5 = 39
119
xlExcel7 = 39
120
xlExcel8 = 56
121
xlExcel9 = 43
122
xlHtml = 44
123
xlIntlAddIn = 26
124
xlIntlMacro = 25
125
xlJSON = 51
126
xlOpenDocumentSpreadsheet = 60
127
xlOpenXMLStrictWorkbook = 61
128
xlOpenXMLTemplate = 54
129
xlOpenXMLTemplateMacroEnabled = 53
130
xlOpenXMLWorkbook = 51
131
xlOpenXMLWorkbookMacroEnabled = 52
132
xlPDF = 57
133
xlSYLK = 2
134
xlTemplate = 17
135
xlTemplate8 = 17
136
xlText = -4158
137
xlTextMac = 19
138
xlTextPrinter = 36
139
xlTextWindows = 20
140
xlUnicodeText = 42
141
xlWebArchive = 45
142
xlWJ2WD1 = 14
143
xlWJ3 = 40
144
xlWJ3FJ3 = 41
145
xlWK1 = 5
146
xlWK1ALL = 31
147
xlWK1FMT = 30
148
xlWK3 = 15
149
xlWK3FM3 = 32
150
xlWK4 = 38
151
xlWKS = 4
152
xlWorkbookDefault = 51
153
xlWorkbookNormal = -4143
154
xlXPS = 58
155
```
156
157
### Range and Cell Operations Constants
158
159
Constants for range operations, directions, and cell manipulations.
160
161
```python { .api }
162
class Direction:
163
xlDown = -4121
164
xlToLeft = -4159
165
xlToRight = -4161
166
xlUp = -4162
167
168
class InsertShiftDirection:
169
xlShiftDown = -4121
170
xlShiftToRight = -4161
171
172
class DeleteShiftDirection:
173
xlShiftToLeft = -4159
174
xlShiftUp = -4162
175
176
class HAlign:
177
xlHAlignCenter = -4108
178
xlHAlignCenterAcrossSelection = 7
179
xlHAlignDistributed = -4117
180
xlHAlignFill = 5
181
xlHAlignGeneral = 1
182
xlHAlignJustify = -4130
183
xlHAlignLeft = -4131
184
xlHAlignRight = -4152
185
186
class VAlign:
187
xlVAlignBottom = -4107
188
xlVAlignCenter = -4108
189
xlVAlignDistributed = -4117
190
xlVAlignJustify = -4130
191
xlVAlignTop = -4160
192
193
class BordersIndex:
194
xlDiagonalDown = 5
195
xlDiagonalUp = 6
196
xlEdgeBottom = 9
197
xlEdgeLeft = 7
198
xlEdgeRight = 10
199
xlEdgeTop = 8
200
xlInsideHorizontal = 12
201
xlInsideVertical = 11
202
```
203
204
### Calculation and Formula Constants
205
206
Constants for calculation modes, formula types, and mathematical operations.
207
208
```python { .api }
209
class Calculation:
210
xlCalculationAutomatic = -4105
211
xlCalculationManual = -4135
212
xlCalculationSemiautomatic = 2
213
214
class FormulaLabel:
215
xlColumnLabels = 2
216
xlMixedLabels = 3
217
xlNoLabels = -4142
218
xlRowLabels = 1
219
220
class ConsolidationFunction:
221
xlAverage = -4106
222
xlCount = -4112
223
xlCountNums = -4113
224
xlMax = -4136
225
xlMin = -4139
226
xlProduct = -4149
227
xlStDev = -4155
228
xlStDevP = -4156
229
xlSum = -4157
230
xlUnknown = 1000
231
xlVar = -4164
232
xlVarP = -4165
233
```
234
235
### Office.js Integration Constants
236
237
Constants specific to Office.js and web-based Excel integration (PRO features).
238
239
```python { .api }
240
class ObjectHandleIcons:
241
"""Icons for object handles in Office.js (available in top-level namespace)."""
242
243
# Standard icons
244
ICON_ADD = "add"
245
ICON_CANCEL = "cancel"
246
ICON_CHECK = "check"
247
ICON_DELETE = "delete"
248
ICON_EDIT = "edit"
249
ICON_FILTER = "filter"
250
ICON_REFRESH = "refresh"
251
ICON_SAVE = "save"
252
ICON_SEARCH = "search"
253
ICON_SETTINGS = "settings"
254
ICON_SORT = "sort"
255
ICON_WARNING = "warning"
256
257
# Chart icons
258
ICON_CHART_BAR = "chart-bar"
259
ICON_CHART_LINE = "chart-line"
260
ICON_CHART_PIE = "chart-pie"
261
ICON_CHART_SCATTER = "chart-scatter"
262
263
# Data icons
264
ICON_DATABASE = "database"
265
ICON_EXPORT = "export"
266
ICON_IMPORT = "import"
267
ICON_TABLE = "table"
268
```
269
270
### Usage Examples
271
272
Common patterns for using xlwings constants:
273
274
```python
275
import xlwings as xw
276
from xlwings.constants import (
277
ChartType, FileFormat, Direction,
278
HAlign, VAlign, RGBColor
279
)
280
281
# Chart creation with constants
282
wb = xw.books.add()
283
ws = wb.sheets[0]
284
285
# Add sample data
286
ws.range('A1:B5').value = [
287
['Month', 'Sales'],
288
['Jan', 100], ['Feb', 120],
289
['Mar', 140], ['Apr', 110]
290
]
291
292
# Create chart using constants
293
chart = ws.charts.add()
294
chart.chart_type = ChartType.xlColumnClustered
295
chart.source_data = ws.range('A1:B5')
296
297
# Range operations with direction constants
298
start_cell = ws.range('A1')
299
last_row = start_cell.end(Direction.xlDown)
300
last_col = start_cell.end(Direction.xlToRight)
301
302
# Formatting with alignment constants
303
data_range = ws.range('A1:B5')
304
data_range.api.HorizontalAlignment = HAlign.xlHAlignCenter
305
data_range.api.VerticalAlignment = VAlign.xlVAlignCenter
306
307
# Color formatting
308
ws.range('A1:B1').color = RGBColor.rgbLightBlue
309
ws.range('A1:B1').api.Font.Color = RGBColor.rgbWhite
310
311
# Save with file format constants
312
wb.save('/path/to/file.xlsx') # Default format
313
wb.api.SaveAs('/path/to/file.csv', FileFormat.xlCSV)
314
wb.api.SaveAs('/path/to/file.pdf', FileFormat.xlPDF)
315
```
316
317
### Constant Categories Summary
318
319
The 254 constant classes are organized into these major categories:
320
321
```python
322
# Core Excel functionality (50+ classes)
323
ChartType, FileFormat, Direction, HAlign, VAlign, BordersIndex, ColorIndex, RGBColor
324
325
# Data operations (40+ classes)
326
ConsolidationFunction, Calculation, DataType, SortOrder, FilterAction
327
328
# Formatting and display (60+ classes)
329
FontStyle, LineStyle, Pattern, TextOrientation, NumberFormat
330
331
# Chart and graphics (30+ classes)
332
ChartElementPosition, ChartLocation, ChartSplitType, PictureFormat
333
334
# Import/Export operations (20+ classes)
335
TextQualifier, ImportFormat, ExportFormat, WebFormatting
336
337
# Advanced features (50+ classes)
338
PivotTableSourceType, ProtectionMode, PrintLocation, PageSetup
339
340
# Office.js specific (4+ classes)
341
ObjectHandleIcons, WebExtensionStoreType, BindingType
342
```
343
344
### Platform-Specific Constants
345
346
Some constants are available only on specific platforms:
347
348
```python
349
# Windows-only constants (COM-specific)
350
if xw.engines.active.name == 'excel':
351
from xlwings.constants import (
352
WindowState, # Excel window states
353
DisplayFormat, # Display formatting options
354
PrintPreview, # Print preview options
355
)
356
357
# macOS-only constants (AppleScript-specific)
358
if xw.engines.active.name == 'applescript':
359
from xlwings.constants import (
360
MacScriptFormat, # AppleScript formatting
361
MacFileAccess, # File access permissions
362
)
363
364
# PRO-only constants (Office.js and advanced features)
365
if xw.__pro__:
366
from xlwings.constants import (
367
ServerConnectionType, # xlwings Server connections
368
RemoteExecutionMode, # Remote execution options
369
WebExcelFeatures, # Web Excel capabilities
370
)
371
```
372
373
## Types
374
375
```python { .api }
376
# Constant type definitions
377
ConstantClass = type # Type representing constant classes
378
ConstantValue = int # Most Excel constants are integers
379
380
# Specific constant types
381
ChartTypeConstant = int
382
FileFormatConstant = int
383
DirectionConstant = int
384
AlignmentConstant = int
385
ColorConstant = int
386
CalculationConstant = int
387
388
# Icon constants (Office.js)
389
IconConstant = str
390
391
# Collection of all constant classes
392
ExcelConstants = dict[str, ConstantClass]
393
```