Posts

Showing posts with the label Excel

NPOI Does Not Support CSV

I've been using NPOI for sometime now and was recently asked to create a process to output some data in a csv for better support. I was hoping to bring NPOI in the mix but I had to ask myself does NPOI support CSV/TSV?, simply put no.

Alternatives
http://filehelpers.sourceforge.net/
https://github.com/MarcosMeli/FileHelpers

Library Version - Reading/Writing
Project Version - Server/Storage Features included.

And... There just doing it my way. Personally speaking I didn't like jumping into FileHelpers, I felt was much more overhead than what I need so I looked at creating a small snippet of code for myself. Unlike with NPOI, I also didn't like from what I could see was examples that needed a model to be passed in. Either way, I will try to post an update when I have finished that piece of the puzzle.

Resources
Returning in the middle of a using block - A question for the code examples I saw. asp.net - Response Content type as CSV
Back to Basics - Keep it Simple and Develop Yo…

MVC Excel Email Attachment with NPOI

The First Question I had after successfully creating a Excel sheet was how do I create an attachment from a stream? A second to be more specific was how do I add an attachment to an email using System.Net.Mail? Ultimately I wanted to have the Excel Exports in C# using NPOI but I started small and thankfully others had already asked and answered these questions. After which was just a matter of knowing What the correct content-type for excel files was?
First Attempt
MailMessage mail = new MailMessage(); HSSFWorkbook workbook = CreateExcel(OrderId); MemoryStream ms = new MemoryStream(workbook.GetBytes()); mail.Attachments.Add(new Attachment(ms, "example.xls", "application/vnd.ms-excel")); _emailService.SendEmail("example@example.com", "Email test", "Testing 123"); Changed it to.. MemoryStream ms = new MemoryStream(); workbook.Write(ms); This was based on the QA "NPOI - Sending workbook as ema…

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? W…