C# create/modify/read .xlsx files

With EPPlus it’s not required to create file, you can do all with streams, here is an example of ASP.NET ashx handler that will export datatable into excel file and serve it back to the client : public class GetExcel : IHttpHandler { public void ProcessRequest(HttpContext context) { var dt = DBServer.GetDataTable(“select * from table”); … Read more

How to read file using NPOI

Simple read example below: using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; //….. private void button1_Click(object sender, EventArgs e) { HSSFWorkbook hssfwb; using (FileStream file = new FileStream(@”c:\test.xls”, FileMode.Open, FileAccess.Read)) { hssfwb= new HSSFWorkbook(file); } ISheet sheet = hssfwb.GetSheet(“Arkusz1”); for (int row = 0; row <= sheet.LastRowNum; row++) { if (sheet.GetRow(row) != null) //null is when the row only … Read more