C # operate word bookmarks

Source: Internet
Author: User
Word. Application app = new Word. Application ();
// Template File
String TemplateFile = @ "D: \ lin \ Invoice.doc ";
// Generate a new file with a template Style
String FileName = @ "D: \ lin \" + DateTime. Now. ToString ("yyyyMMddHHmmssfffffff") + ". doc ";
String Fname = DateTime. Now. ToString ("yyyyMMddHHmmssfffffff") + ". doc ";
// FileName = Server. MapPath ("~ /UpLoad/TestWord/"+ Fname );
// Copy the template file to the new file
File. Copy (TemplateFile, FileName );
Word. Document doc = new Word. Document ();
Object Obj_FileName = FileName;
Object Visible = false;
Object ReadOnly = false;
Object missing = System. Reflection. Missing. Value;
// Open the file
Doc = app. Documents. Open (ref Obj_FileName, ref missing, ref ReadOnly, ref missing,
Ref missing,
Ref missing, ref Visible,
Ref missing,
Ref missing );
Doc. Activate ();

Foreach (Word. Bookmark bm in doc. Bookmarks)
{
If (bm. Name = "BookMark_Date ")
{
Bm. Select ();
Bm. Range. Text = "2008"; // ViewState ["FK_ProdurcePlanID"]. ToString ();
}
// Else if (bm. Name = "class ")
//{
// Bm. Select ();
// Bm. Range. Text = ViewState ["_ class"]. ToString ();
//}

}
Object IsSave = true;
Doc. Close (ref IsSave, ref missing, ref missing );

Response. Write ("<script language = 'javascript '> alert ('word generation successful! '); </Script> ");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.