2

I have a grid view which contains items along with their serial numbers, description and quantity ordered. What I want to do is to allow users select some rows in my grid view and print them as an invoice either in a PDF format or Excel format. The invoice has its own template like the company’s name on the header, transaction number and seller information. I managed to build that grid view and print the selected items to a text files to ensure that my work is fine.

My question: what’s the best way to construct my invoice template and read the data source from that grid view? Are there any free components that could help me out? Are there any tutorials on my topic ?

Thanks for your help

dantee_87
  • 71
  • 1
  • 7
  • you have already tested that by creating text files now you want to do same but by creating pdfs right... – Glory Raj Dec 04 '11 at 13:48

3 Answers3

2

Many C# libraries exist to create PDF, here is a list with a few of them. I only used iText in the past, I think it is a good library. You can find tutorial easily. This one looks OK.

For Excel, the .NET Framework has already build-in feature, more info here.

Community
  • 1
  • 1
Flanfl
  • 516
  • 8
  • 29
0

Search for Telerik reporting Check this

Sleiman Jneidi
  • 22,907
  • 14
  • 56
  • 77
Hussein Zawawi
  • 2,907
  • 2
  • 26
  • 44
0

You can use a library called ExcelLibrary to print in invoice Excel format. It's open source library posted on Google Code and downloadable here.

Export a simple DataSet table to .xls or .xlsx

  //Here's the easy part. Create the Excel worksheet from the data set
    ExcelLibrary.DataSetHelper.CreateWorkbook("MyExcelFile.xls", ds);

Check these Create Excel (.XLS and .XLSX) file from C#, Using C# to Create an Excel Document and How to format an Excel file using C# for more details.

Here is an alternate also available:

NPOI library

The great thing about NPOI of course is that it enables you to work with the template in code and then send a copy of the spreadsheet directly to the user. The template remains intact and the user receives a modified copy of the template which contains the data processed by the application.follow this Creating Excel spreadsheets .XLS and .XLSX in C#

You can create formatting in your excel sheet using Office Interop. Check this
C# - Opening Excel Template(xlt), adding data, and saving to new worksheet(xls).

What about iText to use for creating Invoice in PDF format.

Check these list of examples that help you to create and manipulate pdf document.

using System; 
using com.lowagie.text;
using com.lowagie.text.pdf;
using System.IO;

public class TestPDF 
{
    public static void Main(string[] args) 
    {
        Console.WriteLine("Hello World");

        // step 1: creation of a document-object
        Document document = new Document();

        // step 2:
        // we create a writer that listens to the document
        // and directs a PDF-stream to a file
        PdfWriter.getInstance(document, new FileStream("MyPDF.pdf", FileMode.Create));

        // step 3: we open the document
        document.open();

        // step 4: we add a paragraph to the document
        document.add(new Paragraph("Hello World"));

        // step 5: we close the document
        document.close();
    }
}
Community
  • 1
  • 1
Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75