내 테이블의 모든 레코드를 Excel 파일로 쓰고 싶습니다. 내 테이블에 약 30000 개의 행이 있습니다.변환 테이블
저는 Excel20000 행만 쓸 수 있습니다. System out of memory
예외가 발생합니다.
이것은 내 코드입니다. 미리 감사드립니다.
using (SqlConnection con = new SqlConnection(strconnection))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM tbl_ReportwithoutDup"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
using (XLWorkbook wb = new XLWorkbook())
{
wb.Worksheets.Add(dt, "Report1");
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;filename=Report1.xlsx");
using (MemoryStream MyMemoryStream = new MemoryStream())
{
wb.SaveAs(MyMemoryStream);
MyMemoryStream.WriteTo(Response.OutputStream);
Response.Flush();
Response.End();
}
}
}
}
}
}
Excel Interop 서비스 라이브러리를 사용하고 있습니까? 또는 Excel 파일을 생성하기 위해 어떤 라이브러리를 사용하고 있습니까? – mason
서버에서 interop을 사용하지 마십시오. 다음을보십시오. http://stackoverflow.com/a/9569827/351383 –