# excel-build

> excel-build is a library for creating excel files in the browser

Latest version **1.1.2** (published 2024-03-18) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install excel-build
pnpm add excel-build
yarn add excel-build
bun add excel-build
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2024-03-18 |
| First published | 2023-11-01 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 27 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Soohyun Jung |
| Maintainers | sasha1107 |
| Keywords | excel, xls, xlsx, xlsb, xlsm, office, spreadsheet, js-xlsx, xlsx-js, sheetjs-style, sheetjs-style-v2 |

## Links

- npm: https://www.npmjs.com/package/excel-build
- Repository: https://github.com/sasha1107/excel-build
- Homepage: https://excel-build.vercel.app/en/docs
- Issues: https://github.com/sasha1107/excel-build/issues
- npm.io page: https://npm.io/package/excel-build

## Dependencies (1)

- [xlsx-js-style](https://npm.io/package/xlsx-js-style.md) ^1.2.0

## Alternatives

- [csv-to-markdown-table](https://npm.io/package/csv-to-markdown-table.md) — 47.0K weekly downloads
- [@sapphire/ratelimits](https://npm.io/package/@sapphire/ratelimits.md) — 4.4K weekly downloads
- [js-csvparser](https://npm.io/package/js-csvparser.md) — 2.0K weekly downloads
- [@adadapted/js-sdk](https://npm.io/package/@adadapted/js-sdk.md) — 251 weekly downloads
- [@grapecity/spread-sheets-sparklines](https://npm.io/package/@grapecity/spread-sheets-sparklines.md) — 103 weekly downloads

## Recent versions

- 1.1.2 (latest) — 2024-03-18
- 1.1.1 — 2024-02-17
- 1.1.0 — 2024-02-17
- 1.0.27 — 2024-01-19
- 1.0.26 — 2024-01-02
- 1.0.25 — 2024-01-02
- 1.0.24 — 2024-01-02
- 1.0.23 — 2024-01-02
- 1.0.22 — 2024-01-02
- 1.0.21 — 2023-12-27
- 1.0.20 — 2023-12-27
- 1.0.19 — 2023-12-26
- 1.0.18 — 2023-12-06
- 1.0.17 — 2023-12-06
- 1.0.16 — 2023-12-06
- … 16 more at https://npm.io/package/excel-build/versions

## README

# excel-build

[![npm](https://img.shields.io/npm/dt/excel-build)](https://npmtrends.com/excel-build)
[![npm](https://img.shields.io/npm/v/excel-build)](https://www.npmjs.com/package/excel-build)
<a href="https://excel-build.vercel.app/en" target="_blank">
<img height="20px" src="https://img.shields.io/badge/📚-%20Docs-%23000000"/>
</a>

# Installation

```sh
npm install excel-build
```

# Usage

## FileBuilder

```jsx
import { FileBuilder } from 'excel-build';

const excelFile = new FileBuilder('FILE_NAME');

excelFile.addSheet(sheet1).addSheet(sheet2).download();
```

### API

|   Method   |             Description              |    Type    |   Parameter    |    Returns    |
| :--------: | :----------------------------------: | :--------: | :------------: | :-----------: |
| `addSheet` |    Add a sheet to the Excel file.    | `function` | `SheetBuilder` | `FileBuilder` |
| `download` | Download the Excel file you created. | `function` |       -        |    `void`     |

## SheetBuilder

```jsx
import { SheetBuilder } from 'excel-build';

const data = [
  ['1', 'soohyun', 'sasha1107@naver.com', '01012345678', 'FE'],
  ['2', 'sasha', 'sasha981107@gmail.com', '01087654321', 'BE'],
];

const sheet1 = new SheetBuilder('sheet_1');
const sheet2 = new SheetBuilder('sheet_2')
  .appendThead(['id', 'name', 'email', 'phone', 'department'])
  .appendTbody(data)
  .mergeCell([0, 3], [4, 3]);
```

### API

|      Method       |                                       Description                                        |    Type    |                          Parameter                           |    Returns     |
| :---------------: | :--------------------------------------------------------------------------------------: | :--------: | :----------------------------------------------------------: | :------------: |
|   `appendThead`   |                             Adds a header row to the table.                              | `function` |             `(theadArr: string[], option: any)`              | `SheetBuilder` |
|    `appendRow`    |                                 Adds a row to the table.                                 | `function` |  `(tRowArr: string\|number\|boolean\|Date[], option: any)`   | `SheetBuilder` |
|   `appendTbody`   |                            Adds a row in array to the table.                             | `function` | `(tbodyArr: string\|number\|boolean\|Date[][], option: any)` | `SheetBuilder` |
| `appendCustomRow` |                           Add custom style rows to the table.                            | `function` |    `(row: string\|number\|boolean\|Date[], option: any)`     | `SheetBuilder` |
|    `mergeCell`    | Merge the cells with the starting cell [x0, y0] and the ending cell [x1, y1] as factors. | `function` |      `(start: [number, number], end: [number, number])`      | `SheetBuilder` |
|  `getWorkSheet`   |                              Returns the sheet you created.                              | `function` |                             `-`                              | `SheetBuilder` |
|  `getSheetName`   |                        Returns the name of the sheet you created.                        | `function` |                             `-`                              |    `string`    |
| `setColumnWidth`  |                    Set the width for a specific column on the sheet.                     | `function` |           `(columnNumber: number, width: number)`            | `SheetBuilder` |

## CellBuilder

```jsx
const data = ['1', 'soohyun', 'sasha1107@naver.com', '01012345678', 'FE'];

sheet1.appendCustomRow(
  data.map((item) =>
    new CellBuilder(item)
      .setFontSize(20)
      .setFontColor('#FFFFFF')
      .setBackgroundColor('#555555')
      .setFontItalic()
      .build()
  )
);
```

### API

|           Method           |                             Description                             |    Type    |           Parameter           |    Returns    |
| :------------------------: | :-----------------------------------------------------------------: | :--------: | :---------------------------: | :-----------: |
|   `setAlignMentVertical`   |                Sets the vertical alignment of cells.                | `function` | `center` \| `top` \| `bottom` | `CellBuilder` |
|  `setAlignMentHorizontal`  |               Sets the horizontal alignment of cells.               | `function` | `center` \| `left` \| `right` | `CellBuilder` |
|   `setAlignMentWrapText`   |                        Allow text wrapping.                         | `function` |              `-`              | `CellBuilder` |
| `setAlignMentTextRotation` | 180 is rotated down 180 degrees, 255 is special, aligned vertically | `function` |      `0 to 180, or 255`       | `CellBuilder` |
|        `setBorder`         |                  Sets the border style for cells.                   | `function` |  `null` \| `BorderStyleType`  | `CellBuilder` |
|    `setBackgroundColor`    |               Sets the background color of the cell.                | `function` |         `string(HEX)`         | `CellBuilder` |
|       `setFontColor`       |                     Set the color of the font.                      | `function` |         `string(HEX)`         | `CellBuilder` |
|       `setFontSize`        |                         Set the font size.                          | `function` |           `number`            | `CellBuilder` |
|       `setFontBold`        |                        Set the font in bold.                        | `function` |              `-`              | `CellBuilder` |
|      `setFontItalic`       |                       Set the font to italic.                       | `function` |              `-`              | `CellBuilder` |
|      `setFontStrike`       |                   Set strikethrough in the font.                    | `function` |              `-`              | `CellBuilder` |
|     `setFontUnderline`     |                         Underline the font.                         | `function` |              `-`              | `CellBuilder` |
|          `build`           |                            Build a cell.                            | `function` |              `-`              | `CellBuilder` |

<details>
  <summary><code>BorderStyleType</code></summary>

```ts
type BorderType =
  | 'dashDotDot'
  | 'dashDot'
  | 'dashed'
  | 'dotted'
  | 'hair'
  | 'mediumDashDotDot'
  | 'mediumDashDot'
  | 'mediumDashed'
  | 'medium'
  | 'slantDashDot'
  | 'thick'
  | 'thin';

type BorderStyleType = {
  top?: { style: BorderType; color: ColorType };
  bottom?: { style: BorderType; color: ColorType };
  left?: { style: BorderType; color: ColorType };
  right?: { style: BorderType; color: ColorType };
  diagonal?: {
    style: BorderType;
    color: ColorType;
    diagonalUp: boolean;
    diagonalDown: boolean;
  };
};
```

</details>

<details>
  <summary><code>ColorType</code></summary>

```ts
type ColorType = {
  rgb?: string;
  theme?: number;
  tint?: number;
};
```

</details>

## 🙏 Thanks

This project is a fork of [SheetJS/sheetjs](https://github.com/sheetjs/sheetjs) combined with code from
[sheetjs-style](https://www.npmjs.com/package/sheetjs-style) (by [ShanaMaid](https://github.com/ShanaMaid/))
and [sheetjs-style-v2](https://www.npmjs.com/package/sheetjs-style-v2) (by [Raul Gonzalez](https://www.npmjs.com/~armandourbina)) and [xlsx-js-style](https://github.com/gitbrent/xlsx-js-style) (by [gitbrent](https://github.com/gitbrent)).

All projects are under the Apache 2.0 License

- [sheetjs](https://github.com/SheetJS/sheetjs)
- [js-xlsx](https://github.com/protobi/js-xlsx)
- [sheetjs-style](https://www.npmjs.com/package/sheetjs-style)
- [sheetjs-style-v2](https://www.npmjs.com/package/sheetjs-style-v2)
- [xlsx-js-style](https://www.npmjs.com/package/xlsx-js-style)

---
_Source: https://npm.io/package/excel-build · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
