Veggerby.Excel

1 Comment

Having (at work) numerous times been presented with the with the requirement: "we need to have this in Excel", I have created an easy-to-use Excel sheet creation library that does not require Office to be installed (as in the Microsoft.Office.Tools.Excel namespace, which further more requires Microsoft.VisualStudio.Tools.Applications.Runtime and System.Windows.Forms) or any other 3rd party library. This library can however only be used with Office 2003 and later, since it utilized the XML file feature introduced in Office 2003.

Features

  • Intuitive styling of cells
  • Cell merging
  • Formulas with easy cell referencing (simply pass the cell object as reference)
  • Supports multiple worksheets
  • Fast writing using a wrapper around XmlWriter
  • Supports "Open with Excel" from browser – using a small hack feature
  • Abstract HttpHandler supporting Gzip compresion


To-do

  • ASP.NET server control/designer support
  • And much more…

Latest version

Version 0.3.0 released on 2007-08-15:

Source download

Binary download

Release post

History

Version Download Release post Date
0.2.0 source / binary post 2007-07-30
0.1.0 source / binary post 2007-07-21

Usage

Veggerby.Excel uses a simple, intuitive object model to create an Excel sheet. In much the same way as one would construct a ASP.NET Table you add rows, and cells one by one.

ExcelCell c1 = new ExcelCell(2);
c1.Style.ID = "Test";
c1.Style.Alignment.Horizontal = ExcelXmlAlignment.Right;
c1.Style.Font.FontName = "Courier New";
c1.Style.NumberFormatString = "0.0000";
c1.MergeAcross = 1;

ExcelCell c2 = new ExcelCell(12);
c2.MergeDown = 1;
c2.Style.Fill.Color = "#00cc00";
c2.Style.Fill.Pattern = ExcelFillPattern.Gray0625Pct;
c2.Style.Fill.PatternColor = "#ff0000";

ExcelCell c3 = new ExcelCell(4);
c3.ColSpan = 6;

ExcelCell c4 = new ExcelCell("1-2-3");
c4.RowSpan = 6;

ExcelCell c5 = new ExcelCell("Test");
c5.ColSpan = 2;
c5.RowSpan = 2;

ExcelWorksheet sheet;
ExcelWorkbook wkb = new ExcelWorkbook(
    sheet = new ExcelWorksheet(
        new ExcelRow(
            c2,
            c5,
            c4
        ),
        new ExcelRow(
            new ExcelCell("Abe"),
            c3
        ),
        new ExcelRow(
            c1,
            new ExcelFormula("=({0}+1+{1})-{2}*{3}", c1, 10, c2, c3)
        )
    )
);
sheet.Style.Font.Color = "#ff0000";
sheet.Columns[2].Style.ID = "Column";
sheet.Columns[2].Style.Border.LineStyle = ExcelLineStyle.Solid;
sheet.Rows[1].Style.Font.Color = "#0000ff";
sheet.Columns[2].Style.Border.Left.Color = "#00ff00";
sheet.Columns[2].Style.Border.Right.LineStyle = ExcelLineStyle.Dotted;
sheet.Columns[2].Style.Border.Top.Color = "#0000ff";
sheet.Columns[2].Style.Border.Bottom.Color = "#0000ff";

c5.Style.Font.Bold = true;
c4.Style.Font.Bold = true;

wkb.Encoding = Encoding.UTF8;
wkb.Settings.Indent = true;
wkb.Settings.IndentChars = "    ";
wkb.Save(@"e:\test.xml");

One Response to “Veggerby.Excel”

  1. Jose CortezNo Gravatar Says:
    October 9th, 2008 at 18:43

    Do You have this code for vb.net?

Leave a Reply

Icons by N.Design Studio. Designed By Ben Swift. Powered by WordPress, Search Optimization and Free WordPress Themes
Entries RSS Comments RSS Log in