In principal, despre .NET, VB6. C#,VB.NET, ASP.NET Apoi despre programare si multe alte chestii ... de programare.

Subscribe RSS   Mini tools List

vineri, iunie 20, 2008

Data Table sau Ienumerable to Excel/Word / PDF
Va rog sa folositi acest URL NOU de la

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


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


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.


Version 1

Post page:

Weblog post by 'admin' on 'Data Table sau Ienumerable to Excel/Word / PDF'



Trimiteți un comentariu

Links to this post:

Creați un link

<< Home

Acest blog s-a mutat la