I am having a windows application form (C#.net) which i want to export to word on export button click.So how to do it.
How to export the windows form to .doc/.docx
Hi,
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sanjay KumarRank #561 · 4.3K reputationPosted Oct 21, 2013, 4:06 AM EDT
http://www.codeproject.com/Articles/507068/Microsoft-Interop-API-to-convert-the-doc-docx-dot
Sanjay KumarRank #561 · 4.3K reputationPosted Oct 21, 2013, 4:13 AM EDT
try this
http://shailajachowdarydotnet.blogspot.in/2012/05/download-data-in-datagridview-to-word.html
Ring ZhongRank #6,843 · 255 reputationPosted Oct 22, 2013, 7:04 PM EDT
private void btnExportToWord_Click(object sender, EventArgs e)
{
Spire.DataExport.RTF.RTFExport rtfExport = new Spire.DataExport.RTF.RTFExport();
rtfExport.DataSource = Spire.DataExport.Common.ExportSource.DataTable;
rtfExport.DataTable = this.dataGridView1.DataSource as DataTable;
rtfExport.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
RTFStyle rtfStyle = new RTFStyle();
rtfStyle.FontColor = Color.Blue;
rtfStyle.BackgroundColor = Color.LightGreen;
rtfExport.RTFOptions.DataStyle = rtfStyle;
rtfExport.FileName=@"..\..\ToWord.doc";
rtfExport.SaveToFile();
}
source: How to Export DataTable to Word in c#
Neboja12 reputationPosted Jul 18, 2014, 12:53 AM EDT
Hi, it is hard to guess what you are actually looking for, you need to be more specific.
Do you want to screen shot your WinForms app and insert that image into a new document, or do you want to translate the controls used in your form into a document controls, or something else?
Nevertheless when I have a .DOCX related requirement in .NET I use this Word library written in C# so that I can avoid hassle with unmanaged word automation in C# which comes with MS Office.
For the first scenario here is how you can create your word documents in .NET, documents will only include the screenshots:
private void btnExport_Click(object sender, EventArgs e)
{
var bmp = new Bitmap(this.Width, this.Height);
this.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
using (var image = new MemoryStream())
{
bmp.Save(image, ImageFormat.Png);
var doc = new DocumentModel();
doc.Sections.Add(
new Section(doc,
new Paragraph(doc,
new Picture(doc, image))));
doc.Save("Document.docx");
}
}
For the second scenario I believe it would be quite some task to write this mapping, so as an alternative I would advise you to check out a mail merging feature of word files in C#.