MVC 엑셀 내 보 내기 방법 중 하나(View 엑셀 내 보 내기)
10427 단어 Excel 내 보 내기
사고방식:View 로 excel 내 보 내기
단계:
1.태그 추가 이벤트 내 보 내기
$("#export_A").click(function(){
//코드 생략...
window.location.href = "/DuplicateTaskManager/DuplicateTaskManager/ExportExcel/?taskId=" + taskId + "&unitId=" + unitId + "&levelId=" + levelId;
});
2.보기 준비
public ActionResult ExportExcel(int taskId, int unitId, int levelId)
{
HttpContext.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Response.Charset = "utf-8";
HttpContext.Response.ContentEncoding = Encoding.UTF8;
HttpContext.Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + UTF_FileName(" _" + DateTime.Now.ToString("yyyyMMddHHmmss")) + ".xls\"");
//list , , , View
return PartialView(list);
}
/// <summary>
/// UrlEncode
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
private static string UTF_FileName(string filename)
{
return HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8);
}
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }3.데이터 옮 겨 다 니 기 보기
<table border="1">
<thead>
<tr>
<td width="100" rowspan="2">
</td>
<td width="60" rowspan="2">
</td>
<td rowspan="2">
</td>
<td colspan="<%=ss.Keys.Count%>">
<span style="margin-left: 40%;"> </span>
</td>
<td width="60" rowspan="2">
</td>
<td rowspan="2">
</td>
</tr>
<tr>
<%
foreach (var item in ss.Keys)
{
%>
<td width="100">
<%=ss.Get(item.ToString()) %>
</td>
<%
}
%>
</tr>
<%
int i = 1;
foreach (var item in Model)
{%>
<tr>
<td>
<%=item.UnItName %>
</td>
<td>
<%=item.SumCount %>
</td>
<td>
<%=item.NotApprovedCount %>
</td>
<%
foreach (var key in ss.Keys)
{
%>
<td>
<%=item.Dcits.Get(key.ToString()) %>
</td>
<%
}
%>
<td>
<%=string.Format("{0}%", item.CompleteRate.ToString("0.00"))%>
</td>
<td>
<%
if (i < Model.Count)
{%>
<%=i%>
<%}
%>
</td>
</tr>
<%
i++;
}%>
</thead>
</table>
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
결론:간단 한 내 보 내기,빅 데이터 에서 스스로 테스트 하 세 요.