Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: LuisEnMarroquin/json-as-xlsx
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.1.0
Choose a base ref
...
head repository: LuisEnMarroquin/json-as-xlsx
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref

Commits on Sep 30, 2021

  1. Copy the full SHA
    2fef1ac View commit details

Commits on Oct 28, 2021

  1. Fix typo in IColumn type

    elyse0 committed Oct 28, 2021
    Copy the full SHA
    84043d4 View commit details
  2. Copy the full SHA
    9430d26 View commit details
  3. Copy the full SHA
    c67dfd5 View commit details
  4. Copy the full SHA
    6876f0b View commit details
  5. Change IData name to IJsonSheet

    I think "data" was far too general, so this is the name
    I came up with, but I'm open to suggestions (:
    elyse0 committed Oct 28, 2021
    Copy the full SHA
    b7d2c7c View commit details
  6. Copy the full SHA
    e9b7ea4 View commit details
  7. Copy the full SHA
    d219b47 View commit details
  8. Create xlsx function

    This is the first step into dividing this function into
    smaller and type defined functions.
    elyse0 committed Oct 28, 2021
    Copy the full SHA
    2968aa4 View commit details
  9. Add IJsonSheetRow type

    elyse0 committed Oct 28, 2021
    Copy the full SHA
    a8766e6 View commit details
  10. Add getJsonSheetRow function

    This function takes care of returning each content item
    as a jsonSheetRow and avoids using any types
    elyse0 committed Oct 28, 2021
    Copy the full SHA
    a716fde View commit details
  11. Add IWorksheetColumnWidth type

    elyse0 committed Oct 28, 2021
    Copy the full SHA
    9ee7857 View commit details
  12. Add getWorksheetColumnWidths function

    This function returns the appropriate column widths to
    fit the content in each column.
    elyse0 committed Oct 28, 2021
    Copy the full SHA
    5f3c51d View commit details
  13. Add getWorksheet function

    This function takes care of creating the worksheet
    based on the jsonSheet and settings.
    elyse0 committed Oct 28, 2021
    Copy the full SHA
    29f9752 View commit details
  14. Add writeWorkbook function

    This function returns a buffer if writeOptions.type
    is buffer, otherwise tries to write the file.
    elyse0 committed Oct 28, 2021
    Copy the full SHA
    4c165ed View commit details
  15. Verify that jsonSheets are not empty

    This is the same problem as with IColumn[] and IContent[],
    we could create a type IJsonSheets: [IJsonSheet, ...IJSonSheets[]]
    to prevent this, but I'm not sure if we should.
    elyse0 committed Oct 28, 2021
    Copy the full SHA
    ee65bcf View commit details
  16. Refactor variables in xlsx function

    This is optional but in my opinion looks better.
    elyse0 committed Oct 28, 2021
    Copy the full SHA
    f74e6f2 View commit details
  17. Copy the full SHA
    93ea2e8 View commit details
  18. Add tests using Jest

    I added these tests to make sure I didn't break anything
    obvious, but they still don't check the exported files,
    only the return types.
    
    That being said, I think they could be useful for testing
    future changes. (:
    elyse0 committed Oct 28, 2021
    Copy the full SHA
    a2fddfe View commit details

Commits on Oct 30, 2021

  1. Use Date and IContent instead of object

    The object type ({}) can't contain any properties, that makes
    it not very useful.
    elyse0 committed Oct 30, 2021
    Copy the full SHA
    854f17e View commit details
  2. Add getContentProperty function

    This function allows us to access deep drops without the need
    of a function, just the property path.
    elyse0 committed Oct 30, 2021
    Copy the full SHA
    fc07d34 View commit details
  3. Add contentProperty tests

    These tests verify the recently added getContentProperty function.
    elyse0 committed Oct 30, 2021
    Copy the full SHA
    ba03f03 View commit details
  4. Add getJsonSheetRow tests

    elyse0 committed Oct 30, 2021
    Copy the full SHA
    8b6b0c2 View commit details
  5. Copy the full SHA
    72e1bf5 View commit details

Commits on Nov 3, 2021

  1. Merge pull request #21 from elyse0/develop

    Migrate project to Typescript
    LuisEnMarroquin authored Nov 3, 2021
    Copy the full SHA
    74f1dcd View commit details

Commits on Nov 7, 2021

  1. Copy the full SHA
    32e02ef View commit details
  2. Copy the full SHA
    d5e9441 View commit details
  3. Copy the full SHA
    aceb6ba View commit details
  4. Copy the full SHA
    5d5578c View commit details

Commits on Nov 9, 2021

  1. Copy the full SHA
    bbc9371 View commit details

Commits on Nov 17, 2021

  1. Use simple IColumn and IContent array

    The [IColumn, ...IColumn] and [IContent, ...IContent[]] were to make
    sure that they couldn't be empty, but now I think it would be better
    to handle those cases instead of throwing a type error.
    elyse0 committed Nov 17, 2021
    Copy the full SHA
    dea85ec View commit details
  2. Copy the full SHA
    acdd761 View commit details
  3. Copy the full SHA
    2fab9ea View commit details

Commits on Nov 22, 2021

  1. Merge pull request #24 from elyse0/empty-content

    Allow IContent[] to be empty and return an xlsx file with only column labels in that case
    LuisEnMarroquin authored Nov 22, 2021
    Copy the full SHA
    69698ac View commit details
  2. Copy the full SHA
    9b0ddc2 View commit details
  3. Copy the full SHA
    cd0a169 View commit details
  4. Copy the full SHA
    f4a58de View commit details
  5. Copy the full SHA
    53e2e39 View commit details
  6. Copy the full SHA
    838850e View commit details

Commits on Nov 26, 2021

  1. Copy the full SHA
    882c9db View commit details
  2. Copy the full SHA
    d766c5b View commit details

Commits on Nov 27, 2021

  1. Copy the full SHA
    9dfa63e View commit details

Commits on Nov 29, 2021

  1. Merge pull request #26 from elyse0/mini-xlsx-2

    Use xlsx mini
    LuisEnMarroquin authored Nov 29, 2021
    Copy the full SHA
    1a480b9 View commit details
  2. Copy the full SHA
    af3acc3 View commit details

Commits on Dec 13, 2021

  1. Copy the full SHA
    976b86f View commit details
  2. Copy the full SHA
    657aec3 View commit details
  3. Copy the full SHA
    136a09c View commit details
  4. Copy the full SHA
    ffaa64a View commit details

Commits on Dec 16, 2021

  1. 3
    Copy the full SHA
    ef17a8f View commit details
  2. Copy the full SHA
    c5414d5 View commit details
Showing with 15,445 additions and 12,691 deletions.
  1. +45 −0 .github/workflows/main.yml
  2. +0 −52 .github/workflows/publish.yml
  3. +11 −0 .github/workflows/tests.yml
  4. +3 −4 .gitignore
  5. +1 −0 .nvmrc
  6. +4 −0 .prettierrc.json
  7. +0 −5 .vscode/extensions.json
  8. +0 −20 .vscode/settings.json
  9. +1 −0 CNAME
  10. +1 −0 CODEOWNERS
  11. +17 −27 CONTRIBUTING.md
  12. +1 −1 LICENSE
  13. +75 −29 README.md
  14. +0 −58 index.ts
  15. +6 −0 lerna.json
  16. +0 −12,275 package-lock.json
  17. +11 −60 package.json
  18. +18 −0 packages/demo-express/package.json
  19. +17 −0 packages/demo-express/src/index.html
  20. +70 −0 packages/demo-express/src/server.ts
  21. 0 { → packages/demo-express}/tsconfig.json
  22. +1 −0 packages/demo-reactjs/.env
  23. +38 −0 packages/demo-reactjs/package.json
  24. BIN packages/demo-reactjs/public/favicon.ico
  25. +43 −0 packages/demo-reactjs/public/index.html
  26. BIN packages/demo-reactjs/public/logo192.png
  27. BIN packages/demo-reactjs/public/logo512.png
  28. +25 −0 packages/demo-reactjs/public/manifest.json
  29. +3 −0 packages/demo-reactjs/public/robots.txt
  30. +51 −0 packages/demo-reactjs/src/App.tsx
  31. +70 −0 packages/demo-reactjs/src/index.css
  32. +12 −0 packages/demo-reactjs/src/index.tsx
  33. +1 −0 packages/demo-reactjs/src/react-app-env.d.ts
  34. +26 −0 packages/demo-reactjs/tsconfig.json
  35. +16 −0 packages/main-library/jest.config.js
  36. +67 −0 packages/main-library/package.json
  37. +53 −0 packages/main-library/src/__tests__/contentProperty.test.ts
  38. +63 −0 packages/main-library/src/__tests__/getJsonSheetRow.test.ts
  39. +35 −0 packages/main-library/src/__tests__/getWorksheetColumWidths.test.ts
  40. +206 −0 packages/main-library/src/__tests__/index.test.ts
  41. +222 −0 packages/main-library/src/index.ts
  42. +23 −0 packages/main-library/tsconfig.json
  43. BIN public/favicon.ico
  44. +0 −16 public/index.html
  45. +0 −58 server.js
  46. +0 −71 src/App.vue
  47. +0 −10 src/main.js
  48. +0 −5 vue.config.js
  49. +14,209 −0 yarn.lock
45 changes: 45 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Prod deploy

on:
push:
branches:
- main

jobs:
deploy:
if: github.repository == 'LuisEnMarroquin/json-as-xlsx'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: yarn test
- run: yarn build
- name: Copy files to library output folder
run: |
cp README.md packages/main-library/README.md
cp LICENSE packages/main-library/LICENSE
- name: Set environment variable for GitHub
run: |
echo "CURRENT_VERSION=$(node -e "console.log('v' + require('./package.json').version)")" >> $GITHUB_ENV
echo CURRENT_VERSION ${{ env.CURRENT_VERSION }}
working-directory: packages/main-library/
- name: Publish package to NPM registry
run: |
echo "//registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN" > ~/.npmrc
npm publish --access public
env:
NPM_AUTH_TOKEN: ${{ secrets.TOKEN_NPM }}
working-directory: packages/main-library/
- name: Create a new GitHub release
run: |
echo ${{ secrets.TOKEN_GITHUB }} > nothing.md
gh auth login --with-token < nothing.md
gh release create ${{ env.CURRENT_VERSION }} -F README.md -t "Released ${{ env.CURRENT_VERSION }}"
- name: Prepare static files for deployment
run: yarn run static
- uses: JamesIves/github-pages-deploy-action@v4
with:
folder: build
branch: gh-pages
git-config-name: LuisEnMarroquin
git-config-email: mluis651@gmail.com
52 changes: 0 additions & 52 deletions .github/workflows/publish.yml

This file was deleted.

11 changes: 11 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Test suites

on: [push, pull_request_target]

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: yarn test
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Folders
dist/
build/
coverage/
node_modules/

# File managers
@@ -8,14 +10,11 @@ node_modules/
desktop.ini

# Other lockfiles
yarn.lock
package-lock.json
npm-shrinkwrap.json

# Log files
*.log*

# Excel files
*.xlsx

# Now this is a typescript project
index.js
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16.14.2
4 changes: 4 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"semi": false,
"printWidth": 512
}
5 changes: 0 additions & 5 deletions .vscode/extensions.json

This file was deleted.

20 changes: 0 additions & 20 deletions .vscode/settings.json

This file was deleted.

1 change: 1 addition & 0 deletions CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
xlsx.marroquin.dev
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @LuisEnMarroquin
44 changes: 17 additions & 27 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,33 @@
# Dev environment
## Requirements

Here are the **node** and **npm** versions that we use to develop this project
These are the software versions I personally use

```shell
$ node --version && npm --version
v14.17.4
6.14.14
$ node --version
v16.14.2
$ npm --version
8.5.0
$ yarn --version
1.22.19
```

After cloning the repository, run `npm install` to install the dependencies
Other versions may work but I can not guarantee that

## Run in dev mode
## Develop locally

You'll have to use 2 consoles to run the app, one for the actual package `index.ts`
It will start the library and demo project in dev mode

```shell
$ npm run start
$ yarn start
```

Then if you want to test the package with `VueJS` you can execute the following
- Express: localhost:5500
- ReactJS: localhost:6500

```shell
$ npm run start-client
```

Otherwise if you want to test with `express` use the following command

```shell
$ npm run start-server
```

## Linting code

This project uses `ts-standard` for linting, included in optional dependencies
## Code linting

```shell
$ npm run lint
```
This project uses `prettier` for linting code

## Deploy to NPM

There is a pipeline for that, just do a PR and I'll merge it
There is a pipeline for that, just do a PR and it will be merged
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 - present, LuisEnMarroquin <luis@marroquin.dev>
Copyright (c) 2022, LuisEnMarroquin <xlsx@marroquin.dev>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
104 changes: 75 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,104 @@
# json-as-xlsx

This is a tool that helps to build an excel from a json and it depends only on `xlsx`
This is a tool that helps to build an excel from a json and it depends only on `xlsx` library

Now with version **2.0.0** and above supports multiple sheets and custom styling
You can see a live example of it working on any of this sites (there are many just in case):

You can see a live example of how it works on this site: [luisenmarroquin.github.io/json-as-xlsx](https://luisenmarroquin.github.io/json-as-xlsx)
- [xlsx.pages.dev](https://xlsx.pages.dev)
- [xlsx.marroquin.dev](https://xlsx.marroquin.dev)
- [xlsx.luismarroquin.com](https://xlsx.luismarroquin.com)

## Usage

Just import and use it

```js
let xlsx = require('json-as-xlsx')
import xlsx from "json-as-xlsx"
// or require
let xlsx = require("json-as-xlsx")

let data = [
{
sheet: 'Adults',
sheet: "Adults",
columns: [
{ label: 'User', value: 'user' }, // Top level data
{ label: 'Age', value: row => (row.age + ' years') }, // Run functions
{ label: 'Phone', value: row => (row.more ? row.more.phone || '' : '') }, // Deep props
{ label: "User", value: "user" }, // Top level data
{ label: "Age", value: (row) => row.age + " years" }, // Custom format
{ label: "Phone", value: (row) => (row.more ? row.more.phone || "" : "") }, // Run functions
],
content: [
{ user: 'Andrea', age: 20, more: { phone: '11111111' } },
{ user: 'Luis', age: 21, more: { phone: '12345678' } }
]
}, {
sheet: 'Children',
{ user: "Andrea", age: 20, more: { phone: "11111111" } },
{ user: "Luis", age: 21, more: { phone: "12345678" } },
],
},
{
sheet: "Children",
columns: [
{ label: 'User', value: 'user' }, // Top level data
{ label: 'Age', value: row => (row.age + ' years') }, // Run functions
{ label: 'Phone', value: row => (row.more ? row.more.phone || '' : '') }, // Deep props
{ label: "User", value: "user" }, // Top level data
{ label: "Age", value: "age", format: '# "years"' }, // Column format
{ label: "Phone", value: "more.phone", format: "(###) ###-####" }, // Deep props and column format
],
content: [
{ user: 'Manuel', age: 16, more: { phone: '99999999' } },
{ user: 'Ana', age: 17, more: { phone: '87654321' } }
]
}
{ user: "Manuel", age: 16, more: { phone: 9999999900 } },
{ user: "Ana", age: 17, more: { phone: 8765432135 } },
],
},
]

let settings = {
fileName: 'MySpreadsheet', // Name of the spreadsheet
fileName: "MySpreadsheet", // Name of the resulting spreadsheet
extraLength: 3, // A bigger number means that columns will be wider
writeOptions: {} // Style options from https://github.com/SheetJS/sheetjs#writing-options
writeMode: "writeFile", // The available parameters are 'WriteFile' and 'write'. This setting is optional. Useful in such cases https://docs.sheetjs.com/docs/solutions/output#example-remote-file
writeOptions: {}, // Style options from https://docs.sheetjs.com/docs/api/write-options
RTL: true, // Display the columns from right-to-left (the default value is false)
}

xlsx(data, settings) // Will download the excel file
```

## Examples
If you want to trigger something after the file is downloaded, you can use the `callback` parameter:

```js
let callback = function (sheet) {
console.log("Download complete:", sheet)
}

xlsx(data, settings, callback) // Will download the excel file
```

### Column formatting

> **Note:** Cell formatting is type based, i.e. the format type and value type must match.
>
> If you want to use a Date format, the value must be of type Date; if you want a number format, the value must be a Number.
This are my files used for development, remember to change:
Column formatting can be provided in the column object, i.e.

```js
columns: [{ label: "Income", value: "income", format: "€#,##0.00" }]
```

- A list of SheetJS format examples can be found
here: [SSF library](https://github.com/SheetJS/sheetjs/blob/f443aa8475ebf051fc4e888cf0a6c3e5b751813c/bits/10_ssf.js#L42)
- ECMA-376 number formatting
specification: [Number formats](https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_numFmts_topic_ID0E6KK6.html)

Examples

```js
// Number formats
"$0.00" // Basic
"#,##0.00" // Pound
"0%" // Percentage
'#.# "ft"' // Number and text

// Date formats
"d-mmm-yy" // 12-Mar-22
"ddd" // (eg. Sat)
"dddd" // (eg. Saturday)
"h:mm AM/PM" // 1:10 PM
```

## Examples

`require('./index.js')` and `require('../index.js')` to `require('json-as-xlsx')`
This are files used for development, please change imports from `../../src/index` to `json-as-xlsx`

* Frontend with [Vue here](https://github.com/LuisEnMarroquin/json-as-xlsx/blob/main/src/App.vue)
* Backend with [Express here](https://github.com/LuisEnMarroquin/json-as-xlsx/blob/main/server.js)
- [Express with TypeScript](https://github.com/LuisEnMarroquin/json-as-xlsx/blob/main/packages/demo-express)
- [ReactJS with TypeScript](https://github.com/LuisEnMarroquin/json-as-xlsx/blob/main/packages/demo-reactjs)
Loading