asp.net generation word__.net

Source: Internet
Author: User
Tags save file
<SUMMARY></SUMMARY>
Word Application Object
///
Private Microsoft.Office.Interop.Word.Application _wordapplication;

<SUMMARY></SUMMARY>
Word file Object
///
Private Microsoft.Office.Interop.Word.Document _worddocument;
<SUMMARY></SUMMARY>
Create a document
///
public void Createaword ()
{
Instantiate a Word Application object
This._wordapplication = new Microsoft.Office.Interop.Word.ApplicationClass ();
Object mynothing = System.Reflection.Missing.Value;

This._worddocument = This._wordapplication.documents.add (ref mynothing, ref mynothing, ref mynothing, ref myNothing);
}
<SUMMARY></SUMMARY>
Add header
///
<param name= "Ppageheader"/>
public void Setpageheader (string ppageheader)
{
Add header
This._wordapplication.activewindow.view.type =microsoft. Office. Interop. Word.WdViewType.wdOutlineView;
This._wordapplication.activewindow.view.seekview = Microsoft.Office.Interop.Word.WdSeekView.wdSeekPrimaryHeader;
This._wordapplication.activewindow.activepane.selection.insertafter (Ppageheader);
To set center alignment
This._wordapplication.selection.paragraphformat.alignment =microsoft. Office. Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
Jump out of header settings
This._wordapplication.activewindow.view.seekview = Microsoft.Office.Interop.Word.WdSeekView.wdSeekMainDocument;
}
<SUMMARY></SUMMARY>
Insert text
///
<param name= "Ptext"/> Text information
<param name= "pfontsize"/> Font size
<param name= "pfontcolor"/> Font Color
<param name= "Pfontbold"/> Font Bold
<param name= "ptextalignment"/> Direction
public void InsertText (string ptext, int pfontsize, Microsoft.Office.Interop.Word.WdColor pfontcolor, int pfontbold, Microsoft.Office.Interop.Word.WdParagraphAlignment ptextalignment)
{
Set font style and orientation
This._wordapplication.application.selection.font.size = pfontsize;
This._wordapplication.application.selection.font.bold = Pfontbold;
This._wordapplication.application.selection.font.color= Pfontcolor;
This._wordapplication.application.selection.paragraphformat.alignment = ptextalignment;
This._wordapplication.application.selection.typetext (Ptext);
}


<SUMMARY></SUMMARY>
Line Wrap
///
public void newline ()
{
Line Wrap
This._wordapplication.application.selection.typeparagraph ();
}
<SUMMARY></SUMMARY>
Insert a picture
///
<param name= "Ppicturefilename"/>
public void InsertPicture (string ppicturefilename)
{
Object mynothing = System.Reflection.Missing.Value;
Center Picture Display
This._wordapplication.selection.paragraphformat.alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
This._wordapplication.application.selection.inlineshapes.addpicture (Ppicturefilename, ref myNothing, ref myNothing , ref mynothing);
}
<SUMMARY></SUMMARY>
Save File
///
<param name= "Pfilename"/> Saved file name
public void Saveword (string pfilename)
{
Object mynothing = System.Reflection.Missing.Value;
Object myfilename = Pfilename;
Object Mywordformatdocument =microsoft. Office. Interop. Word.WdSaveFormat.wdFormatDocument;
Object MYLOCKD = false;
Object mypassword = "";
Object myaddto = true;
Try
{
This._worddocument.saveas (ref myfilename, ref mywordformatdocument, ref MYLOCKD, ref mypassword, ref myaddto, ref MYPASSW Ord
Ref MYLOCKD, ref MYLOCKD, ref MYLOCKD, ref MYLOCKD, ref mynothing, ref mynothing, ref mynothing,
Ref mynothing, ref mynothing, ref mynothing);
}
Catch
{
throw new Exception ("Export Word document failed!");
}
}
}
Related Article

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.