nicolaskruchten / pivottable

Open-source Javascript Pivot Table (aka Pivot Grid, Pivot Chart, Cross-Tab) implementation with drag'n'drop.
https://pivottable.js.org/
MIT License
4.36k stars 1.08k forks source link

how to remove total and freeze and then export to excel #749

Open adityos2003 opened 7 years ago

adityos2003 commented 7 years ago

Hello mr nicholas , before thanks for opensource this source, because i can pivot in localhost so and then help me to remove total and freeze and button export to excel, thanks remove total

SAMJN commented 7 years ago

You can give those particular cells ID or class and can give CSS to change these.

nicolaskruchten commented 7 years ago
  1. Removing totals can be done using CSS: https://github.com/nicolaskruchten/pivottable/wiki/Frequently-Asked-Questions#totals
  2. Freezing is not a supported feature unfortunately.
  3. Neither is exporting other than with the export renderer: https://github.com/nicolaskruchten/pivottable/wiki/Frequently-Asked-Questions#exporting-renderer-output-to-excel-or-images
adityos2003 commented 7 years ago
  1. Neither is exporting other than with the export renderer: https://github.com/nicolaskruchten/pivottable/wiki/Frequently-Asked-Questions#exporting-renderer-output-to-excel-or-images

thanks before solution its, and then asking about export, if it can without copy image and than paste image in the excel ?. i mean have button and then click export to .xlsx (excel) or csv (save), like format pivot table and graph report in excel.

nicolaskruchten commented 7 years ago

Like I said, there is no built-in way to export to Excel or CSV, sorry :)

adityos2003 commented 7 years ago

oh ok nic, thanks, i'm fun learn nic, all code in web so may you help me, about above

  1. Tips and Tricks save config to cookie and restore config from cookie ? when i can make that, may that's code save cookie used write excel
  2. about var callWithJQuery where is call file/link ?
nicolaskruchten commented 7 years ago
  1. See here: https://pivottable.js.org/examples/save_restore.html
  2. I don't understand what you're asking.
adityos2003 commented 7 years ago

thanks nic, sory about question me, because i'm excited learn code this. about last question cookie, first i think the pivot js can print/export excel then i need view pivot and then can to print/save/export in excel, the big deals i have idea to view in html pivot from render js and then -> it has button click to excel, so do you help me ? step and example return with picture, thanks nic

nicolaskruchten commented 7 years ago

I'm sorry but I cannot understand what you're asking for :(

adityos2003 commented 7 years ago

its ok, i mean like this in new box bold pop up

I'm sorry but I cannot understand what you're asking for :(

nicolaskruchten commented 7 years ago

OK, but as I told you above:

  1. Freezing columns and rows is not a feature of this library.
  2. Exporting to Excel is not a feature of this library.

If you need to accomplish the goals above, you will have to write your own code for this, and I suggest you seek help on StackOverflow.

adityos2003 commented 7 years ago

thanks nic, i will try code

adityos2003 commented 7 years ago

hi nic i will try this code like this :

« back to PivotTable.js examples

view export

the question

  1. how i can export/download/save to excel in bold box from button Export to TAB (Excel) ? with sample source.

  2. i'm compare the question like https://github.com/nicolaskruchten/pivottable/issues/639 , what is similiar? .

Thanks nic

Bill-VA commented 6 years ago

You can use the css above to hide the total column and row, or you can add a bit of extra code to actually remove them. Using the onRefresh callback, just add an ID attribute to the pivot table (used for this purpose and later for export), and then remove the offending column and row.

$("#output").pivotUI(
      $.pivotUtilities.myData, {
        rows: ["row1", "row2", "row3", "row4",],
        cols: ["col1", "col2"],
        vals: ["values"],
        aggregatorName: "List Unique Values",
        rendererName: "Table",
        onRefresh: function() {     
            $('table .pvtTable').attr('id', 'mytable'); 
            $('#mytable thead tr:first').find('th:last').remove();
            $('#mytable tr').find('td:last').remove();
            $('#mytable').find('tr:last').remove();             
           }  
});  

To export to Excel, I experimented with several options and none seemed to work in all browsers or were able to handle the thousands of lines in my pivot tables. I finally found one a couple days ago called SheetJS. It even maintains most of the table formatting (colspans, etc.). After including the necessary js files:

<!-- SheetJS js-xlsx library -->
<script type="text/javascript" src="//unpkg.com/xlsx/dist/xlsx.full.min.js"></script>
<!-- FileSaver.js is the library of choice for Chrome -->
<script type="text/javascript" src="//rawgit.com/eligrey/Blob.js/master/Blob.js"></script>
<script type="text/javascript" src="//rawgit.com/eligrey/FileSaver.js/master/FileSaver.js"></script>

Then a bit of code:

function exportData(fn) { 
    return export_table_to_excel('mytable', 'xlsx', fn); 
}   

function s2ab(s) {
    if(typeof ArrayBuffer !== 'undefined') {
        var buf = new ArrayBuffer(s.length);
        var view = new Uint8Array(buf);
        for (var i=0; i!=s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
        return buf;
    } else {
        var buf = new Array(s.length);
        for (var i=0; i!=s.length; ++i) buf[i] = s.charCodeAt(i) & 0xFF;
        return buf;
    }
}

function export_table_to_excel(id, type, fn) {
var wb = XLSX.utils.table_to_book(document.getElementById(id), {sheet:"Sheet JS"});
var wbout = XLSX.write(wb, {bookType:type, bookSST:true, type: 'binary'});
var fname = fn || 'myFileName.' + type;
try {
    saveAs(new Blob([s2ab(wbout)],{type:"application/octet-stream"}), fname);
} catch(e) { if(typeof console != 'undefined') console.log(e, wbout); }
return wbout;
}

Then just trigger it with a exportData(); function call.

adityos2003 commented 6 years ago

could you help me, complete code and then ready to run

fbeqirllari commented 6 years ago

there is no need for other JavaScript libraries

export: function () { var uri = 'data:application/vnd.ms-excel;base64,', template = '\ <!--[if gte mso 9]>\

{worksheet}\ {table}
', base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) }, format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) } table = tableDom if (table === undefined) return; var ctx = { worksheet: 'Worksheet', table: table.innerHTML } if (navigator.msSaveOrOpenBlob) { var blob = new Blob([format(template, ctx)], { type: 'data:application/vnd.ms-excel;base64' }); navigator.msSaveOrOpenBlob(blob, "data.xls"); } else { downloadLink = document.createElement("a"); document.body.appendChild(downloadLink); downloadLink.href = uri + base64(format(template, ctx)); downloadLink.download = "data.xls"; return downloadLink.click(); } } the complete function attached [export.zip](https://github.com/nicolaskruchten/pivottable/files/2335453/export.zip)