Asp.net 如何在asp mvc2中将选定数据导出到excel工作表而不使用第三方
我想导出excel工作表上的选定数据我的视图代码在这里Asp.net 如何在asp mvc2中将选定数据导出到excel工作表而不使用第三方,asp.net,asp.net-mvc-2,Asp.net,Asp.net Mvc 2,我想导出excel工作表上的选定数据我的视图代码在这里 <% using (Html.BeginForm("ExcelExport", "Process", FormMethod.Post)) { %> <div id="formdata" style="width:700px;overflow:scroll"> <table border="0"> <tr> <th>select</th>
<% using (Html.BeginForm("ExcelExport", "Process", FormMethod.Post))
{ %>
<div id="formdata" style="width:700px;overflow:scroll">
<table border="0">
<tr>
<th>select</th>
<th>
FirstName
</th>
<th>
Lastname
</th>
<th>
EmailID
</th>
<th>
ContactNO
</th>
<th>
Qualification
</th>
<th>
CurrentCTC
</th>
<th>
ExpectedCTC
</th>
<th>
Experience
</th>
<th>CurrentLocation</th>
<th> keyskill</th>
<th>Company</th>
</tr>
<% foreach (var candidate in Model)
{ %>
<div class="item">
<tr>
<td>
<input type="checkbox" name="cid" value="<%= candidate.CandidateID %>" />
<%:Html.ActionLink("W", "Getfile", new { id = candidate.CandidateID })%>
</td>
<td>
<h3><%=candidate.FirstName%></h3>
</td>
<td>
<%=candidate.LastName%></td>
<td><%=candidate.EmailID%></td>
<td><%=candidate.Phone1%></td>
<td> <%=candidate.Qualification%></td>
<td><%=candidate.CurrentCTC%></td>
<td><%=candidate.ExpectedCTC%></td>
<td><%=candidate.Experience%></td>
<td><%=candidate.CurrentLocation %></td>
<td><%=candidate.KeySkill.KeySkills %></td>
<td><%=candidate.Company.CompanyName %></td>
我想选中“使用行”复选框,然后单击“导出”按钮,然后将我的数据导出到excel工作表中。请任何人给我示例代码,其紧急情况嗨,朋友们,我得到了解决方案
这是我的代码,我将所选项目提取到excel中
public ActionResult ExportExcel(int[] cid )
{
var grid = new GridView();
Response.ClearContent();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment;filename=candidateRecord.xls");
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
var candidate = IcandidateRepository.Candidate.ToList();
grid.DataSource = from p in candidate where cid.Contains(p.CandidateID) select new { name = p.FirstName, companyName = p.Company.CompanyName };
grid.DataBind();
grid.RenderControl(hw);
Response.Write(sw);
Response.End();
return View();
}
打开excel文档i记事本,您会看到某种xml。所以你应该能够复制这个。之后,你只需要发送文件作为exel文件:这是理论,你可以检查这个链接出来,请给相关的样本代码的紧迫性
public ActionResult ExportExcel(int[] cid )
{
var grid = new GridView();
Response.ClearContent();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment;filename=candidateRecord.xls");
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
var candidate = IcandidateRepository.Candidate.ToList();
grid.DataSource = from p in candidate where cid.Contains(p.CandidateID) select new { name = p.FirstName, companyName = p.Company.CompanyName };
grid.DataBind();
grid.RenderControl(hw);
Response.Write(sw);
Response.End();
return View();
}