Drawings & images
Picture / chart anchors, image format detection.
Drawing
src/drawing/drawing.tsaddChartAt function
src/drawing/drawing.ts:193Anchor a chart to a worksheet at a single-cell ref. Lazy-allocates
ws.drawing. chart is the same ChartReference shape makeChart
DrawingItem accepts ({ space } for legacy chart, { cxSpace } for
chartex).
function addChartAt(ws: Worksheet, at: string, chart: ChartReference, opts?: { heightPx?: number; widthPx?: number }): DrawingItemParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
at | string | |
chart | ChartReference | |
opts? = {} | { heightPx?: number; widthPx?: number } |
Returns
DrawingItem
addImageAt function
src/drawing/drawing.ts:169Drop an image onto a worksheet at a single-cell anchor. Lazy-allocates
ws.drawing (as makeDrawing([])) on first call and appends a picture
DrawingItem.
image accepts either an XlsxImage (already loaded via loadImage) or raw
image bytes — in the bytes case, this helper sniffs the format with
loadImage itself.
at is a cell ref like "C3". Override widthPx / heightPx to scale;
otherwise the helper uses 96×96 defaults that look fine for typical icons.
function addImageAt(ws: Worksheet, at: string, image: XlsxImage | Uint8Array<ArrayBufferLike>, opts?: { heightPx?: number; widthPx?: number }): DrawingItemParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
at | string | |
image | XlsxImage | Uint8Array<ArrayBufferLike> | |
opts? = {} | { heightPx?: number; widthPx?: number } |
Returns
DrawingItem
listChartsOnSheet function
src/drawing/drawing.ts:224Read-only snapshot of every chart DrawingItem on the sheet. Each item has its anchor + chart reference.
function listChartsOnSheet(ws: Worksheet): readonly DrawingItem[]Parameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
readonly DrawingItem[]
listImagesOnSheet function
src/drawing/drawing.ts:215Read-only snapshot of every picture DrawingItem on the sheet. Returns the matching items (each with its anchor + picture reference). Empty array when the sheet has no drawing or only non-picture items.
function listImagesOnSheet(ws: Worksheet): readonly DrawingItem[]Parameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
readonly DrawingItem[]
makeChartDrawingItem function
src/drawing/drawing.ts:136function makeChartDrawingItem(anchor: DrawingAnchor, chart?: ChartReference): DrawingItemParameters
| Name | Type | Description |
|---|---|---|
anchor | DrawingAnchor | |
chart? = {} | ChartReference |
Returns
DrawingItem
makeDrawing function
src/drawing/drawing.ts:132function makeDrawing(items?: DrawingItem[]): DrawingParameters
| Name | Type | Description |
|---|---|---|
items? = [] | DrawingItem[] |
Returns
Drawing
makePictureDrawingItem function
src/drawing/drawing.ts:140function makePictureDrawingItem(anchor: DrawingAnchor, picture: PictureReference | XlsxImage): DrawingItemParameters
| Name | Type | Description |
|---|---|---|
anchor | DrawingAnchor | |
picture | PictureReference | XlsxImage |
Returns
DrawingItem
makeShapeDrawingItem function
src/drawing/drawing.ts:147function makeShapeDrawingItem(anchor: DrawingAnchor, shape: ShapeReference): DrawingItemParameters
| Name | Type | Description |
|---|---|---|
anchor | DrawingAnchor | |
shape | ShapeReference |
Returns
DrawingItem
removeAllCharts function
src/drawing/drawing.ts:256Drop every chart DrawingItem from the worksheet, leaving pictures and any other content kinds untouched. Returns the count removed.
function removeAllCharts(ws: Worksheet): numberParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
number
removeAllDrawingItems function
src/drawing/drawing.ts:234Drop every DrawingItem from the worksheet. Returns the count removed. The
ws.drawing field itself is left in place (empty) so subsequent addImageAt
/ addChartAt calls don't have to re-allocate.
function removeAllDrawingItems(ws: Worksheet): numberParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
number
removeAllImages function
src/drawing/drawing.ts:245Drop every picture DrawingItem from the worksheet, leaving charts and any other content kinds untouched. Returns the count removed.
function removeAllImages(ws: Worksheet): numberParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
number
Colors
src/drawing/dml/colors.tsmakeColor function
src/drawing/dml/colors.ts:122function makeColor(base: DmlColor, mods?: ColorMod[]): DmlColorWithModsParameters
| Name | Type | Description |
|---|---|---|
base | DmlColor | |
mods? = [] | ColorMod[] |
Returns
DmlColorWithMods
makeSchemeColor function
src/drawing/dml/colors.ts:120function makeSchemeColor(name: SchemeColorName): DmlColorParameters
| Name | Type | Description |
|---|---|---|
name | SchemeColorName |
Returns
DmlColor
makeSrgbColor function
src/drawing/dml/colors.ts:118function makeSrgbColor(rrggbb: string): DmlColorParameters
| Name | Type | Description |
|---|---|---|
rrggbb | string |
Returns
DmlColor
SCHEME_COLOR_NAMES const
src/drawing/dml/colors.ts:31const SCHEME_COLOR_NAMES: ReadonlyArray<SchemeColorName>VALUED_COLOR_MOD_KINDS const
src/drawing/dml/colors.ts:90Color mod kinds that carry a numeric val attribute.
const VALUED_COLOR_MOD_KINDS: ReadonlyArray<ColorMod["kind"]>VALUELESS_COLOR_MOD_KINDS const
src/drawing/dml/colors.ts:87Color mod kinds that take no val attribute (their elements are empty).
const VALUELESS_COLOR_MOD_KINDS: ReadonlyArray<ColorMod["kind"]>Text
src/drawing/dml/text.tsmakeBreak function
src/drawing/dml/text.ts:230function makeBreak(rPr?: RunProperties): TextRunParameters
| Name | Type | Description |
|---|---|---|
rPr? | RunProperties |
Returns
TextRun
makeParagraph function
src/drawing/dml/text.ts:232function makeParagraph(runs: TextRun[], pPr?: ParagraphProperties, endParaRPr?: RunProperties): TextParagraphParameters
| Name | Type | Description |
|---|---|---|
runs | TextRun[] | |
pPr? | ParagraphProperties | |
endParaRPr? | RunProperties |
Returns
TextParagraph
makeRun function
src/drawing/dml/text.ts:227function makeRun(text: string, rPr?: RunProperties): TextRunParameters
| Name | Type | Description |
|---|---|---|
text | string | |
rPr? | RunProperties |
Returns
TextRun
makeRunProperties function
src/drawing/dml/text.ts:225function makeRunProperties(opts?: Partial<RunProperties>): RunPropertiesParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | Partial<RunProperties> |
Returns
RunProperties
makeSimpleTextBody function
src/drawing/dml/text.ts:253Convenience: build a single-paragraph body with one run.
function makeSimpleTextBody(text: string, rPr?: RunProperties): TextBodyParameters
| Name | Type | Description |
|---|---|---|
text | string | |
rPr? | RunProperties |
Returns
TextBody
makeTextBody function
src/drawing/dml/text.ts:242function makeTextBody(paragraphs: TextParagraph[], bodyPr?: TextBodyProperties, lstStyle?: TextListStyle): TextBodyParameters
| Name | Type | Description |
|---|---|---|
paragraphs | TextParagraph[] | |
bodyPr? = {} | TextBodyProperties | |
lstStyle? | TextListStyle |
Returns
TextBody
Fill
src/drawing/dml/fill.tsmakeGradientFill function
src/drawing/dml/fill.ts:84function makeGradientFill(opts: { flip?: TileFlip; lineDir?: GradientLineDir; rotWithShape?: boolean; stops: GradientStop[] }): FillParameters
| Name | Type | Description |
|---|---|---|
opts | { flip?: TileFlip; lineDir?: GradientLineDir; rotWithShape?: boolean; stops: GradientStop[] } |
Returns
Fill
makeNoFill function
src/drawing/dml/fill.ts:81function makeNoFill(): FillReturns
Fill
makePatternFill function
src/drawing/dml/fill.ts:97function makePatternFill(opts: { bgClr?: DmlColorWithMods; fgClr?: DmlColorWithMods; preset: string }): FillParameters
| Name | Type | Description |
|---|---|---|
opts | { bgClr?: DmlColorWithMods; fgClr?: DmlColorWithMods; preset: string } |
Returns
Fill
makeSolidFill function
src/drawing/dml/fill.ts:82function makeSolidFill(color: DmlColorWithMods): FillParameters
| Name | Type | Description |
|---|---|---|
color | DmlColorWithMods |
Returns
Fill
PRESET_PATTERN_NAMES const
src/drawing/dml/fill.ts:109Excel's preset pattern names (54 entries, ECMA-376 §20.1.10.50; matches openpyxl).
const PRESET_PATTERN_NAMES: ReadonlyArray<string>Geometry
src/drawing/dml/geometry.tsmakePresetGeometry function
src/drawing/dml/geometry.ts:303function makePresetGeometry(prst: string, avLst?: ShapeGuide[]): PresetGeometryParameters
| Name | Type | Description |
|---|---|---|
prst | string | |
avLst? | ShapeGuide[] |
Returns
PresetGeometry
PRESET_SHAPE_NAMES const
src/drawing/dml/geometry.ts:16ECMA-376 §20.1.10.55 preset shape catalogue (ST_PresetShapeType, 187
entries). Pulled from openpyxl's PresetGeometry2D.prst Set so the test
corpus stays directly comparable.
const PRESET_SHAPE_NAMES: ReadonlyArray<string>Anchor
src/drawing/anchor.tsmakeOneCellAnchor function
src/drawing/anchor.ts:71Build a one-cell anchor pinned at from with an explicit pixel extent.
function makeOneCellAnchor(opts: { from: string | AnchorMarker; heightPx: number; widthPx: number }): DrawingAnchorParameters
| Name | Type | Description |
|---|---|---|
opts | { from: string | AnchorMarker; heightPx: number; widthPx: number } |
Returns
DrawingAnchor
Image
src/drawing/image.tsloadImage function
src/drawing/image.ts:253Build an XlsxImage from raw bytes. Detects the format and dimensions
automatically. Caller may pass an explicit format to override detection
(e.g. when bytes were read from a data: URL with a known MIME type) or
width/height to skip the parser.
function loadImage(bytes: Uint8Array, opts?: { format?: XlsxImageFormat; height?: number; width?: number }): XlsxImageParameters
| Name | Type | Description |
|---|---|---|
bytes | Uint8Array | |
opts? = {} | { format?: XlsxImageFormat; height?: number; width?: number } |
Returns
XlsxImage
Line
src/drawing/dml/line.tsmakeLine function
src/drawing/dml/line.ts:47function makeLine(opts?: Partial<LineProperties>): LinePropertiesParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | Partial<LineProperties> |
Returns
LineProperties
Shape properties
src/drawing/dml/shape-properties.tsmakeShapeProperties function
src/drawing/dml/shape-properties.ts:57function makeShapeProperties(opts?: Partial<ShapeProperties>): ShapePropertiesParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | Partial<ShapeProperties> |
Returns
ShapeProperties