├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── dist
├── index.html
├── index.js
├── index.js.map
├── index.map
├── tableToExcel.517b1af9.js
├── tableToExcel.517b1af9.js.map
├── tableToExcel.517b1af9.map
├── tableToExcel.js
├── tableToExcel.js.map
└── tableToExcel.map
├── package-lock.json
├── package.json
├── sample
└── index.html
├── src
├── parser.js
└── tableToExcel.js
└── test
├── parser.test.js
├── samples
├── colAndRowSpan.html
├── colSpan.html
├── multipleMerges.html
├── simpleTable.html
└── styles.html
└── utils
└── utils.js
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Runtime data
9 | pids
10 | *.pid
11 | *.seed
12 | *.pid.lock
13 |
14 | # Directory for instrumented libs generated by jscoverage/JSCover
15 | lib-cov
16 |
17 | # Coverage directory used by tools like istanbul
18 | coverage
19 |
20 | # nyc test coverage
21 | .nyc_output
22 |
23 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
24 | .grunt
25 |
26 | # Bower dependency directory (https://bower.io/)
27 | bower_components
28 |
29 | # node-waf configuration
30 | .lock-wscript
31 |
32 | # Compiled binary addons (https://nodejs.org/api/addons.html)
33 | build/Release
34 |
35 | # Dependency directories
36 | node_modules/
37 | jspm_packages/
38 |
39 | # TypeScript v1 declaration files
40 | typings/
41 |
42 | # Optional npm cache directory
43 | .npm
44 |
45 | # Optional eslint cache
46 | .eslintcache
47 |
48 | # Optional REPL history
49 | .node_repl_history
50 |
51 | # Output of 'npm pack'
52 | *.tgz
53 |
54 | # Yarn Integrity file
55 | .yarn-integrity
56 |
57 | # dotenv environment variables file
58 | .env
59 |
60 | # parcel-bundler cache (https://parceljs.org/)
61 | .cache
62 |
63 | # next.js build output
64 | .next
65 |
66 | # nuxt.js build output
67 | .nuxt
68 |
69 | # vuepress build output
70 | .vuepress/dist
71 |
72 | # Serverless directories
73 | .serverless/
74 |
75 | # FuseBox cache
76 | .fusebox/
77 |
78 | #DynamoDB Local files
79 | .dynamodb/
80 | .vscode/
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "8"
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Linways Technologies Pvt. Ltd.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Table to Excel 2
2 |
3 | [](https://travis-ci.org/linways/table-to-excel)
4 |
5 | Export HTML table to valid excel file effortlessly.
6 | This library uses [exceljs/exceljs](https://github.com/exceljs/exceljs) under the hood to create the excel.
7 | (Initial version of this library was using [protobi/js-xlsx](https://github.com/linways/table-to-excel/tree/V0.2.1), it can be found [here](https://github.com/linways/table-to-excel/tree/V0.2.1))
8 |
9 | # Installation
10 |
11 | ## Browser
12 |
13 | Just add a script tag:
14 |
15 | ```html
16 |
17 | ```
18 |
19 | ## Node
20 |
21 | ```bash
22 | npm install @linways/table-to-excel --save
23 | ```
24 |
25 | ```javascript
26 | import TableToExcel from "@linways/table-to-excel";
27 | ```
28 |
29 | # Usage
30 |
31 | Create your HTML table as normal.
32 | To export content of table `#table1` run:
33 |
34 | ```javascript
35 | TableToExcel.convert(document.getElementById("table1"));
36 | ```
37 |
38 | or
39 |
40 | ```javascript
41 | TableToExcel.convert(document.getElementById("table1"), {
42 | name: "table1.xlsx",
43 | sheet: {
44 | name: "Sheet 1"
45 | }
46 | });
47 | ```
48 | Check [this pen](https://codepen.io/rohithb/pen/YdjVbb) for working example.
49 |
50 |
51 |
52 |
53 | # Cell Types
54 |
55 | Cell types can be set using the following data attributes:
56 |
57 | | Attribute | Description | Possible Values |
58 | | ---------------- | ---------------------------------- | -------------------------------------------------------------------------- |
59 | | `data-t` | To specify the data type of a cell | `s` : String (Default) `n` : Number `b` : Boolean `d` : Date |
60 | | `data-hyperlink` | To add hyper link to cell | External URL or hyperlink to another sheet |
61 | | `data-error` | To add value of a cell as error | |
62 |
63 | Example:
64 |
65 | ```html
66 |
67 |
2500
68 |
69 |
05-23-2018
70 |
71 |
true
72 |
73 |
0
74 |
75 |
Google
76 | ```
77 |
78 | # Cell Styling
79 |
80 | All styles are set using `data` attributes on `td` tags.
81 | There are 5 types of attributes: `data-f-*`, `data-a-*`, `data-b-*`, `data-fill-*` and `data-num-fmt` which corresponds to five top-level attributes `font`, `alignment`, `border`, `fill` and `numFmt`.
82 |
83 | | Category | Attribute | Description | Values |
84 | | --------- | ---------------------- | ----------------------------- | ------------------------------------------------------------------------------------------- |
85 | | font | `data-f-name` | Font name | "Calibri" ,"Arial" etc. |
86 | | | `data-f-sz` | Font size | "11" // font size in points |
87 | | | `data-f-color` | Font color | A hex ARGB value. Eg: FFFFOOOO for opaque red. |
88 | | | `data-f-bold` | Bold | `true` or `false` |
89 | | | `data-f-italic` | Italic | `true` or `false` |
90 | | | `data-underline` | Underline | `true` or `false` |
91 | | | `data-f-strike` | Strike | `true` or `false` |
92 | | Alignment | `data-a-h` | Horizontal alignment | `left`, `center`, `right`, `fill`, `justify`, `centerContinuous`, `distributed` |
93 | | | `data-a-v` | Vertical alignment | `bottom`, `middle`, `top`, `distributed`, `justify` |
94 | | | `data-a-wrap` | Wrap text | `true` or `false` |
95 | | | `data-a-indent` | Indent | Integer |
96 | | | `data-a-rtl` | Text direction: Right to Left | `true` or `false` |
97 | | | `data-a-text-rotation` | Text rotation | 0 to 90 |
98 | | | | | -1 to -90 |
99 | | | | | vertical |
100 | | Border | `data-b-a-s` | Border style (all borders) | Refer `BORDER_STYLES` |
101 | | | `data-b-t-s` | Border top style | Refer `BORDER_STYLES` |
102 | | | `data-b-b-s` | Border bottom style | Refer `BORDER_STYLES` |
103 | | | `data-b-l-s` | Border left style | Refer `BORDER_STYLES` |
104 | | | `data-b-r-s` | Border right style | Refer `BORDER_STYLES` |
105 | | | `data-b-a-c` | Border color (all borders) | A hex ARGB value. Eg: FFFFOOOO for opaque red. |
106 | | | `data-b-t-c` | Border top color | A hex ARGB value. |
107 | | | `data-b-b-c` | Border bottom color | A hex ARGB value. |
108 | | | `data-b-l-c` | Border left color | A hex ARGB value. |
109 | | | `data-b-r-c` | Border right color | A hex ARGB value. |
110 | | Fill | `data-fill-color` | Cell background color | A hex ARGB value. |
111 | | numFmt | `data-num-fmt` | Number Format | "0" |
112 | | | | | "0.00%" |
113 | | | | | "0.0%" // string specifying a custom format |
114 | | | | | "0.00%;\\(0.00%\\);\\-;@" // string specifying a custom format, escaping special characters |
115 |
116 | **`BORDER_STYLES:`** `thin`, `dotted`, `dashDot`, `hair`, `dashDotDot`, `slantDashDot`, `mediumDashed`, `mediumDashDotDot`, `mediumDashDot`, `medium`, `double`, `thick`
117 |
118 | # Exclude Cells and rows
119 |
120 | To exclude a cell or a row from the exported excel add `data-exclude="true"` to the corresponding `td` or `tr`.
121 | Example:
122 |
123 | ```html
124 |
125 |
126 |
Excluded row
127 |
Something
128 |
129 |
130 |
131 |
132 |
Included Cell
133 |
Excluded Cell
134 |
Included Cell
135 |
136 | ```
137 |
138 | # Column Width
139 |
140 | Column width's can be set by specifying `data-cols-width` in the `
` tag.
141 | `data-cols-width` accepts comma separated column widths specified in character count .
142 | `data-cols-width="10,20"` will set width of first coulmn as width of 10 charaters and second column as 20 characters wide.
143 | Example:
144 |
145 | ```html
146 |
147 | ...
148 |
149 | ```
150 |
151 | # Row Height
152 |
153 | Row Height can be set by specifying `data-height` in the `
` tag.
154 | Example:
155 |
156 | ```html
157 |
158 |
Cell 1
159 |
Cell 2
160 |
161 | ```
162 |
163 | # Release Changelog
164 |
165 | ## 1.0.0
166 |
167 | [Migration Guide](https://github.com/linways/table-to-excel/wiki/Migration-guide-for-V0.2.1-to-V1.0.0) for migrating from V0.2.1 to V1.0.0
168 |
169 | - Changed the backend to Exce[exceljs/exceljs](https://github.com/exceljs/exceljs)lJS
170 | - Added border color
171 | - Option to set style and color for all borders
172 | - Exclude row
173 | - Added text underline
174 | - Added support for hyperlinks
175 | - Text intent
176 | - RTL support
177 | - Extra alignment options
178 | - String "true/false" will be accepted as Boolean
179 | - Changed border style values
180 | - Text rotation values changed
181 |
182 | ## 1.0.2
183 |
184 | - Fixed bug in handling multiple columns merges in a sheet
185 |
186 | ## 1.0.3
187 |
188 | - Option to specify row height
189 |
--------------------------------------------------------------------------------
/dist/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
11 |