Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new plugin to handle excel files (#2343)
* Add new plugin to handle excel files * Run format
- Loading branch information
1 parent
d1f34cb
commit 6b402fb
Showing
15 changed files
with
599 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"env": { | ||
"browser": true | ||
}, | ||
"globals": { | ||
"graphql": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
public | ||
.cache | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# using-excel | ||
|
||
https://using-excel.gatsbyjs.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module.exports = { | ||
siteMetadata: { | ||
title: `gatsby-example-using-excel`, | ||
description: `Blazing-fast React.js static site generator`, | ||
}, | ||
plugins: [ | ||
`gatsby-transformer-excel`, | ||
{ | ||
resolve: `gatsby-source-filesystem`, | ||
options: { | ||
path: `${__dirname}/src/data`, | ||
name: `data`, | ||
}, | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "using-excel", | ||
"private": true, | ||
"description": "Gatsby example site using using-excel", | ||
"author": "SheetJS <dev@sheetjs.com>", | ||
"dependencies": { | ||
"gatsby": "latest", | ||
"gatsby-link": "latest", | ||
"gatsby-source-filesystem": "latest", | ||
"gatsby-transformer-excel": "latest" | ||
}, | ||
"license": "MIT", | ||
"main": "n/a", | ||
"scripts": { | ||
"develop": "gatsby develop", | ||
"build": "gatsby build" | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React from "react" | ||
|
||
class IndexComponent extends React.Component { | ||
render() { | ||
const data1 = this.props.data.allLettersXlsxSheet1.edges | ||
const data2 = this.props.data.allLettersXlsxSheet2.edges | ||
return ( | ||
<div> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th colSpan="2">Sheet1</th> | ||
</tr> | ||
<tr> | ||
<th>Letter</th> | ||
<th>ASCII Value</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{data1.map((row, i) => ( | ||
<tr key={`${row.node.value} ${i}`}> | ||
<td>{row.node.letter}</td> | ||
<td>{row.node.value}</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th colSpan="2">Sheet2</th> | ||
</tr> | ||
<tr> | ||
<th>Letter</th> | ||
<th>ASCII Value</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{data2.map((row, i) => ( | ||
<tr key={`${row.node.value} ${i}`}> | ||
<td>{row.node.letter}</td> | ||
<td>{row.node.value}</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
export default IndexComponent | ||
|
||
export const IndexQuery = graphql` | ||
query IndexQuery { | ||
allLettersXlsxSheet1 { | ||
edges { | ||
node { | ||
letter | ||
value | ||
} | ||
} | ||
} | ||
allLettersXlsxSheet2 { | ||
edges { | ||
node { | ||
letter | ||
value | ||
} | ||
} | ||
} | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/*.js | ||
!index.js | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Logs | ||
logs | ||
*.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git | ||
node_modules | ||
*.un~ | ||
yarn.lock | ||
src | ||
flow-typed | ||
coverage | ||
decls | ||
examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# gatsby-transformer-excel | ||
|
||
Parses Excel files into JSON arrays. | ||
|
||
## Install | ||
|
||
`npm install --save gatsby-transformer-excel` | ||
|
||
## How to use | ||
|
||
```javascript | ||
// In your gatsby-config.js | ||
plugins: [ | ||
`gatsby-transformer-excel`, | ||
] | ||
``` | ||
|
||
## Parsing algorithm | ||
|
||
The parsing is powered by the [SheetJS / js-xlsx](https://git.io/xlsx) library. | ||
Each row of each worksheet is converted into a node whose keys are determined | ||
by the first row and whose type is determined by the name of the worksheet. | ||
|
||
So if your project has a `letters.xlsx` with two worksheets: | ||
|
||
``` | ||
------ Sheet1 ------ | ||
/| A | B | | ||
-+---------+-------+ | ||
1| letter | value | | ||
-+---------+-------+ | ||
2| a | 97 | | ||
-+---------+-------+ | ||
3| b | 98 | | ||
------ Sheet2 ------ | ||
/| A | B | | ||
-+---------+-------+ | ||
1| letter | value | | ||
-+---------+-------+ | ||
2| A | 65 | | ||
-+---------+-------+ | ||
3| B | 66 | | ||
``` | ||
|
||
the following nodes would be created: | ||
|
||
```javascript | ||
[ | ||
{ letter: 'a', value: 97, type: 'LettersXlsxSheet1' }, | ||
{ letter: 'b', value: 98, type: 'LettersXlsxSheet1' }, | ||
{ letter: 'A', value: 65, type: 'LettersXlsxSheet2' }, | ||
{ letter: 'B', value: 66, type: 'LettersXlsxSheet2' }, | ||
] | ||
``` | ||
|
||
## How to query | ||
|
||
You'd be able to query your letters like: | ||
|
||
```graphql | ||
{ | ||
allLettersXlsxSheet1 { | ||
edges { | ||
node { | ||
letter | ||
value | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Which would return: | ||
|
||
```javascript | ||
{ | ||
allLettersXlsxSheet1: { | ||
edges: [ | ||
{ | ||
node: { | ||
letter: 'a' | ||
value: 97 | ||
} | ||
}, | ||
{ | ||
node: { | ||
letter: 'b' | ||
value: 98 | ||
} | ||
}, | ||
] | ||
} | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// noop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "gatsby-transformer-excel", | ||
"version": "0.1.0", | ||
"description": "Gatsby transformer plugin for Excel spreadsheets", | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "babel src --out-dir . --ignore __tests__", | ||
"watch": "babel -w src --out-dir . --ignore __tests__", | ||
"prepublish": "cross-env NODE_ENV=production npm run build" | ||
}, | ||
"keywords": [ | ||
"gatsby", | ||
"excel", | ||
"gatsby-plugin" | ||
], | ||
"author": "SheetJS <dev@sheetjs.com>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"babel-runtime": "^6.26.0", | ||
"xlsx": "^0.11.5" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"cross-env": "^5.0.5" | ||
} | ||
} |
Oops, something went wrong.