asp.net mvc 4 - Rendering partial view to string in MVC4 -
i need export partial view contents excel sheet. view contains decimal values, , after export decimal values rounded nearest values. how avoid rounding of decimal , export is?
below code have written render partial view string.
protected string renderpartialviewtostring(string viewname, object model) { if (string.isnullorempty(viewname)) viewname = controllercontext.routedata.getrequiredstring("action"); viewdata.model = model; using (stringwriter sw = new stringwriter()) { viewengineresult viewresult = viewengines.engines.findpartialview(controllercontext, viewname); viewcontext viewcontext = new viewcontext(controllercontext, viewresult.view, viewdata, tempdata, sw); viewresult.view.render(viewcontext, sw); return sw.getstringbuilder().tostring(); } } if view returned value, rounded.
and calling function
string str = renderpartialviewtostring("mypartialview", objmodel);
below piece of code call above said method
using (streamwriter outfile = new streamwriter(pathfile)) { outfile.write(str); } microsoft.office.interop.excel.application xlapp = new microsoft.office.interop.excel.application(); microsoft.office.interop.excel.workbook xlworkbook = xlapp.workbooks.open(pathfile, system.reflection.missing.value, system.reflection.missing.value, system.reflection.missing.value, system.reflection.missing.value, system.reflection.missing.value, system.reflection.missing.value, system.reflection.missing.value, system.reflection.missing.value, system.reflection.missing.value, system.reflection.missing.value, system.reflection.missing.value, system.reflection.missing.value, system.reflection.missing.value, system.reflection.missing.value); microsoft.office.interop.excel.worksheet xlworksheet = (worksheet)xlworkbook.worksheets[1]; xlworkbook.saveas(filename, microsoft.office.interop.excel.xlfileformat.xlworkbookdefault, type.missing, type.missing, true, false, xlsaveasaccessmode.xlnochange, xlsaveconflictresolution.xllocalsessionchanges, type.missing, type.missing); xlworkbook.close(); system.io.file.delete(pathfile); xlapp.quit();
Comments
Post a Comment