ASP.NET MVC를 사용하여 데이터베이스에서 Excel 시트로 데이터를 내보내는 방법은 무엇입니까?

DiPix

누구든지 간단한 NuGet 패키지 또는 데이터베이스에서 Excel로 데이터를 내보내는 다른 방법을 알고 있습니까? 몇 개의 테이블과 각각 다른 워크 시트로 내보내려는 테이블이 있지만 동일한 Excel 파일에 있습니다.

또한 나중에 파일 Excel에서 데이터베이스로 데이터를 가져오고 싶습니다. 두 작업 모두 다른 라이브러리가 될 수 있습니다.

나는 이미 이것을 시도했지만 작동하지 않습니다.


@EDIT-해결됨

다음은 몇 가지 유용한 링크입니다. 언젠가 누군가를 도울 수 있기를 바랍니다. :)

http://epplus.codeplex.com/

http://techbrij.com/export-excel-xls-xlsx-asp-net-npoi-epplus

사라 바난 아루나 기리

이 코드는 EPPlus 에서 가져 오며 질문에 도움이됩니다. ::

private void ExcelExport(DataTable table)
        {
            using (ExcelPackage packge = new ExcelPackage())
            {
                //Create the worksheet
                ExcelWorksheet ws = packge.Workbook.Worksheets.Add("Demo");

                //Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
                ws.Cells["A1"].LoadFromDataTable(table, true);

                //Format the header for column 1-3
                using (ExcelRange range = ws.Cells["A1:C1"])
                {
                    range.Style.Font.Bold = true;
                    range.Style.Fill.PatternType = ExcelFillStyle.Solid;                      //Set Pattern for the background to Solid
                    range.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(79, 129, 189)); //Set color to dark blue
                    range.Style.Font.Color.SetColor(Color.White);
                }

               //Example how to Format Column 1 as numeric 
                using (ExcelRange col = ws.Cells[2, 1, 2 + table.Rows.Count, 1])
                {
                    col.Style.Numberformat.Format = "#,##0.00";
                    col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Right;
                }

                //Write it back to the client
                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AddHeader("content-disposition", "attachment;  filename=ExcelExport.xlsx");
                Response.BinaryWrite(packge.GetAsByteArray());
            }
        }

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관