Skip to content
This repository has been archived by the owner on Apr 18, 2020. It is now read-only.

Commit

Permalink
Merge pull request #15 from linways/#11
Browse files Browse the repository at this point in the history
Added option to specify row height
  • Loading branch information
rohithb authored Apr 7, 2019
2 parents 8dbc2ae + af4a398 commit 6ce7615
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 11 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ Example:
</table>
```

# Row Height

Row Height can be set by specifying `data-height` in the `<tr>` tag.
Example:

```html
<tr data-height="42.5">
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
```

# Release Changelog

## 1.0.0
Expand All @@ -166,3 +178,11 @@ Example:
- String "true/false" will be accepted as Boolean
- Changed border style values
- Text rotation values changed

## 1.0.2

- Fixed bug in handling multiple columns merges in a sheet

## 1.0.3

- Option to specify row height
3 changes: 3 additions & 0 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@
<td data-exclude="true">Excluded Cell</td>
<td>Included Cell</td>
</tr>
<tr data-height="42">
<td>Row height 42</td>
</tr>
</tbody>
</table>

Expand Down
2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ var parent = module.bundle.parent;
if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
var hostname = "" || location.hostname;
var protocol = location.protocol === 'https:' ? 'wss' : 'ws';
var ws = new WebSocket(protocol + '://' + hostname + ':' + "52850" + '/');
var ws = new WebSocket(protocol + '://' + hostname + ':' + "49818" + '/');

ws.onmessage = function (event) {
var data = JSON.parse(event.data);
Expand Down
13 changes: 9 additions & 4 deletions dist/tableToExcel.517b1af9.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,22 @@ var TTEParser = function () {

for (_r = 0; _r < rows.length; ++_r) {
var row = rows[_r];
r = _r + 1; // Actual excel row number

c = 1; // Actual excel col number

if (row.getAttribute("data-exclude") === "true") {
rows.splice(_r, 1);
_r--;
continue;
}

var tds = _toConsumableArray(row.children);
if (row.getAttribute("data-height")) {
var exRow = ws.getRow(r);
exRow.height = parseFloat(row.getAttribute("data-height"));
}

r = _r + 1;
c = 1;
var tds = _toConsumableArray(row.children);

for (_c = 0; _c < tds.length; ++_c) {
var td = tds[_c];
Expand Down Expand Up @@ -44629,7 +44634,7 @@ var parent = module.bundle.parent;
if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
var hostname = "" || location.hostname;
var protocol = location.protocol === 'https:' ? 'wss' : 'ws';
var ws = new WebSocket(protocol + '://' + hostname + ':' + "52850" + '/');
var ws = new WebSocket(protocol + '://' + hostname + ':' + "49818" + '/');

ws.onmessage = function (event) {
var data = JSON.parse(event.data);
Expand Down
2 changes: 1 addition & 1 deletion dist/tableToExcel.517b1af9.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/tableToExcel.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/tableToExcel.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@linways/table-to-excel",
"version": "1.0.2",
"version": "1.0.3",
"description": "Javascript library to create 'valid' excel file from html table with styles",
"main": "./dist/tableToExcel.js",
"repository": {
Expand Down
3 changes: 3 additions & 0 deletions sample/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@
<td data-exclude="true">Excluded Cell</td>
<td>Included Cell</td>
</tr>
<tr data-height="42">
<td>Row height 42</td>
</tr>
</tbody>
</table>

Expand Down
9 changes: 7 additions & 2 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ const TTEParser = (function() {
let merges = [];
for (_r = 0; _r < rows.length; ++_r) {
let row = rows[_r];
r = _r + 1; // Actual excel row number
c = 1; // Actual excel col number
if (row.getAttribute("data-exclude") === "true") {
rows.splice(_r, 1);
_r--;
continue;
}
if (row.getAttribute("data-height")) {
let exRow = ws.getRow(r);
exRow.height = parseFloat(row.getAttribute("data-height"));
}

let tds = [...row.children];
r = _r + 1;
c = 1;
for (_c = 0; _c < tds.length; ++_c) {
let td = tds[_c];
if (td.getAttribute("data-exclude") === "true") {
Expand Down
9 changes: 9 additions & 0 deletions test/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ describe("Parser", function() {
});
});

describe("Row height", function() {
it("Should handle the row height", function() {
let table = getTable("styles");
let ws = getWorkSheet();
ws = Parser.parseDomToTable(ws, table, _opts);
expect(ws.getRow(13).height).to.equals(45);
});
});

describe("Multiple merges", function() {
var ws;
it("should handle multiple merges properly", function() {
Expand Down
3 changes: 3 additions & 0 deletions test/samples/styles.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,8 @@
<td data-exclude="true">Excluded Cell</td>
<td>Included Cell</td>
</tr>
<tr data-height="45">
<td>Row height 45</td>
</tr>
</tbody>
</table>

0 comments on commit 6ce7615

Please sign in to comment.