CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-xlwings

Python library for seamless bidirectional communication between Python and Excel across Windows and macOS platforms.

Overview
Eval results
Files

constants.mddocs/

Constants and Enumerations

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.

Capabilities

Excel Constants Overview

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.

# Available in xlwings.constants module
# Import pattern:
from xlwings.constants import (
    ChartType, XlChartType,
    Direction, InsertShiftDirection, 
    FileFormat, XlFileFormat,
    RGBColor, ColorIndex,
    HAlign, VAlign,
    # ... and 240+ other constant classes
)

# Top-level namespace constant
from xlwings import ObjectHandleIcons  # Available directly

Chart and Visualization Constants

Constants for chart types, formatting, and visualization elements.

# Chart type constants
class ChartType:
    xlArea = -4098
    xlAreaStacked = 76
    xlAreaStacked100 = 77
    xlBarClustered = 57
    xlBarOfPie = 71
    xlBarStacked = 58
    xlBarStacked100 = 59
    xlBubble = 15
    xlBubble3DEffect = 87
    xlColumnClustered = 51
    xlColumnStacked = 52
    xlColumnStacked100 = 53
    xlConeBarClustered = 102
    xlConeCol = 105
    xlCylinderBarClustered = 95
    xlDoughnut = -4120
    xlDoughnutExploded = 80
    xlLine = 4
    xlLineMarkers = 65
    xlLineMarkersStacked = 66
    xlLineMarkersStacked100 = 67
    xlLineStacked = 63
    xlLineStacked100 = 64
    xlPie = 5
    xlPieExploded = 69
    xlPieOfPie = 68
    xlRadar = -4151
    xlRadarFilled = 82
    xlRadarMarkers = 81
    xlRegionMap = 140
    xlStockHLC = 88
    xlStockOHLC = 89
    xlStockVHLC = 90
    xlStockVOHLC = 91
    xlSurface = 83
    xlSurfaceTopView = 85
    xlSurfaceTopViewWireframe = 86
    xlSurfaceWireframe = 84
    xlXYScatter = -4169
    xlXYScatterLines = 74
    xlXYScatterLinesNoMarkers = 75
    xlXYScatterSmooth = 72
    xlXYScatterSmoothNoMarkers = 73

# Color constants
class RGBColor:
    rgbAliceBlue = 16775408
    rgbAntiqueWhite = 14150650
    rgbAqua = 16776960
    rgbAquamarine = 13959039
    rgbAzure = 16777200
    rgbBeige = 14480885
    rgbBisque = 12903679
    rgbBlack = 0
    rgbBlanchedAlmond = 13495295
    rgbBlue = 16711680
    rgbBlueViolet = 14822282
    rgbBrown = 2763429
    rgbBurlyWood = 8894686
    # ... many more color constants

class ColorIndex:
    xlColorIndexAutomatic = -4105
    xlColorIndexNone = -4142

File Operations Constants

Constants for file formats, save options, and import/export operations.

class FileFormat:
    xlAddIn = 18
    xlCSV = 6
    xlCSVMac = 22
    xlCSVWindows = 23
    xlDBF2 = 7
    xlDBF3 = 8
    xlDBF4 = 11
    xlDIF = 9
    xlExcel12 = 50
    xlExcel2 = 16
    xlExcel3 = 29
    xlExcel4 = 33
    xlExcel4Workbook = 35
    xlExcel5 = 39
    xlExcel7 = 39
    xlExcel8 = 56
    xlExcel9 = 43
    xlHtml = 44
    xlIntlAddIn = 26
    xlIntlMacro = 25
    xlJSON = 51
    xlOpenDocumentSpreadsheet = 60
    xlOpenXMLStrictWorkbook = 61
    xlOpenXMLTemplate = 54
    xlOpenXMLTemplateMacroEnabled = 53
    xlOpenXMLWorkbook = 51
    xlOpenXMLWorkbookMacroEnabled = 52
    xlPDF = 57
    xlSYLK = 2
    xlTemplate = 17
    xlTemplate8 = 17
    xlText = -4158
    xlTextMac = 19
    xlTextPrinter = 36
    xlTextWindows = 20
    xlUnicodeText = 42
    xlWebArchive = 45
    xlWJ2WD1 = 14
    xlWJ3 = 40
    xlWJ3FJ3 = 41
    xlWK1 = 5
    xlWK1ALL = 31
    xlWK1FMT = 30
    xlWK3 = 15
    xlWK3FM3 = 32
    xlWK4 = 38
    xlWKS = 4
    xlWorkbookDefault = 51
    xlWorkbookNormal = -4143
    xlXPS = 58

Range and Cell Operations Constants

Constants for range operations, directions, and cell manipulations.

class Direction:
    xlDown = -4121
    xlToLeft = -4159
    xlToRight = -4161
    xlUp = -4162

class InsertShiftDirection:
    xlShiftDown = -4121
    xlShiftToRight = -4161

class DeleteShiftDirection:
    xlShiftToLeft = -4159
    xlShiftUp = -4162

class HAlign:
    xlHAlignCenter = -4108
    xlHAlignCenterAcrossSelection = 7
    xlHAlignDistributed = -4117
    xlHAlignFill = 5
    xlHAlignGeneral = 1
    xlHAlignJustify = -4130
    xlHAlignLeft = -4131
    xlHAlignRight = -4152

class VAlign:
    xlVAlignBottom = -4107
    xlVAlignCenter = -4108
    xlVAlignDistributed = -4117
    xlVAlignJustify = -4130
    xlVAlignTop = -4160

class BordersIndex:
    xlDiagonalDown = 5
    xlDiagonalUp = 6
    xlEdgeBottom = 9
    xlEdgeLeft = 7
    xlEdgeRight = 10
    xlEdgeTop = 8
    xlInsideHorizontal = 12
    xlInsideVertical = 11

Calculation and Formula Constants

Constants for calculation modes, formula types, and mathematical operations.

class Calculation:
    xlCalculationAutomatic = -4105
    xlCalculationManual = -4135
    xlCalculationSemiautomatic = 2

class FormulaLabel:
    xlColumnLabels = 2
    xlMixedLabels = 3
    xlNoLabels = -4142
    xlRowLabels = 1

class ConsolidationFunction:
    xlAverage = -4106
    xlCount = -4112
    xlCountNums = -4113
    xlMax = -4136
    xlMin = -4139
    xlProduct = -4149
    xlStDev = -4155
    xlStDevP = -4156
    xlSum = -4157
    xlUnknown = 1000
    xlVar = -4164
    xlVarP = -4165

Office.js Integration Constants

Constants specific to Office.js and web-based Excel integration (PRO features).

class ObjectHandleIcons:
    """Icons for object handles in Office.js (available in top-level namespace)."""
    
    # Standard icons
    ICON_ADD = "add"
    ICON_CANCEL = "cancel" 
    ICON_CHECK = "check"
    ICON_DELETE = "delete"
    ICON_EDIT = "edit"
    ICON_FILTER = "filter"
    ICON_REFRESH = "refresh"
    ICON_SAVE = "save"
    ICON_SEARCH = "search"
    ICON_SETTINGS = "settings"
    ICON_SORT = "sort"
    ICON_WARNING = "warning"
    
    # Chart icons
    ICON_CHART_BAR = "chart-bar"
    ICON_CHART_LINE = "chart-line"
    ICON_CHART_PIE = "chart-pie"
    ICON_CHART_SCATTER = "chart-scatter"
    
    # Data icons
    ICON_DATABASE = "database"
    ICON_EXPORT = "export" 
    ICON_IMPORT = "import"
    ICON_TABLE = "table"

Usage Examples

Common patterns for using xlwings constants:

import xlwings as xw
from xlwings.constants import (
    ChartType, FileFormat, Direction, 
    HAlign, VAlign, RGBColor
)

# Chart creation with constants
wb = xw.books.add()
ws = wb.sheets[0]

# Add sample data
ws.range('A1:B5').value = [
    ['Month', 'Sales'],
    ['Jan', 100], ['Feb', 120], 
    ['Mar', 140], ['Apr', 110]
]

# Create chart using constants
chart = ws.charts.add()
chart.chart_type = ChartType.xlColumnClustered
chart.source_data = ws.range('A1:B5')

# Range operations with direction constants
start_cell = ws.range('A1')
last_row = start_cell.end(Direction.xlDown)
last_col = start_cell.end(Direction.xlToRight)

# Formatting with alignment constants
data_range = ws.range('A1:B5')
data_range.api.HorizontalAlignment = HAlign.xlHAlignCenter
data_range.api.VerticalAlignment = VAlign.xlVAlignCenter

# Color formatting
ws.range('A1:B1').color = RGBColor.rgbLightBlue
ws.range('A1:B1').api.Font.Color = RGBColor.rgbWhite

# Save with file format constants
wb.save('/path/to/file.xlsx')  # Default format
wb.api.SaveAs('/path/to/file.csv', FileFormat.xlCSV)
wb.api.SaveAs('/path/to/file.pdf', FileFormat.xlPDF)

Constant Categories Summary

The 254 constant classes are organized into these major categories:

# Core Excel functionality (50+ classes)
ChartType, FileFormat, Direction, HAlign, VAlign, BordersIndex, ColorIndex, RGBColor

# Data operations (40+ classes)  
ConsolidationFunction, Calculation, DataType, SortOrder, FilterAction

# Formatting and display (60+ classes)
FontStyle, LineStyle, Pattern, TextOrientation, NumberFormat

# Chart and graphics (30+ classes)
ChartElementPosition, ChartLocation, ChartSplitType, PictureFormat

# Import/Export operations (20+ classes)
TextQualifier, ImportFormat, ExportFormat, WebFormatting

# Advanced features (50+ classes)
PivotTableSourceType, ProtectionMode, PrintLocation, PageSetup

# Office.js specific (4+ classes)
ObjectHandleIcons, WebExtensionStoreType, BindingType

Platform-Specific Constants

Some constants are available only on specific platforms:

# Windows-only constants (COM-specific)
if xw.engines.active.name == 'excel':
    from xlwings.constants import (
        WindowState,  # Excel window states
        DisplayFormat,  # Display formatting options
        PrintPreview,  # Print preview options
    )

# macOS-only constants (AppleScript-specific)
if xw.engines.active.name == 'applescript':
    from xlwings.constants import (
        MacScriptFormat,  # AppleScript formatting
        MacFileAccess,   # File access permissions
    )

# PRO-only constants (Office.js and advanced features)
if xw.__pro__:
    from xlwings.constants import (
        ServerConnectionType,  # xlwings Server connections
        RemoteExecutionMode,   # Remote execution options
        WebExcelFeatures,     # Web Excel capabilities
    )

Types

# Constant type definitions
ConstantClass = type  # Type representing constant classes
ConstantValue = int   # Most Excel constants are integers

# Specific constant types
ChartTypeConstant = int
FileFormatConstant = int
DirectionConstant = int
AlignmentConstant = int
ColorConstant = int
CalculationConstant = int

# Icon constants (Office.js)
IconConstant = str

# Collection of all constant classes
ExcelConstants = dict[str, ConstantClass]

Install with Tessl CLI

npx tessl i tessl/pypi-xlwings

docs

charts-visualization.md

cli.md

collections-functions.md

constants.md

conversion.md

core-objects.md

index.md

pro-features.md

udfs.md

utilities.md

tile.json