Link generates fixed-format Word documents, such as analysis reports. You can first create a fixed-format document template to mark the locations where data or other things need to be dynamically inserted as bookmarks, use the web page program to replace the bookmarks with data. protected void button_click (Object sender, eventargs E)
{
Object nothing = system. reflection. Missing. value;
// Obtain the path for saving the Word file
Object filename = @ saveas. text;
Object dotname = @ "C: \ test. Dot ";
// Create a component object named wordapp
Microsoft. Office. InterOP. Word. Application wordapp = new Microsoft. Office. InterOP. Word. applicationclass ();
// Create a document object named worddoc
Microsoft. office. interOP. word. document worddoc = wordapp. documents. open (ref dotname, ref nothing, ref nothing, ref nothing, ref nothing );
// Microsoft. Office. InterOP. Word. Document worddoc = wordapp. Documents. Add (ref nothing, ref nothing );
Foreach (bookmark BM in worddoc. bookmarks)
{
If (BM. Name = "value ")
{
BM. Select ();
BM. range. Text = textbox2.text;
}
Else if (BM. Name = "itemname ")
{
BM. Select ();
BM. range. Text = textbox1.text;
}
Else if (BM. Name = "fcstvalue ")
{
BM. Select ();
BM. range. Text = textbox3.text;
}
Else if (BM. Name = "modelname ")
{
BM. Select ();
BM. range. Text = textbox4.text;
}
Else if (BM. Name = "increaserate ")
{
BM. Select ();
BM. range. Text = textbox5.text;
}
}
// Save the content of the worddoc object as a doc object
Worddoc. saveas (ref filename, ref nothing, ref nothing, ref nothing, ref nothing );
// Close the worddoc Document Object
Worddoc. Close (ref nothing, ref nothing, ref nothing );
// Close the wordapp Component Object
Wordapp. Quit (ref nothing, ref nothing, ref nothing );
// Return results
Result. TEXT = "document path: <a href = '" + saveas. text + "'>" + saveas. text + "</a> (click the link to View Details) <br/> result: Success! ";
}
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.