20120601_Excel 元件 ep plus joncash

681 views
585 views

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
681
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

20120601_Excel 元件 ep plus joncash

  1. 1. 1Excel 元件 -EPPlus!Presented byJoncash6/1/2012
  2. 2. 2Outline• Introduction EPPlus• Other Library• Limit & License• How to use• Snippet Code• References
  3. 3. 3Introduction EPPLus• EPPlus is a .net library that reads and writes Excel 2007/2010 files using the Open Office Xml format (xlsx).• EPPlus 提供簡單、便捷的 API 介面 ▫ 用 .Cells[rowIndex, colIndex] 就能直接存取欄位 ▫ 用 .Cells[r1:c1] 就能取得一段選取範圍 ▫ 用 Cells[…].Style.Font.Color.SetColor(Color.Red) 改變字型 ▫ Many more
  4. 4. 4Other Library• NPOI Library ▫ 源自於 Apache POI 專案• Open XML SDK ▫ 微軟提供的函式庫• OpenOffice.org SDK ▫ OpenOffice• LinqToExcel ▫ 只限於讀取
  5. 5. 5Limit & License• Only Support Excel 2007/2010• LGPL ( GNU Lesser General Public License ) ▫ 純引用 Library 不用 open source. ▫ 有修改 Library, 修改的部份要及產品中使用到的 Source Code 要 Open Source
  6. 6. 6How to use• Download ▫ http://epplus.codeplex.com/ ▫ NuGet• Reference EPPlus.dll in your project
  7. 7. 7Snippet Code//Create ExcelFileInfo newFile = new FileInfo(outputDir.FullName + @"sample6.xlsx");ExcelPackage pck = new ExcelPackage(newFile);//Add the Content sheetvar ws = pck.Workbook.Worksheets.Add("Content");//set stylews.Cells["B1:E1"].Style.Font.Bold = true;//set valuews.Cells["B1"].Value = "Name";
  8. 8. 8EPPlus and Linqvar sheet1 = pck.Workbook.Worksheets["Sheet1"];var query = (from cell in sheet1.Cells["a:a"]where cell.Value != ""select cell);query3.SingleOrDefault().Value.Dump(); Version 2.8 has added support for enumeration of cells....
  9. 9. 9NPOI V.S EPPlusNPOI EPPLUs// 建立 worksheet var pck = new ExcelPackage(newvar workBook = new HSSFWorkbook(); FileInfo(@"D:EPPLus.xlsx"));// 建立 sheet // 建立 sheetvar sheet1 = var sheet1 =workBook.CreateSheet("Sheet1"); pck.Workbook.Worksheets.Add("Sheet1") ;// 設值sheet1.CreateRow(1).CreateCell(1).SetCellValue("XXX"); // 設值 sheet1.Cells[1, 1].Value = "XXX";// 存檔FileStream file = new // 存檔FileStream(@"C:NPOI.xls", pck.Save();FileMode.Create);hssfworkbook.Write(file);file.Close();
  10. 10. 10References• 比NPOI更討喜的Excel元件-EPPlus!• EPPlus-Create advanced Excel 2007 spreadsheets on• [C#] NPOI、OpenXML SDK、 OpenOffice.org SDK 寫入資料到 EXCEL 檔案• 在 Server 端存取 Excel 檔案的利器: NPOI Library• Creating Reports in Excel 2007 using EPPlus (

×