Hi experts, I need to print my gridview into a word document which is Read Only.
I have found two methods. The first one is to create a word document that is read-only.
Word.ApplicationClass oWordApp = new Word.ApplicationClass();
object missing = System.Reflection.Missing.Value;
object readOnly = true;
object fileName = (Server.MapPath("Docs/" + projectID + "/EP/") + projectID + "_endpack.doc");
object isVisible = true;
Object start = Type.Missing;
object Missing = Type.Missing;
Object end = Type.Missing;
Word.Document oWordDoc = oWordApp.Documents.Add(ref missing, ref missing,ref missing, ref isVisible);
oWordDoc.Activate();
oWordApp.Selection.TypeText(form);
oWordApp.Selection.TypeParagraph();
oWordDoc.SaveAs(ref fileName, ref missing, ref missing, ref missing, ref
missing, ref missing,
ref readOnly, ref missing, ref missing, ref missing, ref missing, ref
missing, ref missing,
ref missing, ref missing, ref missing);
oWordApp.Application.Quit(ref missing, ref missing, ref missing);
The second method is to print the gridview into the word.
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=form.doc");
Response.Charset = "";
Response.ContentType = "application/vnd.word";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
htmlWrite.Write("
" + form + " ");htmlWrite.WriteBreak(); htmlWrite.WriteBreak();
GridView1.RenderControl(htmlWrite);
htmlWrite.WriteBreak();
gv_retrieve2.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
Both methods are working perflectly separately.
But how can I used Word.ApplicationClass to write the gridview that I have or to use Response to set the Word document to Read-Only?
Please help. THanks!
ArshadPosted Dec 31, 2007, 12:04 AM
Hi first u will have to add one word file in ur project solution then create the resource file for that word document the run one Thread in the page of perticular event and try to impliment ur code from word to DataGrid.its similar like what u have given.just try it
I hope u will get that
Regards
Arshad