Copy portion of the page in angular 4 -
i have web application generates nicely formatted table (bootstrap type). have button when clicked copies table in clipboard user can paste in word/excel.
i have tried several libraries like: ng2-clipboard, angx-clipboard allow copies values input fields , not portion of page. tried create table's html dinamically in service doesn't keep styling , in word ends pasting html piece of code.
i have snippet used work on old version of application, think selects table , calls copy command:
this.selectelementcontents = function (el) { el = document.getelementbyid('filtered-table'); var body = document.body, range, sel; if (document.createrange && window.getselection) { range = document.createrange(); sel = window.getselection(); sel.removeallranges(); try { range.selectnodecontents(el); sel.addrange(range); } catch (e) { range.selectnode(el); sel.addrange(range); } } else if (body.createtextrange) { range = body.createtextrange(); range.movetoelementtext(el); range.select(); } document.execcommand('copy'); }
this not seem correct "angular" way things, how should proceed?
Comments
Post a Comment