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("<center>" + form + "</center>");
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!