Skip to content

Commit 519117a

Browse files
committed
[gatsby-transformer-excel] add option to disable raw output
1 parent f8e63df commit 519117a

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

packages/gatsby-transformer-excel/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,24 @@ Which would return:
108108
}
109109
}
110110
```
111+
112+
## Troubleshooting
113+
### Field Type Conflicts
114+
If your columns have different data types, e.g. numbers and strings graphql will omit these values and provide you with a field type conflicts warning during build.
115+
To solve this, you can set the rawOutput option of the plugin to false. This will convert all values to strings.
116+
117+
```javascript
118+
// In your gatsby-config.js
119+
module.exports = {
120+
plugins: [
121+
{
122+
resolve: `gatsby-transformer-excel`,
123+
options: {
124+
rawOutput: false,
125+
}
126+
}
127+
],
128+
};
129+
```
130+
131+
This will make sure, that all field types are converted to strings.

packages/gatsby-transformer-excel/src/gatsby-node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async function onCreateNode(
2727
let wb = XLSX.read(content, { type: `binary`, cellDates: true })
2828
wb.SheetNames.forEach((n, idx) => {
2929
let ws = wb.Sheets[n]
30-
let parsedContent = XLSX.utils.sheet_to_json(ws, { raw: true })
30+
let parsedContent = XLSX.utils.sheet_to_json(ws, { raw: options && `rawOutput` in options ? options.rawOutput : true })
3131

3232
if (_.isArray(parsedContent)) {
3333
const csvArray = parsedContent.map((obj, i) => {

0 commit comments

Comments
 (0)