メインコンテンツまでスキップ

.image()

画像を追加します。

ImageOptions

.image({
source: Buffer | string, // Buffer、URL、またはファイルパス
width?: number, // 幅(ピクセル)
height?: number, // 高さ(ピクセル)
row?: number, // 行位置(0-indexed)
col?: number, // 列位置(0-indexed)
})
プロパティ説明
sourceBuffer | string画像データ、URL、またはファイルパス(Node.jsのみ)
widthnumber画像の幅(ピクセル)
heightnumber画像の高さ(ピクセル)
rownumber配置する行(0から開始)
colnumber配置する列(0から開始)

source

Bufferを使用

import { readFileSync } from "fs";

const logoBuffer = readFileSync("./logo.png");

.image({
source: logoBuffer,
width: 150,
height: 75,
})

ファイルパスを使用(Node.jsのみ)

.image({
source: "./logo.png",
width: 150,
height: 75,
})

URLを使用(ブラウザ・Node.js両対応)

.image({
source: "https://example.com/logo.png",
width: 150,
height: 75,
})

使用例

import { readFileSync } from "fs";

const logoBuffer = readFileSync("./logo.png");

const output = await xlmake()
.sheet("レポート")
.text({ value: "月次レポート", style: { bold: true, fontSize: 16 } })
.space(1)
.image({
source: logoBuffer,
width: 150,
height: 75,
})
.space(2)
.table({
preset: "basic",
columns: [...],
data: [...],
})
.getNode();

関連