Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: util/table2CSV.js

Issue 4123001: Modified chrome pageload extension (Closed) Base URL: http://src.chromium.org/svn/trunk/src/chrome/common/extensions/docs/examples/extensions/benchmark/
Patch Set: '' Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « util/sorttable.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 This is a small JQuery utility to export HTML table as CSV file.
3
4 The author is Kunal Babre and the original script can be found in
5 http://www.kunalbabre.com/projects/table2CSV.php. Permissions are
6 granted by the author to make changes and redistribute.
7
8 Changes made by jning: To avoid exporting the textbox, radio buttons and etc.
9 in the table, the parameters rowNum and index in $().find().each() or
10 $().filter().find.each() help to ignore non-data cells.
11 */
12
13 jQuery.fn.table2CSV = function(rowNum, options) {
14 var options = jQuery.extend({
15 separator: ',',
16 header: [],
17 delivery: 'popup' // popup, value
18 },
19 options);
20
21 var csvData = [];
22 var headerArr = [];
23 var el = this;
24
25 //header
26 var numCols = options.header.length;
27 var tmpRow = []; // construct header avalible array
28
29 if (numCols > 0) {
30 for (var i = 0; i < numCols; i++) {
31 tmpRow[tmpRow.length] = formatData(options.header[i]);
32 }
33 } else {
34 $(el).filter(':visible').find('th').each(function(index) {
35 if (index > 0 && $(this).css('display') != 'none')
36 tmpRow[tmpRow.length] = formatData($(this).html());
37 });
38 }
39
40 row2CSV(tmpRow);
41
42 // actual data
43 $(el).find('tr').each(function(index) {
44 if (index < rowNum + 1) {
45 var tmpRow = [];
46 $(this).filter(':visible').find('td').each(function(index) {
47 if (index > 0 && $(this).css('display') != 'none')
48 tmpRow[tmpRow.length] = formatData($(this).html());
49 });
50 row2CSV(tmpRow);
51 }
52 });
53 if (options.delivery == 'popup') {
54 var mydata = csvData.join('\n');
55 return popup(mydata);
56 } else {
57 var mydata = csvData.join('\n');
58 return mydata;
59 }
60
61 function row2CSV(tmpRow) {
62 var tmp = tmpRow.join('') // to remove any blank rows
63 // alert(tmp);
64 if (tmpRow.length > 0 && tmp != '') {
65 var mystr = tmpRow.join(options.separator);
66 csvData[csvData.length] = mystr;
67 }
68 }
69 function formatData(input) {
70 // replace " with “
71 var regexp = new RegExp(/["]/g);
72 var output = input.replace(regexp, "“");
73 //HTML
74 var regexp = new RegExp(/\<[^\<]+\>/g);
75 var output = output.replace(regexp, "");
76 if (output == "") return '';
77 return '"' + output + '"';
78 }
79 function popup(data) {
80 var generator = window.open('', 'csv', 'height=400,width=600');
81 generator.document.write('<html><head><title>CSV</title>');
82 generator.document.write('</head><body >');
83 generator.document.write('<textArea cols=70 rows=15 wrap="off" >');
84 generator.document.write(data);
85 generator.document.write('</textArea>');
86 generator.document.write('</body></html>');
87 generator.document.close();
88 return true;
89 }
90 };
OLDNEW
« no previous file with comments | « util/sorttable.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698