Click here to Skip to main content
15,886,019 members
Articles / Programming Languages / C#

Generate Excel files without using Microsoft Excel

Rate me:
Please Sign up or sign in to vote.
4.80/5 (93 votes)
22 Jun 2011CPOL2 min read 648.6K   24.3K   269  
A C# class to create Excel files without requiring Microsoft Excel.
// C# Excel Writer library v2.0
// by Serhiy Perevoznyk, 2008-2011

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace XLSExportDemo
{
    internal class CellInfo
    {
        private object value;

        public CellInfo(ExcelDocument document)
        {
            BackColor = ExcelColor.Automatic;
            ForeColor = ExcelColor.Automatic;
            Font = document.DefaultFont;
            this.Document = document;
        }

        internal byte FXIndex { get; set; }
        public ExcelDocument Document { get; set; }

        public object Value
        {
            get { return value; }
            set
            {
                this.value = value;
                if (value is DateTime)
                    this.Format = Document.Formats[15];
            }
        }
        
        public string Format { get; set; }
        public ExcelColor BackColor { get; set; }
        public ExcelColor ForeColor { get; set; }
        public int Row { get; set; }
        public int Column { get; set; }
        public Font Font { get; set; }
        public Alignment Alignment { get; set; }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Belgium Belgium
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions