¹Ú¿ëÁØ °»ç ´ÔÀÌ ¾²½Å ¿ø¹® ±ÛÀÔ´Ï´Ù.
¾È³çÇϼ¼¿ä.
±¸±Û °Ë»ö ¿£Áø¿¡¼
"asp.net gridview download to excel"
½ÄÀ¸·Î °Ë»öÇغ¸¸é ³ª¿À´Â ¸¹Àº ¾ÆƼŬµéÀÌ µµ¿òÀÌ µÉ °Í °°½À´Ï´Ù.
Ãß°¡·Î,
¾Æ·¡ ¸µÅ©ÀÇ À¯Æ©ºê °Á¸¦
Âü°íÇØ º¸½Ã±â ¹Ù¶ø´Ï´Ù.
(µ¥ºê·º °ÀÇ µ¥¸ð) ASP.NET Web Forms¿¡¼ GridView Ãâ·Â ³»¿ëÀ» Excel(¿¢¼¿) ÆÄÀÏ·Î ´Ù¿î·Îµå
https://youtu.be/UXkmyUy2c_k
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Web;
namespace LogManager.Models
{
public class ExcelDownUtility
{
public static void ExcelDownloadWithTabSeparatedValues(
IEnumerable data, TextWriter output)
{
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ContentEncoding =
System.Text.Encoding.Default;
HttpContext.Current.Response.AddHeader(
"content-disposition", "attachment;filename=" +
HttpUtility.UrlEncode(System.DateTime.Now.ToString(),
System.Text.Encoding.UTF8) + ".xls");
HttpContext.Current.Response.AddHeader(
"Content-Type", "application/vnd.ms-excel");
PropertyDescriptorCollection props =
TypeDescriptor.GetProperties(typeof(T));
foreach (PropertyDescriptor prop in props)
{
output.Write(prop.DisplayName);
output.Write("\t");
}
output.WriteLine();
foreach (T item in data)
{
foreach (PropertyDescriptor prop in props)
{
output.Write(prop.Converter.ConvertToString(
prop.GetValue(item)));
output.Write("\t");
}
output.WriteLine();
}
HttpContext.Current.Response.End();
}
}
}
¾ÈÁ¤ÁØ ´ÔÀÌ ¾²½Å ¿ø¹® ±ÛÀÔ´Ï´Ù.
¾È³çÇϼ¼¿ä ¹Ú¿ëÁØ°»ç´Ô
°»ç´Ô °ÀÇ·Î asp.net ¿°ø Áß¿¡ ÀÖ½À´Ï´Ù
ȸ鿡 ÀڷḦ °Ë»öÇÏ¿© gridview·Î »Ñ·ÁÁö°ÔÇߴµ¥
ȸ鿡 º¸ÀÌ´Â gridview¸¦ ¿¢¼¿·Î ´Ù¿î·Îµå¹Þ°Ô ÇÏ·Á´Ï ¹æ¹ýÀ» ¸ð¸£°Ú½À´Ï´Ù
¾Ë·ÁÁÖ½Ã¸é °¨»çÇÏ°Ú½À´Ï´Ù