This project is read-only.

Where Does a Beginner Start

Mar 31, 2010 at 9:03 PM

I have been directed to the NPOI tools to create Excel spreadsheets from my code behind (Visual Basic) my ASP.Net web site using Visual Web Developer 2008 Express.

The only problem is there are no instructions telling me:

1.  What files I need.

2. Where to place these files in my web site.

3. What to place at the top of my Visual Basic page so that I may use the Excel functions.

Can anyone please provide these essential instructions?  I have been to the web site, but there are no instructions on how to get started (in English).

One problem with coders is we write code and then leave it up to others to figure out how to use it.  I need a step by step road map.  Thanks.

Apr 1, 2010 at 1:59 AM

Here is a nice reply I received for a similar question on the ASP.NET Forums from Hans:

1. Download the NPOI Release Binary, and unzip the zip file

2. Copy all the files (except ICSharpCode.SharpZipLib.dll) into the Bin directory of your website 

3. Place this import statements:

Imports System.IO
Imports NPOI.HSSF.UserModel
Imports NPOI.HSSF.Util
Imports NPOI.POIFS.FileSystem

4. and an example:

    Public Sub CreateAndDownloadXls(ByVal filename As String)
        'Create workbook
        Dim workbook = New HSSFWorkbook()
        'Create Sheets
        Dim sheet1 As HSSFSheet = workbook.CreateSheet("Sheet1")
        Dim sheet2 As HSSFSheet = workbook.CreateSheet("Sheet2")

        'Select Cell A1 on sheet1 and set value to "Hello World"
        Dim RowNumber As Integer = 0 'RowNumber is zero based
        Dim Column As Integer = 0 'Column is zero based
        sheet1.CreateRow(RowNumber).CreateCell(Column).SetCellValue("Hello World")

        'Merge Cells on sheet2, A2 (0,1) to C4 (2,3)
        Dim region As New Region(0, 1, 2, 3)
        'Select the merged region with the top left cell (0,1)
        sheet2.CreateRow(0).CreateCell(1).SetCellValue("merged cells")
        'Create XLS file in memory

        Dim file As New MemoryStream()
        'Stream file to browser
        Response.ContentType = "application/"
        Response.AddHeader("Content-Disposition", String.Format("attachment;filename={0}", filename))
    End Sub