System.Web.HttpResponse objResponse = System.Web.HttpContext.Current.Response;
objResponse.ClearContent();
objResponse.ClearHeaders();
objResponse.ContentType = "application/vnd.msexcel";
objResponse.AddHeader("content-disposition", "attachment; filename=SearchResults.xls");
objResponse.AppendHeader("Content-Length", result.Length.ToString());
objResponse.Charset = "euc-kr";
objResponse.ContentEncoding = Encoding.GetEncoding(949);
objResponse.Write(result);
objResponse.Flush();
objResponse.Close();
objResponse.End();
예제는 엑셀 데이터를 다운로드 하는 경우이다. result string 에는 탭으로 분리된 텍스트를 넣어주면 xls파일로 다운로드 된다. 정식 엑셀 파일은 아니고 csv를 xls 확장자로 다운로드 하면 나머지는 엑셀이 알아서 한다. 푸른색으로 된 부분은 한글 코드 문제로 넣어 준것이다. 그냥 Unicode로 보내면 엑셀이 제대로 처리하지 못한다. 이유는 모르겠다.