Skip to content

Commit 01f1ab4

Browse files
committed
Initial commit
Signed-off-by: Michael-Rainabba Richardson <[email protected]>
0 parents  commit 01f1ab4

15 files changed

+439
-0
lines changed

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This file is for unifying the coding style for different editors and IDEs
2+
# editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
indent_style = tab
8+
end_of_line = lf
9+
charset = utf-8
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
node_modules

.jshintrc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"boss": true,
3+
"curly": true,
4+
"eqeqeq": true,
5+
"eqnull": true,
6+
"expr": true,
7+
"immed": true,
8+
"noarg": true,
9+
"onevar": true,
10+
"quotmark": "double",
11+
"smarttabs": true,
12+
"trailing": true,
13+
"unused": true,
14+
"node": true
15+
}

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
language: node_js
2+
node_js:
3+
- 0.8

CONTRIBUTING.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Contributing
2+
3+
Before sending a pull request remember to follow [jQuery Core Style Guide](http://contribute.jquery.org/style-guide/js/).
4+
5+
1. Fork it!
6+
2. Create your feature branch: `git checkout -b my-new-feature`
7+
3. Make your changes on the `src` folder, never on the `dist` folder.
8+
4. Commit your changes: `git commit -m 'Add some feature'`
9+
5. Push to the branch: `git push origin my-new-feature`
10+
6. Submit a pull request :D

Gruntfile.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
module.exports = function(grunt) {
2+
3+
grunt.initConfig({
4+
5+
// Import package manifest
6+
pkg: grunt.file.readJSON("table2excel.jquery.json"),
7+
8+
// Banner definitions
9+
meta: {
10+
banner: "/*\n" +
11+
" * <%= pkg.title || pkg.name %> - v<%= pkg.version %>\n" +
12+
" * <%= pkg.description %>\n" +
13+
" * <%= pkg.homepage %>\n" +
14+
" *\n" +
15+
" * Made by <%= pkg.author.name %>\n" +
16+
" * Under <%= pkg.licenses[0].type %> License\n" +
17+
" */\n"
18+
},
19+
20+
// Concat definitions
21+
concat: {
22+
dist: {
23+
src: ["src/jquery.table2excel.js"],
24+
dest: "dist/jquery.table2excel.js"
25+
},
26+
options: {
27+
banner: "<%= meta.banner %>"
28+
}
29+
},
30+
31+
// Lint definitions
32+
jshint: {
33+
files: ["src/jquery.table2excel.js"],
34+
options: {
35+
jshintrc: ".jshintrc"
36+
}
37+
},
38+
39+
// Minify definitions
40+
uglify: {
41+
my_target: {
42+
src: ["dist/jquery.table2excel.js"],
43+
dest: "dist/jquery.table2excel.min.js"
44+
},
45+
options: {
46+
banner: "<%= meta.banner %>"
47+
}
48+
},
49+
50+
});
51+
52+
grunt.loadNpmTasks("grunt-contrib-concat");
53+
grunt.loadNpmTasks("grunt-contrib-jshint");
54+
grunt.loadNpmTasks("grunt-contrib-uglify");
55+
56+
grunt.registerTask("default", ["jshint", "concat", "uglify"]);
57+
grunt.registerTask("travis", ["jshint"]);
58+
59+
};

README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# jQuery table2excel Plugin by Rainabba (https://github.com/rainabba/jquery-table2excel/jquery-table2excel)
2+
3+
#Credit for the core table export code concept goes to insin (met on Freenode in #javascript) and core code inspired from https://gist.github.com/insin/1031969
4+
5+
6+
## Usage
7+
8+
1. Include jQuery:
9+
10+
```html
11+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
12+
```
13+
14+
2. Include table2excel plugin's code:
15+
16+
```html
17+
<script src="dist/jquery.table2excel.min.js"></script>
18+
```
19+
20+
3. Call the plugin:
21+
22+
```javascript
23+
$("table#table2excel").table2excel({
24+
exclude: ".excludeThisClass",
25+
name: "Excel Document Name"
26+
});
27+
```
28+
29+
#### [demo/](https://github.com/rainabba/jquery-table2excel/tree/master/demo)
30+
31+
Contains a simple HTML file to demonstrate your plugin.
32+
33+
#### [dist/](https://github.com/rainabba/jquery-table2excel/tree/master/dist)
34+
35+
This is where the generated files are stored once Grunt runs.
36+
37+
#### [.editorconfig](https://github.com/rainabba/jquery-table2excel/tree/master/.editorconfig)
38+
39+
This file is for unifying the coding style for different editors and IDEs.
40+
41+
> Check [editorconfig.org](http://editorconfig.org) if you haven't heard about this project yet.
42+
43+
#### [.jshintrc](https://github.com/rainabba/jquery-table2excel/tree/master/.jshintrc)
44+
45+
List of rules used by JSHint to detect errors and potential problems in JavaScript.
46+
47+
> Check [jshint.com](http://jshint.com/about/) if you haven't heard about this project yet.
48+
49+
#### [.travis.yml](https://github.com/rainabba/jquery-table2excel/tree/master/.travis.yml)
50+
51+
Definitions for continous integration using Travis.
52+
53+
> Check [travis-ci.org](http://about.travis-ci.org/) if you haven't heard about this project yet.
54+
55+
#### [table2excel.jquery.json](https://github.com/rainabba/jquery-table2excel/tree/master/table2excel.jquery.json)
56+
57+
Package manifest file used to publish plugins in jQuery Plugin Registry.
58+
59+
> Check this [Package Manifest Guide](http://plugins.jquery.com/docs/package-manifest/) for more details.
60+
61+
#### [Gruntfile.js](https://github.com/rainabba/jquery-table2excel/tree/master/Gruntfile.js)
62+
63+
Contains all automated tasks using Grunt.
64+
65+
> Check [gruntjs.com](http://gruntjs.com) if you haven't heard about this project yet.
66+
67+
#### [package.json](https://github.com/rainabba/jquery-table2excel/tree/master/package.json)
68+
69+
Specify all dependencies loaded via Node.JS.
70+
71+
> Check [NPM](https://npmjs.org/doc/json.html) for more details.
72+
73+
## Contributing
74+
75+
Check [CONTRIBUTING.md](https://github.com/rainabba/jquery-table2excel/blob/master/CONTRIBUTING.md)
76+
77+
## History
78+
79+
Check [Release](https://github.com/rainabba/jquery-table2excel/releases) list.
80+
81+
## License
82+
83+
[MIT License](http://zenorocha.mit-license.org/)

bower.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "jquery-table2excel",
3+
"version": "1.0.0",
4+
"homepage": "https://github.com/jquery-table2excel/",
5+
"authors": [
6+
"rainabba <[email protected]>"
7+
],
8+
"description": "jQuery plugin to export an .xls file in browser from an HTML table.",
9+
"main": "src/jquery.table2excel.js",
10+
"keywords": [
11+
"jquery",
12+
"plugin",
13+
"table2excel",
14+
"jquery-plugin",
15+
"jquery-table2excel"
16+
],
17+
"license": "MIT"
18+
}

demo/download.xls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>Excel Document Name</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table><tr><td>This Should get exported as a header</td><td>This should too</td></tr><tr><td>data1a</td><td>data1b</td></tr><tr><td>data2a</td><td>data2b</td></tr><tr><td colspan="2">This footer spans 2 cells</td></tr></table></body></html>

demo/index.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>jQuery Boilerplate</title>
5+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
6+
<script src="../src/jquery.table2excel.js"></script>
7+
</head>
8+
<body>
9+
<table id="table2excel">
10+
<thead>
11+
<tr class="noExl"><td>This shouldn't get exported</td><td>This shouldn't get exported either</td></tr>
12+
<tr><td>This Should get exported as a header</td><td>This should too</td></tr>
13+
</thead>
14+
<tbody>
15+
<tr><td>data1a</td><td>data1b</td></tr>
16+
<tr><td>data2a</td><td>data2b</td></tr>
17+
</tbody>
18+
<tfoot>
19+
<tr><td colspan="2">This footer spans 2 cells</td></tr>
20+
</tfoot>
21+
</table>
22+
<script>
23+
$(function() {
24+
$("#table2excel").table2excel({
25+
exclude: ".noExl",
26+
name: "Excel Document Name"
27+
});
28+
});
29+
</script>
30+
</body>
31+
</html>

dist/jquery.table2excel.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* jQuery table2excel - v1.0.0
3+
* jQuery plugin to export an .xls file in browser from an HTML table
4+
* https://github.com/rainabba/jquery-table2excel
5+
*
6+
* Made by rainabba
7+
* Under MIT License
8+
*/
9+
//table2excel.js
10+
;(function ( $, window, document, undefined ) {
11+
var pluginName = "table2excel",
12+
defaults = {
13+
exclude: ".noExl",
14+
name: "Table2Excel"
15+
};
16+
17+
// The actual plugin constructor
18+
function Plugin ( element, options ) {
19+
this.element = element;
20+
// jQuery has an extend method which merges the contents of two or
21+
// more objects, storing the result in the first object. The first object
22+
// is generally empty as we don't want to alter the default options for
23+
// future instances of the plugin
24+
this.settings = $.extend( {}, defaults, options );
25+
this._defaults = defaults;
26+
this._name = pluginName;
27+
this.init();
28+
}
29+
30+
Plugin.prototype = {
31+
init: function () {
32+
this.template = "<html xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns=\"http://www.w3.org/TR/REC-html40\"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>";
33+
this.tableRows = "";
34+
35+
// get contents of table except for exclude
36+
$(this.element).find("tr").not(this.settings.exclude).each(function (i,o) {
37+
this.tableRows += "<tr>" + $(o).html() + "</tr>";
38+
});
39+
this.tableToExcel(this.tableRows, this.settings.name);
40+
},
41+
tableToExcel: function (table, name) {
42+
this.uri = "data:application/vnd.ms-excel;base64,";
43+
this.base64 = function (s) {
44+
return window.btoa(unescape(encodeURIComponent(s)));
45+
};
46+
this.format = function (s, c) {
47+
return s.replace(/{(\w+)}/g, function (m, p) {
48+
return c[p];
49+
});
50+
};
51+
this.ctx = {
52+
worksheet: name || "Worksheet",
53+
table: table
54+
};
55+
window.location.href = this.uri + this.base64(this.format(this.template, this.ctx));
56+
}
57+
};
58+
59+
$.fn[ pluginName ] = function ( options ) {
60+
this.each(function() {
61+
if ( !$.data( this, "plugin_" + pluginName ) ) {
62+
$.data( this, "plugin_" + pluginName, new Plugin( this, options ) );
63+
}
64+
});
65+
66+
// chain jQuery functions
67+
return this;
68+
};
69+
70+
})( jQuery, window, document );

dist/jquery.table2excel.min.js

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "jquery-table2excel",
3+
"title": "jQuery table2excel",
4+
"description": "jQuery plugin to export an .xls file in browser from an HTML table",
5+
"author": "rainabba",
6+
"repository": {
7+
"type": "git",
8+
"url": "http://github.com/rainabba/jquery-table2excel.git"
9+
},
10+
"homepage": "https://github.com/rainabba/jquery-table2excel/",
11+
"version": "1.0.0",
12+
"devDependencies": {
13+
"grunt": "~0.4.1",
14+
"grunt-cli": "~0.1.13",
15+
"grunt-contrib-jshint": "~0.8.0",
16+
"grunt-contrib-concat": "~0.3.0",
17+
"grunt-contrib-uglify": "~0.3.2"
18+
},
19+
"scripts": {
20+
"test": "grunt travis --verbose"
21+
}
22+
}

0 commit comments

Comments
 (0)