简体   繁体   中英

Can't get text Area value in export to excel and also in printing page

I am using ASP.NET MVC 4 and html with razor engine. Upon my project requirement I have to print the values inside the table and also export it into excel. I m using the JavaScript code as follows :

function exportbtn() {
    debugger;
    var chk = FCDdata.outerHTML;
    $("#idhdnfield").val(chk);
}

Then in my controller I get the value of hidden field and then export it to excel.

Response.Clear();
Response.AppendHeader("content-disposition", "attachment;filename=Crewdata.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.ms-excel";
Response.Write(hdnfield);
Response.End();

My problem is , there sa column in my table where I have to display many values. So I used text area in my td.

<td> <textarea>My value </textarea> </td>

But this value is left blank in my excel sheet and also the print page shows the first visible line with scroll and not the whole values inside td. Can you please advise what needs to be done?

Probably your textarea value has line breaks. So try to send the data with linebreaks removed ie

function exportbtn() {
    debugger;
    var chk = FCDdata.outerHTML;
    $("#idhdnfield").val(chk.split("\n").join("").split("\r").join(""));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM