-
-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #331 from jmaister/fix-data
Add fix data functions
- Loading branch information
Showing
4 changed files
with
157 additions
and
4 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,63 @@ | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Export to excel test</title> | ||
<script src="dist/excellentexport.js"></script> | ||
<style> | ||
table, tr, td { | ||
border: 1px black solid; | ||
} | ||
</style> | ||
<script> | ||
function newApi(format) { | ||
return ExcellentExport.convert({ | ||
anchor: 'anchorNewApi-' + format, | ||
filename: 'data_123.' + format, | ||
format: format | ||
}, [{ | ||
name: 'Sheet Name Here 1', | ||
from: { | ||
table: 'datatable' | ||
}, | ||
fixValue: (value, row, col) => { | ||
let v = value.replace(/<br>/gi, "\n"); | ||
let strippedString = v.replace(/(<([^>]+)>)/gi, ""); | ||
return strippedString; | ||
} | ||
}]); | ||
} | ||
</script> | ||
</head> | ||
<body> | ||
<h1>ExcellentExport.js</h1> | ||
|
||
Check on <a href="http://jordiburgos.com">jordiburgos.com</a> and <a href="https://github.com/jmaister/excellentexport">GitHub</a>. | ||
|
||
<h3>Test page</h3> | ||
|
||
Test table: | ||
<table id="datatable"> | ||
<tr> | ||
<th>Column 1</th> | ||
<th>Column 2</th> | ||
<th>Column 3</th> | ||
<th>Column 4</th> | ||
</tr> | ||
<tr> | ||
<td>hello<br>world</td> | ||
<td><span>text in span</span></td> | ||
<td>abc</td> | ||
<td>def</td> | ||
</tr> | ||
</table> | ||
|
||
<br/> | ||
|
||
<a href="#" id="anchorNewApi-xlsx" onclick="return newApi('xlsx');">Export to XLSX from array</a> | ||
<br> | ||
<a href="#" id="anchorNewApi-xls" onclick="return newApi('xls');">Export to XLS from array</a> | ||
<br> | ||
<a href="#" id="anchorNewApi-csv" onclick="return newApi('csv');">Export to CSV from array</a> | ||
|
||
</body> | ||
</html> |
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,72 @@ | ||
const assert = require('assert'); | ||
|
||
import ExcellentExport from '../excellentexport'; | ||
|
||
|
||
describe('Fix data', function() { | ||
beforeEach(() => { | ||
document.body.innerHTML = ''; | ||
const element = document.createElement("div"); | ||
element.innerHTML = '<a id="anchor">Link</a>'; | ||
|
||
document.body.appendChild(element); | ||
}); | ||
|
||
it('should fix values', function() { | ||
const options = { | ||
anchor: 'anchor', | ||
filename: 'data_from_array', | ||
format: 'xlsx' | ||
}; | ||
|
||
const sheets = [ | ||
{ | ||
name: 'Sheet Name Here 1', | ||
from: { | ||
array: [ | ||
['hello', '<td>hello</td>', 'bye'], | ||
] | ||
}, | ||
fixValue: (value, row, col) => { | ||
let v = value.replace(/<br>/gi, "\n"); | ||
let strippedString = v.replace(/(<([^>]+)>)/gi, ""); | ||
return strippedString; | ||
} | ||
} | ||
]; | ||
|
||
const workbook = ExcellentExport.convert(options, sheets); | ||
assert.ok(workbook, 'Result must not be null'); | ||
}); | ||
|
||
it('should process the whole array', function() { | ||
const options = { | ||
anchor: 'anchor', | ||
filename: 'data_from_array', | ||
format: 'xlsx' | ||
}; | ||
|
||
const sheets = [ | ||
{ | ||
name: 'Sheet Name Here 1', | ||
from: { | ||
array: [ | ||
['hello', '<td>hello</td>', 'bye'], | ||
] | ||
}, | ||
fixData: (array) => { | ||
return array.map(r => { | ||
return r.map(v => { | ||
return "fixed-" + v; | ||
}) | ||
}); | ||
} | ||
} | ||
]; | ||
|
||
const workbook = ExcellentExport.convert(options, sheets); | ||
assert.ok(workbook, 'Result must not be null'); | ||
}); | ||
|
||
}); | ||
|