xlsx-js-style

About

SheetJS with Style! 有风格的SheetJS!Create Excel spreadsheets with basic styling options using JavaScript.使用JavaScript创建具有基本样式选项的Excel电子表格。github

Installation安装

Install npm:用npm安装:

npm install xlsx-js-style

Install browser:在浏览器中安装

<script src="dist/xlsx.bundle.js"></script>

Core API

Style API样式API

Cell Style Example单元格样式示例

// STEP 1: Create a new workbook
const wb = XLSX.utils.book_new();

// STEP 2: Create data rows and styles
let row = [
	{ v: "Courier: 24", t: "s", s: { font: { name: "Courier", sz: 24 } } },
	{ v: "bold & color", t: "s", s: { font: { bold: true, color: { rgb: "FF0000" } } } },
	{ v: "fill: color", t: "s", s: { fill: { fgColor: { rgb: "E9E9E9" } } } },
	{ v: "line\nbreak", t: "s", s: { alignment: { wrapText: true } } },
];

// STEP 3: Create worksheet with rows; Add worksheet to workbook
const ws = XLSX.utils.aoa_to_sheet([row]);
XLSX.utils.book_append_sheet(wb, ws, "readme demo");

// STEP 4: Write Excel file to browser
XLSX.writeFile(wb, "xlsx-js-style-demo.xlsx");

Cell Style Properties单元格样式属性

Style Prop样式属性 Sub Prop子属性 Default默认值 Description/Values描述/值
alignment vertical bottom "top" or "center" or "bottom""top""center""bottom"
horizontal left "left" or "center" or "right""left""center""right"
wrapText false true or falsetruefalse
textRotation 0 0 to 180, or 255 // 180 is rotated down 180 degrees, 255 is special, aligned vertically0180,或255//180是向下旋转180度,255是特殊的,垂直对齐
border top { style: BORDER_STYLE, color: COLOR_STYLE }
bottom { style: BORDER_STYLE, color: COLOR_STYLE }
left { style: BORDER_STYLE, color: COLOR_STYLE }
right { style: BORDER_STYLE, color: COLOR_STYLE }
diagonal { style: BORDER_STYLE, color: COLOR_STYLE, diagonalUp: true/false, diagonalDown: true/false }
fill patternType "none" "solid" or "none"
fgColor foreground color: see 前景色:请参阅COLOR_STYLE
bgColor background color: see 背景色:请参阅COLOR_STYLE
font bold false font bold true or false粗体字truefalse
color font color 字色COLOR_STYLE
italic false font italic true or false斜体字truefalse
name "Calibri" font name字体名称
strike false font strikethrough true or false横贯线truefalse
sz "11" font size (points)字体大小(点)
underline false font underline true or false下划线truefalse
vertAlign "superscript" or "subscript"
numFmt 0 Ex: "0" // integer index to built in formats, see StyleBuilder.SSF property内置格式的整数索引,请参阅StyleBuilder.SSF属性
Ex: "0.00%" // string matching a built-in format, see StyleBuilder.SSF匹配内置格式的字符串,请参阅StyleBuilder.SSF
Ex: "0.0%" // string specifying a custom format指定自定义格式的字符串
Ex: "0.00%;\\(0.00%\\);\\-;@" // string specifying a custom format, escaping special characters指定自定义格式的字符串,转义特殊字符
Ex: "m/dd/yy" // string a date format using Excel's format notation使用Excel的格式表示法字符串化日期格式

COLOR_STYLE {object} Properties

Colors for border, fill, font are specified as an name/value object - use one of the following:borderfillfont的颜色被指定为名称/值对象-请使用以下选项之一:

Color Prop颜色属性 Description描述 Example示例
rgb hex RGB value十六进制RGB值 {rgb: "FFCC00"}
theme theme color index主题颜色索引 {theme: 4} // (0-n) // Theme color index 4 ("Blue, Accent 1")主题颜色索引4(“蓝色,强调文字颜色1”)
tint tint by percent按百分比着色 {theme: 1, tint: 0.4} // ("Blue, Accent 1, Lighter 40%")

BORDER_STYLE {string} Properties属性

Border style property is one of the following values:边框样式属性是以下值之一:

Border Notes边框注释

Borders for merged areas are specified for each cell within the merged area. 为合并区域内的每个单元格指定合并区域的边界。For example, to apply a box border to a merged area of 3x3 cells, border styles would need to be specified for eight different cells:例如,要将框边框应用于3x3单元格的合并区域,需要为八个不同的单元格指定边框样式:

Thanks谢谢

This project is a fork of SheetJS/sheetjs combined with code from sheetjs-style (by ShanaMaid) and sheetjs-style-v2 (by Raul Gonzalez).这个项目是SheetJS/sheetjs的分支,结合了sheetjs-style(由ShanaMaid编写)和sheetjs-style-v2(由Raul Gonzalez编写)的代码。

All projects are under the Apache 2.0 License所有项目都在Apache 2.0许可证下

License

Please consult the attached LICENSE file for details. All rights not explicitly granted by the Apache 2.0 License are reserved by the Original Author.