SheetJS with Style! 有风格的SheetJS!Create Excel spreadsheets with basic styling options using JavaScript.使用JavaScript创建具有基本样式选项的Excel电子表格。github
Install npm:用npm安装:
npm install xlsx-js-style
Install browser:在浏览器中安装
<script src="dist/xlsx.bundle.js"></script>
// 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");
alignment
, border
, fill
, font
, numFmt
.alignment
、border
、fill
、font
、numFmt
。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 false true 或false |
|
textRotation |
0 |
0 to 180 , or 255 // 180 is rotated down 180 degrees, 255 is special, aligned vertically0 到180 ,或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" "none" |
fgColor |
COLOR_STYLE |
||
bgColor |
COLOR_STYLE |
||
font |
bold |
false |
true or false true 或false |
color |
COLOR_STYLE |
||
italic |
false |
true or false true 或false |
|
name |
"Calibri" |
||
strike |
false |
true or false true 或false |
|
sz |
"11" |
||
underline |
false |
true or false true 或false |
|
vertAlign |
"superscript" "subscript" |
||
numFmt |
0 |
Ex: "0" // |
|
Ex: "0.00%" // |
|||
Ex: "0.0%" // |
|||
Ex: "0.00%;\\(0.00%\\);\\-;@" // |
|||
Ex: "m/dd/yy" // |
COLOR_STYLE
{object} PropertiesColors for border
, fill
, font
are specified as an name/value object - use one of the following:border
、fill
和font
的颜色被指定为名称/值对象-请使用以下选项之一:
rgb |
{rgb: "FFCC00"} |
|
theme |
{theme: 4} // (0-n) // |
|
tint |
{theme: 1, tint: 0.4} // ("Blue, Accent 1, Lighter 40%") |
BORDER_STYLE
{string} Border style property is one of the following values:边框样式属性是以下值之一:
dashDotDot
dashDot
dashed
dotted
hair
mediumDashDotDot
mediumDashDot
mediumDashed
medium
slantDashDot
thick
thin
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单元格的合并区域,需要为八个不同的单元格指定边框样式:
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许可证下
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.