Click here to Skip to main content
15,895,784 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 653.2K   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
{
    public class Cell
    {
        private ExcelDocument document;
        private CellInfo cellInfo;

        internal Cell(int row, int column, ExcelDocument document)
        {
            this.document = document;
            cellInfo = document.GetCellInfo(row, column);
        }

        internal ExcelDocument Document
        {
            get { return this.document; }
        }

        public object Value
        {
            get { return cellInfo.Value; }
            set { cellInfo.Value = value; }
        }

        public string Format
        {
            get { return cellInfo.Format; }
            set
            {
                cellInfo.Format = value;
                if (!document.Formats.Contains(value))
                    document.Formats.Add(value);
            }
        }

        public ExcelColor BackColor
        {
            get { return cellInfo.BackColor; }
            set { cellInfo.BackColor = value; }
        }

        public ExcelColor ForeColor
        {
            get { return cellInfo.ForeColor; }
            set { cellInfo.ForeColor = value; }
        }

        public Font Font
        {
            get { return cellInfo.Font; }
            set { cellInfo.Font = value; }
        }

        public Alignment Alignment
        {
            get { return cellInfo.Alignment; }
            set { cellInfo.Alignment = value; }
        }

        public int Row
        {
            get { return cellInfo.Row; }
        }

        public int Column
        {
            get { return cellInfo.Column; }
        }
    }
}

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