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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
NebojaPosted Jul 18, 2014, 4:53 AM
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#.
Ring ZhongPosted Oct 22, 2013, 11:04 PM
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#
Sanjay KumarPosted Oct 21, 2013, 8:13 AM
try this
http://shailajachowdarydotnet.blogspot.in/2012/05/download-data-in-datagridview-to-word.html
Sanjay KumarPosted Oct 21, 2013, 8:06 AM
http://www.codeproject.com/Articles/507068/Microsoft-Interop-API-to-convert-the-doc-docx-dot