This commit is contained in:
SheetJS 2023-01-21 23:23:58 -05:00
parent ba82e6c915
commit 562de3e267
2 changed files with 34 additions and 3 deletions

@ -357,6 +357,7 @@ Two files must be written:
- `sheetformer.ts` (the raw transformer module):
```ts title="sheetformer.ts"
// @ts-ignore
import { defineTransformer } from "@nuxt/content/transformers/utils";
import { read, utils } from "xlsx";
import { readFileSync } from "node:fs";
@ -434,7 +435,7 @@ Loading http://localhost:3000/pres should show some JSON data:
5) Create a page. Save the following content to `pages/pres.vue`:
```html
```html title="pages/pres.vue"
<script setup>
const {data} = await useAsyncData('s5s', () => queryContent('/pres').findOne());
</script>

@ -1,5 +1,5 @@
---
title: Headless Automation
title: Browser Automation
---
import Tabs from '@theme/Tabs';
@ -19,7 +19,37 @@ back to the automation script.
This demo focuses on exporting table data to a workbook. Headless browsers do
not generally support passing objects between the browser context and the
automation script, so the file data must be generated in the browser context
and sent back to the automation script for saving in the file system. Steps:
and sent back to the automation script for saving in the file system.
```mermaid
sequenceDiagram
autonumber off
actor U as User
participant C as Controller
participant B as Browser
U->>C: run script
rect rgba(255, 0, 0, 0.25)
C->>B: launch browser
B->>C: ready
C->>B: load URL
B->>C: site loaded
end
rect rgba(0, 127, 0, 0.25)
C->>B: add SheetJS script
B->>C: script loaded
end
rect rgba(255, 0, 0, 0.25)
C->>B: ask for file
Note over B: scrape tables
Note over B: generate workbook
B->>C: file bytes
end
rect rgba(0, 127, 0, 0.25)
C->>U: save file
end
```
Steps:
1) Launch the headless browser and load the target site.