티스토리 툴바


달력

05

« 2012/05 »

  •  
  •  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  •  
  •  
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" 선언
<%@ 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)
{
   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 2.
   Case 1.의 문제점은 전체데이터를 가져오기 못하고 현재 조회된 내용만 엑셀로 변환된다.
   따라서 step.5에서 다시 DB로 접속하여 전체 데이터를 가져오는 로직을 구현이 필요함.

저작자 표시

'My Develop > ASP.NET' 카테고리의 다른 글

jqGrid Excel 변환 asp.net 2.0  (0) 2010/10/14
SyntaxHighlighter 자료  (0) 2010/10/05
TAG jqGrid, 엑셀
Posted by julieth
2010/10/05 17:24

SyntaxHighlighter 자료 My Develop/ASP.NET2010/10/05 17:24

Example

      	string url = "<a href=\"" + someObj.getUrl() + "\" target=\"_blank\">";
      
      	// single line comments
      	// second single line
      	override protected void OnLoad(EventArgs e)
      	{
      		if(Attributes["class"] != null)
      		{
      			//_year.CssClass = _month.CssClass = _day.CssClass = Attributes["class"];
      		}
      		base.OnLoad(e);
      	}
      

관련자료 URL:
http://alexgorbatchev.com/SyntaxHighlighter/about.html
저작자 표시

'My Develop > ASP.NET' 카테고리의 다른 글

jqGrid Excel 변환 asp.net 2.0  (0) 2010/10/14
SyntaxHighlighter 자료  (0) 2010/10/05
Posted by julieth