MVC Data Exported to Excel with NPOI

This is an article for just writing an Excel file using NPOI and I want the quickest and easiest way to export a excel file from Asp.net MVC. To keep everything in work fluid motion I will keep the user on the same page and do a forced download within that page. This is a setup that I have seen in multiple times and I think works great in today's modern website designs.

Creates excel files
Leniel Macaferi's blog: Creating Excel spreadsheets .XLS and .XLSX in C#
Create Excel Spreadsheets Using NPOI
var workbook = new HSSFWorkbook();
var ExampleSheet = workbook.CreateSheet("Example Sheet");
var rowIndex = 0;
var row = ExampleSheet.CreateRow(rowIndex);
row.CreateCell(0).SetCellValue("Example in first cell(0,0)");
rowIndex++;
Problems I faced
XLS is not the same as CVS which is obvious but truthfully I did not know the difference between the two file types (other than their different extensions). So I asked myself what is the Difference between CSV and XLS files? When creating a file with NPOI make sure you are using XLS and not CVS.  If by mistake you create the file a CSV file type you can simply change the extension but remember by default some windows by hide known extensions. How to Change a File Extension in Windows may not be clear and the link provide should help.

Research

The Next part is to create this Excel as a Email Attachment!

Popular posts from this blog

Aspetcore: NLog with Postgresql

Mongodb Cheatsheet

Installing Windows on Acer chromebook 15 cb3-532