Click here to Skip to main content
13,050,358 members (141,607 online)
Click here to Skip to main content


352 bookmarked
Posted 15 Jan 2008

A Very Easy to Use Excel XML Import-Export Library

, 25 Nov 2008
Import export library for the Excel XML format, which reduces a programmer's work to the bare minimum.
using System;
using System.Globalization;
using System.Xml;
using Yogesh.Extensions;

namespace Yogesh.ExcelXml
	/// <summary>
	/// Column class represents a column properties of a single column in a worksheet
	/// </summary>
	/// <remarks>
	/// Column class represents a column properties of a single column in a worksheet.
	/// <para>You cannot directly declare a instance of a column class from your code by using
	/// <c>new</c> keyword. The only way to access a column is to retrieve it from
	/// a worksheet by using the <see cref="Yogesh.ExcelXml.Worksheet.Columns"/>
	/// method of the <see cref="Yogesh.ExcelXml.Worksheet"/> class.</para>
	/// </remarks>
	public class Column
		#region Private and Internal fields
		private ExcelXmlWorkbook ParentBook;
		private string styleID;

		#region Public Properties
		/// <summary>
		/// Gets or sets the default width of the column
		/// </summary>
		public double Width { get; set; }

		/// <summary>
		/// Gets or sets the hidden status of the column
		/// </summary>
		public bool Hidden { get; set; }

		/// <summary>
		/// Gets or sets the <see cref="Yogesh.ExcelXml.XmlStyle"/> reference of the column.
		/// <para>Setting this option only affects cells which are added after this value is set. The 
		/// cells which are added in the same column retain their original style settings.</para>
		/// </summary>
		public XmlStyle Style
				return ParentBook.GetStyleByID(styleID);
				styleID = ParentBook.AddStyle(value);

		#region Constructor
		internal Column(Worksheet parent)
			if (parent == null)
				throw new ArgumentNullException("parent");

			ParentBook = parent.ParentBook;

		#region Export
		internal void Export(XmlWriter writer)

			if (Width > 0)
				writer.WriteAttributeString("ss", "Width", null, Width.ToString(

			if (Hidden)
				writer.WriteAttributeString("ss", "Hidden", null, "1");
				writer.WriteAttributeString("ss", "AutoFitWidth", null, "0");

			// Has style? If yes, we only need to write the style if default line
			// style is not same as this one...
			if (!Style.ID.IsNullOrEmpty() && Style.ID != "Default")
				writer.WriteAttributeString("ss", "StyleID", null, Style.ID);


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.


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


About the Author

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 26 Nov 2008
Article Copyright 2008 by Yogesh Jagota
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid