Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Sep 17, 2008 08:16 AM by suthish nair
Member
61 Points
97 Posts
Sep 15, 2008 10:31 AM|LINK
Hi
I want to export the data ffrom sql server and format it to a word document.Can this be done without using any third party
tools in C# 3.5 ????If yes ,pls let me know how to do it along with references
Its urgent
Thanks and Regards
459 Points
127 Posts
Sep 15, 2008 11:48 AM|LINK
You can write the data in the word document using namespaces
Microsoft.office.interop.word,
Microsoft.office.core
Application class
read these link for your reference
http://www.codeproject.com/KB/aspnet/wordapplication.aspx
http://www.codeproject.com/KB/aspnet/Word_Template_Programming.aspx
All-Star
15176 Points
3304 Posts
Sep 15, 2008 12:25 PM|LINK
Here just an example, you need to work on it...
using
using System.Data;
public string ExportToDoc(string filename, DataSet dsInput) { string sFlag = "Error"; try { if (filename.Trim() != "" && dsInput.Tables[0].Rows.Count != 0) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Charset = ""; HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache); HttpContext.Current.Response.ContentType = "application/vnd.word"; HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + filename + ".doc"); System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite); System.Web.UI.WebControls.DataGrid dgDummy = new System.Web.UI.WebControls.DataGrid(); dgDummy.DataSource = dsInput.Tables[0]; dgDummy.DataBind(); dgDummy.RenderControl(htmlWrite); HttpContext.Current.Response.Write(stringWrite.ToString()); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); dgDummy.Dispose(); dsInput.Clear(); dsInput.Dispose(); sFlag = "Success"; } return sFlag; } catch (Exception) { return sFlag; } }
Sep 16, 2008 05:55 AM|LINK
Actually i need to convert the xml data into MS-WORD nd MS-EXCEL nd PDF.
I have browsed through many sites but not able to get the basic understanding.
Any help would be grateful.
Sep 16, 2008 06:46 AM|LINK
This can be done by loading xml file into dataset, Dataset.ReadXml(XMLPath) and use the given function to generate files.
For PDF, you need to use some third party tools.
Search through the Forums, you will get lotz of examples for word, excel and pdf.
Sep 17, 2008 04:36 AM|LINK
With the above code iam able to convert the Xml data and display the data in the word in table format only.
But if i want to display data in word with more features for fromatting like having paragraphs......how to go abut it????/
Sep 17, 2008 06:38 AM|LINK
Can anyone give an overview of WordML which i think is used for converting xml to word...ami right.
If possible pls provide samples using c#..pls help ...its urgent.
Sep 17, 2008 08:16 AM|LINK
Hi,
Till I never used WordML, but got some sample links (you can also find on web).
http://rep.oio.dk/Microsoft.com/officeschemas/wordprocessingml_article.htm
http://www.xmlw.ie/aboutxml/wordml.htm
One more thing you can do is, convert all your xml data (lotz of examples www.w3schools.com XML Section) into an html file with stylesheet
then transfer into a doc file.
bklight
Member
61 Points
97 Posts
Export data to MS word in C# 3.5
Sep 15, 2008 10:31 AM|LINK
Hi
I want to export the data ffrom sql server and format it to a word document.Can this be done without using any third party
tools in C# 3.5 ????If yes ,pls let me know how to do it along with references
Its urgent
Thanks and Regards
devadkarrame...
Member
459 Points
127 Posts
Re: Export data to MS word in C# 3.5
Sep 15, 2008 11:48 AM|LINK
You can write the data in the word document using namespaces
Microsoft.office.interop.word,
Microsoft.office.core
Application class
read these link for your reference
http://www.codeproject.com/KB/aspnet/wordapplication.aspx
http://www.codeproject.com/KB/aspnet/Word_Template_Programming.aspx
Dotnet Developer
Dont forget to click “Mark as Answer” on the post that helped you.
This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers
suthish nair
All-Star
15176 Points
3304 Posts
Re: Export data to MS word in C# 3.5
Sep 15, 2008 12:25 PM|LINK
Here just an example, you need to work on it...
using
System;using System.Data;
using
System.IO;using
System.Web.UI.WebControls;public string ExportToDoc(string filename, DataSet dsInput) { string sFlag = "Error"; try { if (filename.Trim() != "" && dsInput.Tables[0].Rows.Count != 0) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Charset = ""; HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache); HttpContext.Current.Response.ContentType = "application/vnd.word"; HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + filename + ".doc"); System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite); System.Web.UI.WebControls.DataGrid dgDummy = new System.Web.UI.WebControls.DataGrid(); dgDummy.DataSource = dsInput.Tables[0]; dgDummy.DataBind(); dgDummy.RenderControl(htmlWrite); HttpContext.Current.Response.Write(stringWrite.ToString()); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); dgDummy.Dispose(); dsInput.Clear(); dsInput.Dispose(); sFlag = "Success"; } return sFlag; } catch (Exception) { return sFlag; } }My Blog
bklight
Member
61 Points
97 Posts
Re: Export data to MS word in C# 3.5
Sep 16, 2008 05:55 AM|LINK
Hi
Actually i need to convert the xml data into MS-WORD nd MS-EXCEL nd PDF.
I have browsed through many sites but not able to get the basic understanding.
Any help would be grateful.
Thanks and Regards
suthish nair
All-Star
15176 Points
3304 Posts
Re: Export data to MS word in C# 3.5
Sep 16, 2008 06:46 AM|LINK
This can be done by loading xml file into dataset, Dataset.ReadXml(XMLPath) and use the given function to generate files.
For PDF, you need to use some third party tools.
Search through the Forums, you will get lotz of examples for word, excel and pdf.
My Blog
bklight
Member
61 Points
97 Posts
Re: Export data to MS word in C# 3.5
Sep 17, 2008 04:36 AM|LINK
With the above code iam able to convert the Xml data and display the data in the word in table format only.
But if i want to display data in word with more features for fromatting like having paragraphs......how to go abut it????/
bklight
Member
61 Points
97 Posts
Re: Export data to MS word in C# 3.5
Sep 17, 2008 06:38 AM|LINK
Can anyone give an overview of WordML which i think is used for converting xml to word...ami right.
If possible pls provide samples using c#..pls help ...its urgent.
suthish nair
All-Star
15176 Points
3304 Posts
Re: Export data to MS word in C# 3.5
Sep 17, 2008 08:16 AM|LINK
Hi,
Till I never used WordML, but got some sample links (you can also find on web).
http://rep.oio.dk/Microsoft.com/officeschemas/wordprocessingml_article.htm
http://www.xmlw.ie/aboutxml/wordml.htm
One more thing you can do is, convert all your xml data (lotz of examples www.w3schools.com XML Section) into an html file with stylesheet
then transfer into a doc file.
My Blog