Click here to Skip to main content
15,886,199 members
Articles / Productivity Apps and Services / Microsoft Office

Exporting a DataGridView to an Excel/PDF/image file by using Reporting Services report generation

Rate me:
Please Sign up or sign in to vote.
4.94/5 (53 votes)
20 Aug 2008LGPL37 min read 379.7K   29K   248  
ReportExporters is a library for easy exporting of a DataGridView to Excel/PDF/image file types by using Reporting Services report generation.
using System;
using System.Collections.Generic;
using System.Text;
using ReportExporters.Common.Model.Style;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace ReportExporters.Common.Model.DataColumns
{
	public class ReportDataColumn : ReportColumn
	{
		private ReportDataColumn()
		{
			templateFormat = string.Empty;
			
			this.HeaderStyle = new ReportStyle();
			this.DefaultCellStyle = new ReportTableItemStyle();

			this.HeaderCellViewType = new CellViewText();
			this.DataCellViewType = new CellViewText();
		}

		public ReportDataColumn(string _name)
			: this()
		{
			this.name = _name;
		}

		private TypeConverter valueConverter;
		/// <summary>
		/// Custom TypeConverter for converting value at generating report.
		/// </summary>
		public TypeConverter ValueConverter
		{
			get { return valueConverter; }
			set { valueConverter = value; }
		}

		private string templateFormat;
		/// <summary>
		/// Format string which allow to pass one argument 
		/// Like "Image size is {0} Kb"
		/// </summary>
		public string TemplateFormat
		{
			get { return templateFormat; }
			set { templateFormat = value; }
		}

		private string headerText;
		/// <summary>
		/// Text in column header cell
		/// </summary>
		public string HeaderText
		{
			get { return headerText; }
			set { headerText = value; }
		}

		private ReportStyle headerStyle;
		/// <summary>
		/// Style for column header cell
		/// </summary>
		public ReportStyle HeaderStyle
		{
			get { return headerStyle; }
			set { headerStyle = value; }
		}

		private ReportTableItemStyle defaultCellStyle;
		/// <summary>
		/// Style for column item cell
		/// </summary>
		public ReportTableItemStyle DefaultCellStyle
		{
			get { return defaultCellStyle; }
			set { defaultCellStyle = value; }
		}

		private CellViewType headerCellViewType;
		/// <summary>
		/// Type of ReportControl for column header cell
		/// </summary>
		public CellViewType HeaderCellViewType
		{
			get { return headerCellViewType; }
			set { headerCellViewType = value; }
		}

		private CellViewType dataCellViewType;
		/// <summary>
		/// Type of ReportControl for column item cell
		/// </summary>
		public CellViewType DataCellViewType
		{
			get { return dataCellViewType; }
			set { dataCellViewType = value; }
		}

		private Uri _headerCellHyperlink;
		/// <summary>
		/// Column header cell hyperlink
		/// </summary>
		public Uri HeaderCellHyperlink
		{
			get
			{
				return _headerCellHyperlink;
			}
			set
			{
				_headerCellHyperlink = value;
			}
		}
		
		private ReportHyperlinkColumn _hyperlinkColumn;
		/// <summary>
		/// Column that contains hyperlink for item cell 
		/// </summary>
		public ReportHyperlinkColumn HyperlinkColumn
		{
			get
			{
				return _hyperlinkColumn;
			}
			set
			{
				_hyperlinkColumn = value;
			}
		}
	}


}

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 GNU Lesser General Public License (LGPLv3)


Written By
Software Developer
Poland Poland
I also wrote Online Json Editor & 'Json/Xml to Excel converter'. It exports data to excel in the same way as the ReportExporters library does - plain/hierarchical views.
www.json-xls.com

Comments and Discussions