Click here to Skip to main content
12,946,658 members (52,250 online)
Click here to Skip to main content

Stats

435.2K views
17.8K downloads
352 bookmarked
Posted 15 Jan 2008

A Very Easy to Use Excel XML Import-Export Library

, 25 Nov 2008 CPOL
Import export library for the Excel XML format, which reduces a programmer's work to the bare minimum.
using System;
using System.Collections.Generic;

namespace Yogesh.ExcelXml
{
	/// <summary>
	/// Represents a strongly typed list of cells that can be accessed by index.
	/// </summary>
	public class CellCollection : List<Cell>
	{
		/// <summary>
		/// Adds a range to the collection
		/// </summary>
		/// <param name="range">Range to add</param>
		public void Add(Range range)
		{
			foreach (Cell cell in range)
				Add(cell);
		}

		/// <summary>
		/// Adds a worksheet to the collection
		/// </summary>
		/// <param name="ws">Worksheet to add</param>
		public void Add(Worksheet ws)
		{
			foreach (Cell cell in ws)
				Add(cell);
		}

		/// <summary>
		/// Adds a row to the collection
		/// </summary>
		/// <param name="row">Row to add</param>
		public void Add(Row row)
		{
			foreach (Cell cell in row)
				Add(cell);
		}

		/// <summary>
		/// Adds a single cell to the collection if it matches the filter condition
		/// </summary>
		/// <param name="cell">Cell to add</param>
		/// <param name="filterCondition">Filter predicate</param>
		public void Add(Cell cell, Predicate<Cell> filterCondition)
		{
			if (filterCondition(cell))
				Add(cell);
		}

		/// <summary>
		/// Adds a range to the collection if it matches the filter condition
		/// </summary>
		/// <param name="range">Range to add</param>
		/// <param name="filterCondition">Filter predicate</param>
		public void Add(Range range, Predicate<Cell> filterCondition)
		{
			foreach (Cell cell in range)
			{
				if (filterCondition(cell))
					Add(cell);
			}
		}

		/// <summary>
		/// Adds a worksheet to the collection if it matches the filter condition
		/// </summary>
		/// <param name="ws">Worksheet to add</param>
		/// <param name="filterCondition">Filter predicate</param>
		public void Add(Worksheet ws, Predicate<Cell> filterCondition)
		{
			foreach (Cell cell in ws)
			{
				if (filterCondition(cell))
					Add(cell);
			}
		}

		/// <summary>
		/// Adds a row to the collection if it matches the filter condition
		/// </summary>
		/// <param name="row">Row to add</param>
		/// <param name="filterCondition">Filter predicate</param>
		public void Add(Row row, Predicate<Cell> filterCondition)
		{
			foreach (Cell cell in row)
			{
				if (filterCondition(cell))
					Add(cell);
			}
		}
	}
}

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


You may also be interested in...

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