Data Table sau Ienumerable to Excel/Word / PDF

Am reusit sa fac ceea ce vroiam de mult … Sa export din DataTable sau IEnumerable<T> direct in Excel / Word / PDF …
Codul este pe CodePlex

Am vrut sa il pun si pe code project, dar datorita faptului ca sunt foarte succint, mi l-au sters (aproape) imediat.

Asa ca il scriu aici

Introduction

The project exports a DataTable or IEnumerable to Word / Excel / PDF / CSV / HTML / CSV

Background

Make
extensive use of

  1. String
    Template
    – for rendering templates(EXcel 2003, Word 2003 , HTML,CSV)

  2. OfficeSDK
    for rendering the Word
    /Excel 2007
  3. itextsharp. for exporting to PDF from XML.

Using the Code

Every programmer have a DataTable or IEnumerable and wants to export to the user in an easy way.

This project enables an easy and customizable way to export data to various formats.

            
DataTable dta = new DataTable("andrei");
dta.Columns.Add(new DataColumn("ID", typeof(int)));
dta.Columns.Add(new DataColumn("Data", typeof(string)));
dta.Rows.Add(1, "test 1 & <");
dta.Rows.Add(2, "test 2 ");
dta.Rows.Add(3, "test 3 >");

dta.ExportTo(ExportToFormat.Excel2007, @"C:\andrei.xlsx");

dta.ExportTo(ExportToFormat.Word2003XML, @"C:\andrei.doc");


dta.ExportTo(ExportToFormat.Word2007, @"C:\andrei.docx");


dta.ExportTo(ExportToFormat.itextSharpXML, @"C:\aitext.xml");

dta.ExportTo(ExportToFormat.Excel2003XML, @"C:\andrei.xls");


dta.ExportTo(ExportToFormat.HTML, @"C:\andrei.html");


dta.ExportTo(ExportToFormat.XML, @"C:\andrei.xml");

dta.ExportTo(ExportToFormat.PDFtextSharpXML, @"C:\andrei.pdf");


Points of Interest

The String
Template
is really really great. I think that a good programmer can make a second CodeSmith from there…

The itextsharp has some problems with XML transformation to PDF.
Please check whitespaces after xml tags if it says something like ” can not transform table into paragraph”

The
OfficeSDK
is really great – and really easy to use.

History

Version 1

Leave a Reply

Your email address will not be published. Required fields are marked *