public static void ExcelDown(Repeater rpt, String ExcelName)
{
// 다운로드 되도록 헤더 설정
HttpContext.Current.Response.ClearContent();
// 오늘날짜로 저장
DateTime date = DateTime.Now;
string fileName = ExcelName + ".xls";
fileName = date.ToString("yyyy-MM-dd-") + fileName;
//한글처리: 저장할 파일명을 Server.UrlPathEncode()로 감싸준다.
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename="
+ HttpContext.Current.Server.UrlEncode(fileName) );
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
//Remove the charset from the Content-Type header.
HttpContext.Current.Response.Charset = "";
//Turn off the view state.
rpt.EnableViewState = false;
// 정보를 문자열로 쓰기위해 StringWriter클래스 사용.
System.IO.StringWriter stringWriter = new System.IO.StringWriter();
// ASP.NET 서버 컨트롤 출력 스트림에 태그 문자와 텍스트를 씁니다.
// 태그를 클라이언트로 렌더링할 때 사용하는 서식 기능을 제공합니다.
System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(stringWriter);
// 서버 컨트롤 콘텐츠를 출력하고, 추적 기능이 설정된 경우에는 컨트롤에 대한 추적 정보를 저장합니다.
rpt.RenderControl(htmlWriter);
// 엑셀 파일에 한글 깨짐을 방지.
System.Text.Encoding enc = System.Text.Encoding.Default;
byte[] translatedbyte = enc.GetBytes(stringWriter.ToString());
translatedbyte = System.Text.Encoding.Convert(enc, System.Text.Encoding.UTF7, translatedbyte); // UTF7로
string strConverted = enc.GetString(translatedbyte);
HttpContext.Current.Response.Write(strConverted.ToString()); //Write the HTML back to the browser.
HttpContext.Current.Response.End();
// 리피터에 데이타를 묶어준다.
rpt.DataBind();
}
위에 소스는 인터넷에 돌아다니는 소스 조합해서 만든건데요.
MS excel 2003 에서는 저장이 잘되는데 2008에서 열리지가 않습니다. "셀 데이터가 너무 큽니다." 라는 에러가 발생하며
안열려요.
도와주세요.
댓글
댓글 리스트-
작성자심재운 작성시간 08.08.29 참고로 code project 사이트에 가면 Excel 2007 addin written in C# 이 있더군요. 한번 협업에 사용해 보시는건 어떨런지요. http://code.msdn.microsoft.com/ExcelExtensions
-
작성자푸하하3 작성자 본인 여부 작성자 작성시간 08.08.29 위에 소스는 엑셀 2003에서는 잘됩니다. 사실 전 2003 사용해서 몰랐는데, 동료 테스트 중에 발견된 문제점인데요. 인터넷 알아보니, 1. 레지스트리 값을 바꾸라는 말, 2. MS가 제공하는 프로그램을 받으라고 . 3 은 소스 보고 있는데 이해가 잘안가요 ㅋ. 답변 감사합니다.
-
답댓글 작성자심재운 작성시간 08.08.29 레지스터리 어딜.. 바꿔야 하나요? 저는 처음 듣는거지만,,, 아시면 알려주세욤.ㅎ
-
작성자푸하하3 작성자 본인 여부 작성자 작성시간 08.08.29 참고로 '오즈 레포트' 툴로 엑셀로 파일 만들어서 떨구면, 역시나 2007에서 안열립니다. http://msdn.microsoft.com/en-us/library/bb407651.aspx 여기서 소스 따라하는 중인데, 전 왜 Microsoft Excel 12.0 Object Library이 없고 Microsoft Excel 11.0 Object Library 만 있조? 닷넷 프레임웍 2.0이라 그런가요?
-
답댓글 작성자심재운 작성시간 08.08.29 11.0 은 Microsoft Office 2003 용이고요. 12.0 부터 2007 Microsoft Office System 용입니다. 2007 office 설치 하셨다고 하면 보일겝니다. 참고로 닷넷 프레임웍 2.0 와 상관없습니다. 이는 office 가 설치되어야 존재하는 component 입니다.