McKelt.com

Remembering Thoughts

 

Recent comments

Authors

Categories


Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

Winforms export datatable to excel without COM+

Simple export of a datatable to excel without using COM+

Excel will ask if you want to open this as 'An XML List'

SaveFileDialog fileDialog = new SaveFileDialog();
fileDialog.Filter = "Excel files (*.xls)|*.xls";
fileDialog.FileName = "My_File_Name.xls";
fileDialog.ShowDialog();
DataTable dt = GetFilteredDataTable(DisplayedWorkbookView.EmployeesByFocusGroup);
using (FileStream fs = (FileStream)fileDialog.OpenFile())
{
using (StreamWriter sw = new StreamWriter(fs))
{
sw.Write("<?xml version=\"1.0\" standalone=\"yes\"?>");
dt.WriteXml(sw, XmlWriteMode.IgnoreSchema);
sw.Close();
}
fs.Close();
}

Posted by chris on Tuesday, July 22, 2008 5:02 PM
Permalink | Comments (2) | Post RSSRSS comment feed

Comments

Jim United Kingdom

Sunday, July 12, 2009 8:37 AM

Jim

Nice blog, just bookmarked it for later reference

Pierre Cardin United States

Wednesday, July 15, 2009 12:34 AM

Pierre Cardin

I like your blog curently we are looking for a part time article writer would you be interested?

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading