Archive for August, 2007

ExcelReader can Read Excel files in pure C# without interop.

One of my customers ask me to Convert Excel to XML and save the data to database on website, but his website does not support Ms Excel. I have to look for another solution, on CodeProject, I got ExcelReader.

Sample Image - ExcelReader.png

Introduction

This library is built based on the following documents, thanks to their authors:

Record structures in BIFF8/BIFF8X format are considered.

What it can do?

  • It can read read worksheets in a workbook and read cells in a worksheet.
  • It can read cell content (text, number, datetime, or error) and cell format (font, alignment, linestyle, background, etc.).
  • It can read pictures in the file, get information of image size, position, data, and format.

Using the code

  1. Open file:
    Stream fileStream = File.OpenRead(file);
    Workbook book = new Workbook();
    book.Open(fileStream);
    Worksheet sheet = book.Worksheets[0];
  2. Read cell:
    int row = 1;
    int col = 0;
    string ID = sheet.Cells[row, col].StringValue;
    
    Picture pic = sheet.ExtractPicture(row, col);
Share and Enjoy:
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists
  • BlinkList
  • blogmarks
  • blogtercimlap
  • connotea
  • DotNetKicks
  • Fark
  • Fleck
  • Gwar
  • Haohao
  • IndianPad
  • Internetmedia
  • LinkaGoGo
  • MyShare
  • Netscape
  • NewsVine
  • Rec6
  • Reddit
  • Scoopeo
  • Slashdot
  • StumbleUpon
  • Technorati
  • Webride

Freely fill PDF form with the help of iText or iTextSharp

iText(java version) and iTextSharp(dotnet version) are very powerful libraries to create and manipulate PDF, but this time, I just want to talk about how to fill PDF form with the help of iText or iTextSharp.

for java version, please visit http://itextdocs.lowagie.com/tutorial/#part5, there are many examples about fill or create PDF form.

for dotnet version(C#),
the easiest example is
PdfReader reader = new PdfReader("SimpleRegistrationForm.pdf");
PdfStamper stamp1 = new PdfStamper(reader, new FileStream("registered.pdf",FileMode.Create));
AcroFields form1 = stamp1.AcroFields;

form1.SetField("name", "Steven");
form1.SetField("address", "http://blog.rubypdf.com");
form1.SetField("postal_code", "200051");
form1.SetField("email", "rocsky@gmail.com");
stamp1.Close();
reader.Close();

and if you want to fill CJK(Chinese, Japanese and Korean) characters to PDF from, have a look the following code,

BaseFont.AddToResourceSearch("iTextAsian-1.0.dll");
BaseFont.AddToResourceSearch("iTextAsianCmaps-1.0.dll");
BaseFont font = BaseFont.CreateFont("STSong-Light", "UniGB-UCS2-H", BaseFont.EMBEDDED);
//if you want to use truetype fonts
//BaseFont font = BaseFont.CreateFont("c:\\windows\\fonts\\STSONG.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

PdfReader reader = new PdfReader("SimpleRegistrationForm.pdf");
PdfStamper stamp1 = new PdfStamper(reader, new FileStream("registered.pdf",FileMode.Create));

AcroFields form1 = stamp1.AcroFields;

//if the field you want to fill CJK characters, but the font it used does not support cjk, you need modify it before fill.
form1.SetFieldProperty("name","textfont",font,null);

//fill the form now
form1.SetField("name", "小李");
form1.SetField("address", "http://blog.rubypdf.com");
form1.SetField("postal_code", "200051");
form1.SetField("email", "rocsky@gmail.com");
stamp1.Close();
reader.Close();

related resources from my Chinese Blog and my free asp.net hosting,

Share and Enjoy:
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists
  • BlinkList
  • blogmarks
  • blogtercimlap
  • connotea
  • DotNetKicks
  • Fark
  • Fleck
  • Gwar
  • Haohao
  • IndianPad
  • Internetmedia
  • LinkaGoGo
  • MyShare
  • Netscape
  • NewsVine
  • Rec6
  • Reddit
  • Scoopeo
  • Slashdot
  • StumbleUpon
  • Technorati
  • Webride

install YetAnotherForum.NET on free asp.net 2.0 hosting-aspspider.net

YetAnotherForum.NET (YAF) is a Open Source discussion forum or bulletin board system for web sites running ASP.NET. The latest version is ASP.NET v2.0 with a Microsoft SQL Server backend. The full C# source code is available licensed as GPL.

Yesterday, some friends talked about set up a asp.net forum, and one of them recommended YAF, I googled it today, and tried to installed on my free asp.net 2.0 hosting, aspspider.net(it does not offer hosting to new user). It is very easy to install,

  • download from http://sourceforge.net/project/showfiles.php?group_id=90539
  • log on http://www.aspspider.net/cp/
  • upload YAF-v1.9.0-FINAL-BIN.zip and uncompress,
  • create a blank database at local, for example name yaf, so you get yaf.mdf and yaf_log.ldf, just upload yaf.mdf to database folder and forget yaf_log.ldf.
  • attach yaf.mdf as tonyfox_yaf(because my usename is tonyfox, so the prefix is tonyfox_)
  • find default.config and rename to web.config
  • edit the connect string in web.config, just like this,
    .\SQLExpress;Persist Security Info=True;Integrated Security=SSPI;Initial Catalog=tonyfox_yaf
  • install YAF now,http://aspspider.net/tonyfox/install/

Feel free to visit my demo,
http://aspspider.net/tonyfox/

related resource,

Share and Enjoy:
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists
  • BlinkList
  • blogmarks
  • blogtercimlap
  • connotea
  • DotNetKicks
  • Fark
  • Fleck
  • Gwar
  • Haohao
  • IndianPad
  • Internetmedia
  • LinkaGoGo
  • MyShare
  • Netscape
  • NewsVine
  • Rec6
  • Reddit
  • Scoopeo
  • Slashdot
  • StumbleUpon
  • Technorati
  • Webride