Introducing the xlsx-kaku Library that Writes Excel Files in Node.js
Tags: react, node, typescript, excel
Published: 2024-03-31 01:50:03

As the developer of the Excel file output library [xlsx-kaku](https://github.com/motinados/xlsx-kaku), I am eager to directly share its features and advantages, as well as points to be mindful of. Released initially in December 2023, this library is sure to be of great assistance in generating Excel files, especially on the client side.


## Small Build Size: Enhanced Client-Side Performance

One of the library's main highlights is its small build size, which is particularly suitable for client-side use, directly leading to shorter download times and improved execution speed. As developers, we always prioritize user experience and hope this library will aid in achieving that goal.


Below are images from building a project made with Vite + React.



This is before adding xlsx-kaku.
![build size before adding xlsx-kaku](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p1rwz0t2eys3b4fuye7v.png)


This is after adding xlsx-kaku, with the gzip size only increasing by about 20kB.


![build size after adding xlsx-kaku](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/il2mr8tvetmlhvmtgyzb.png)

## Dedicated to File Output: Simple Structure for High Reliability

The library specializes in Excel file output, meaning its simple structure allows developers to easily understand and utilize it. The focus on file output alone reduces the chances of bugs and enables swift debugging if issues arise.

## Points of Caution

### Possibility of API Changes

Since this library was first released in December 2023 and continues to evolve, there might be changes to the API in the future. This variability could affect the project-dependent code, so developers need to be aware of compatibility issues and track library updates.

### Lack of Data Conversion Utilities

Moreover, data conversion utilities are not yet provided, which may necessitate writing additional code when using the library. This could potentially increase the development burden, especially in large projects or those with complex data structures.

## How to Use

Before trying the following code, please install with the command `npm install xlsx-kaku`.

### Basic Code
xlsx-kaku works on both the client-side and server-side.
```ts
import { Workbook } from "xlsx-kaku";

const wb = new Workbook();
const ws = wb.addWorksheet("Sheet1");

ws.setCell(0, 0, { type: "string", value: "Hello" });
ws.setCell(0, 1, { type: "number", value: 123 });

const xlsx = wb.generateXlsxSync();
```
### React Code
I turned the previous code into a React DownloadButton component.
```tsx
import { Workbook } from "xlsx-kaku";

export default function DownloadButton() {
  const handleDownload = () => {
    const wb = new Workbook();
    const ws = wb.addWorksheet("Sheet1");

    ws.setCell(0, 0, { type: "string", value: "Hello" });
    ws.setCell(0, 1, { type: "number", value: 123 });

    const xlsx = wb.generateXlsxSync();

    const blob = new Blob([xlsx], {
      type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    });
    const url = URL.createObjectURL(blob);
    const link = document.createElement("a");
    link.href = url;
    link.download = "sample.xlsx";
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
    URL.revokeObjectURL(url);
  };

  return (
    <div>
      <button onClick={handleDownload}>download xlsx</button>
    </div>
  );
}
```
## Conclusion

As a developer, I hope this library will bring value to your projects, contributing to performance optimization and simplification of the development process. Moving forward, we will focus especially on providing data conversion utilities to make it an even more user-friendly library.

## Related Links

- https://github.com/motinados/xlsx-kaku