2010/10/14 13:37
jqGrid Excel 변환 asp.net 2.0 My Develop/ASP.NET2010/10/14 13:37
Case 1.
step.1: ValidateRequest="false" 선언
step.2: Server Control 추가
step.3: Client Button 추가
step.4: Javascript 구현
step.5: Server Script 구현
Case 1.의 문제점은 전체데이터를 가져오기 못하고 현재 조회된 내용만 엑셀로 변환된다.
따라서 step.5에서 다시 DB로 접속하여 전체 데이터를 가져오는 로직을 구현이 필요함.
step.1: ValidateRequest="false" 선언
<%@ Page Language="C#" MasterPageFile="~/JKAMS_SUB.master"
AutoEventWireup="true" CodeFile="AA_W001.aspx.cs"
Inherits="AA_AA_W001" Title="Untitled Page"
ValidateRequest="false"%>
step.2: Server Control 추가
<form runat="server">
<asp:Button ID="btnExcel" runat="server" Text="Export"
onclick="btnExcel_Click" />
<asp:HiddenField ID="hdnHtml" runat="server" />
</form>
step.3: Client Button 추가
<!-- jqGrid -->
<table id="list1"></table>
<div id="pager1"></div>
<!-- jqGrid -->
<button id="btnExportToExcel">엑셀변환</button>
step.4: Javascript 구현
// 엑셀 변환버튼 이벤트
$('[id$=btnExcel]').hide();
$("#btnExportToExcel").button({ icons: { primary: 'ui-icon-plus'} })
.click(function () {
var tbody = $("#list1").html();
var thead = $(".ui-jqgrid-htable").html();
var htmlTable = "<table>" + thead + tbody + "</table>";
var strCopy = htmlTable;
window.alert(strCopy);
$('[id$=hdnHtml]').val(strCopy); // fill the hidden with the table content
$('[id$=btnExcel]').click(); // click button hidden
});
step.5: Server Script 구현
protected void btnExcel_Click(object sender, EventArgs e)Case 2.
{
string codigo;
codigo = hdnHtml.Value;
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
Page pagina = new Page();
HtmlForm form = new HtmlForm();
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=Visor.xls");
Response.Charset = "UTF-8";
Response.ContentEncoding = Encoding.Default;
pagina.EnableEventValidation = false;
pagina.DesignerInitialize();
pagina.Controls.Add(form);
pagina.RenderControl(htw);
Response.Write(codigo);
Response.End();
}
Case 1.의 문제점은 전체데이터를 가져오기 못하고 현재 조회된 내용만 엑셀로 변환된다.
따라서 step.5에서 다시 DB로 접속하여 전체 데이터를 가져오는 로직을 구현이 필요함.
'My Develop > ASP.NET' 카테고리의 다른 글
| jqGrid Excel 변환 asp.net 2.0 (0) | 2010/10/14 |
|---|---|
| SyntaxHighlighter 자료 (0) | 2010/10/05 |
