Skip to content

Commit

Permalink
[docs] Add page for block-to-xlsx
Browse files Browse the repository at this point in the history
  • Loading branch information
x0k committed Dec 5, 2024
1 parent c4b88c9 commit 4c20400
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 7 deletions.
21 changes: 15 additions & 6 deletions apps/docs/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-check
import { fileURLToPath } from 'node:url'
import { fileURLToPath } from "node:url";
import { defineConfig } from "astro/config";
import starlight from "@astrojs/starlight";
import svelte from "@astrojs/svelte";
Expand Down Expand Up @@ -27,14 +27,23 @@ export default defineConfig({
"data-goatcounter": "https://json-table.counter.x0k.online/count",
async: true,
src: "https://json-table.counter.x0k.online/count.js",
}
},
},
],
sidebar: [
// {
// label: "Guides",
// autogenerate: { directory: "guides" },
// },
{
label: "Packages",
items: [
{
label: "@json-table/core",
link: "/",
},
{
label: "@json-table/block-to-xlsx",
link: "/block-to-xlsx/",
},
],
},
],
components: {
Head: "./src/components/custom-head.astro",
Expand Down
49 changes: 49 additions & 0 deletions apps/docs/src/content/docs/block-to-xlsx.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
title: Block to XLSX
---

import { Code, Card, CardGrid, LinkCard } from '@astrojs/starlight/components';

import Npm from '@/components/npm.astro';

Library for converting blocks to XLSX.

## Installation

<Npm pkg='@json-table/block-to-xlsx exceljs' />

## Usage

```typescript
import { Workbook } from "exceljs";
import { max, sum } from "@json-table/core/lib/math";
import { makeBlockFactory } from "@json-table/core/json-to-table";
import { renderBlockOnWorksheet } from "@json-table/block-to-xlsx";

const block = makeBlockFactory({
cornerCellValue: "",
joinPrimitiveArrayValues: true,
});

const wb = new Workbook();

/* Render table on the `Table` sheet */
renderBlockOnWorksheet(wb.addWorksheet("Table"), block(data), {
columnWidth: (column, i, m, table) => {
const counts = column.map((cell) => cell.count);
return Math.max(
Math.ceil(
(counts.reduce(sum) / table.height +
(counts.reduce(max) * column.length) / table.height) /
2
),
10
);
},
});

```

## License

MIT
2 changes: 1 addition & 1 deletion apps/docs/src/content/docs/index.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: JSON Table
# description: Main page
template: splash
# template: splash
hero:
tagline: Set of tools for converting JSON data into tables (HTML, XLSX, ASCII).
actions:
Expand Down

0 comments on commit 4c20400

Please sign in to comment.