Friday, 15 March 2013

model view controller - Export to .csv from html -



model view controller - Export to .csv from html -

i want export table in html page .csv file. can utilize like:

private void generateexcelfileontype(string filepath1, ref datatable dt) { if (dt != null) { string line = string.empty; if (dt.rows.count > 0) { string str = dt.tocsv(); using (streamwriter sw = new streamwriter(filepath1)) { sw.write(str); } } dt.clear(); dt = null; } }

but there way can straight export html page, print (windows.print)

as far i'm aware there's no reliable way of initiating downloadable file straight web page, other sending http request , responding downloadable mime-type.

i can't see great need 1 either. long can send request various info needed, server can respond appropriately.

update

it seems, comments, aren't looking write csv file locally. if want display csv text within browser, of course possible, simple iteration:

function csv(id){ var output = ''; $('table#' + id + ' tr').each(function(i){ if(i) output += '</br>'; var children = $(this).find('td, th'); children.each(function(j){ output += '\"' + $(this).html() + '\"'; if(j < children.length - 1) output += ', '; }); }); homecoming output; }

here's fiddle...

html model-view-controller

No comments:

Post a Comment