Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

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.
Documentation.zip
ExcelXml.zip
ExcelXml
ExcelXmlTest
bin
Debug
ExcelXmlTest.exe
ExcelXmlTest.vshost.exe
Yogesh.ExcelXml.dll
Yogesh.Extensions.dll
obj
Debug
TempPE
Properties
Yogesh.ExcelXml
bin
Debug
Yogesh.ExcelXml.dll
Yogesh.Extensions.dll
Help
Documentation.chm
LastBuild.log
obj
Debug
Refactor
TempPE
Release
Properties
Extensions.zip
Extensions
Yogesh.Extensions
bin
Debug
Yogesh.Extensions.dll
Properties
Yogesh.Extensions.zip
using System.Xml;
using Yogesh.Extensions;

namespace Yogesh.ExcelXml
{
	/// <summary>
	/// Gets or sets document properties
	/// </summary>
	public class DocumentProperties
	{
		#region Public Properties
		/// <summary>
		/// Gets or sets the author of the workbook
		/// </summary>
		public string Author { get; set; }
		/// <summary>
		/// Gets or sets the last author of the workbook
		/// </summary>
		public string LastAuthor { get; set; }
		/// <summary>
		/// Gets or sets the manager of the workbook
		/// </summary>
		public string Manager { get; set; }
		/// <summary>
		/// Gets or sets the company of the workbook
		/// </summary>
		public string Company { get; set; }
		/// <summary>
		/// Gets or sets the subject of the workbook
		/// </summary>
		public string Subject { get; set; }
		/// <summary>
		/// Gets or sets the title of the workbook
		/// </summary>
		public string Title { get; set; }
		#endregion

		#region Constructor
		/// <summary>
		/// Creates an instance with empty document properties
		/// </summary>
		public DocumentProperties()
		{
			Author = "";
			LastAuthor = "";
			Manager = "";
			Company = "";
			Subject = "";
			Title = "";
		}
		#endregion

		#region Export
		internal void Export(XmlWriter writer)
		{
			// DocumentProperties
			writer.WriteStartElement("", "DocumentProperties", "urn:schemas-microsoft-com:office:office");

			if (!Author.IsNullOrEmpty())
				writer.WriteElementString("Author", Author);
			if (!LastAuthor.IsNullOrEmpty())
				writer.WriteElementString("LastAuthor", LastAuthor);
			if (!Manager.IsNullOrEmpty())
				writer.WriteElementString("Manager", Manager);
			if (!Company.IsNullOrEmpty())
				writer.WriteElementString("Company", Company);
			if (!Subject.IsNullOrEmpty())
				writer.WriteElementString("Subject", Subject);
			if (!Title.IsNullOrEmpty())
				writer.WriteElementString("Title", Title);
			writer.WriteEndElement();
		}
		#endregion

		#region Import
		internal void Import(XmlReader reader)
		{
			while (reader.Read() && !(reader.Name == "DocumentProperties" && reader.NodeType == XmlNodeType.EndElement))
			{
				if (reader.NodeType == XmlNodeType.Element)
				{
					switch (reader.Name)
					{
						// Document Properties
						case "Author":
							{
								if (reader.IsEmptyElement)
									continue;

								reader.Read();
								if (reader.NodeType == XmlNodeType.Text)
									Author = reader.Value;

								break;
							}
						case "LastAuthor":
							{
								if (reader.IsEmptyElement)
									continue;

								reader.Read();
								if (reader.NodeType == XmlNodeType.Text)
									LastAuthor = reader.Value;

								break;
							}
						case "Manager":
							{
								if (reader.IsEmptyElement)
									continue;

								reader.Read();
								if (reader.NodeType == XmlNodeType.Text)
									Manager = reader.Value;

								break;
							}
						case "Company":
							{
								if (reader.IsEmptyElement)
									continue;

								reader.Read();
								if (reader.NodeType == XmlNodeType.Text)
									Company = reader.Value;

								break;
							}
						case "Subject":
							{
								if (reader.IsEmptyElement)
									continue;

								reader.Read();
								if (reader.NodeType == XmlNodeType.Text)
									Subject = reader.Value;

								break;
							}
						case "Title":
							{
								if (reader.IsEmptyElement)
									continue;

								reader.Read();
								if (reader.NodeType == XmlNodeType.Text)
									Title = reader.Value;

								break;
							}
					}
				}
			}
		}
		#endregion
	}
}

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)

Share

About the Author


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