C# 匯出Excel套件 EPPlus

 EPPlus

//非商業用

ExcelPackage.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial;

               //filePath:檔案路徑

                FileInfo FileInfoXLS = new FileInfo(filePath);

                using (ExcelPackage package = new ExcelPackage(FileInfoXLS))

                {

                    ExcelWorksheet ws = package.Workbook.Worksheets.Add("Data");


                    // 將DataTable資料塞到sheet中

                    ws.Cells["A1"].LoadFromDataTable(dtData, true);


                    // 設定Excel Header 樣式

                    using (ExcelRange rng = ws.Cells[1, dtData.Columns.Count])

                    {

                        rng.Style.Font.Bold = true;

                        rng.Style.Fill.PatternType = ExcelFillStyle.Solid;

                        rng.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(79, 129, 189));

                        rng.Style.Font.Color.SetColor(Color.White);

                    }


                    var stream = new MemoryStream();

                    package.Save();

                    package.Dispose();

                }

留言

這個網誌中的熱門文章

ORA-12514: TNS: 監聽器目前不知道連線描述區中要求的服務

Oracle 例外控制(Exception Control)

Oracle 工作排程 DBMS_JOB 筆記