2013-11-26 38 views
1
namespace WordDocument 
{ 
public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { CreateDocument(); 

    } 
    private void CreateDocument() 
    { 
     Microsoft.Office.Interop.Word.Application winword = new Microsoft.Office.Interop.Word.Application(); 

     winword.Visible = true; 

     object missing = System.Reflection.Missing.Value; 

     Microsoft.Office.Interop.Word.Document document = winword.Documents.Add(ref missing, ref missing, ref missing, ref missing); 

     document.Content.SetRange(0, 0); 
     document.Content.Text = "SALE DEED OF THE IMMOVABLE PROPERTY BEING FLAT NO. " + textBox1.Text + " ON THE " + textBox2.Text + " Floor IN THE SCHEME KNOWN AS '" + textBox3.Text + "' FOR Rs. " + textBox4.Text + "-00. (Rs. " + textBox5.Text + " Only)." + Environment.NewLine; 
     document.Content.Font.Name = "Arial"; 
     document.Content.Bold = 1; 
     document.Content.Font.Size = 13; 
     document.Content.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphJustify; 

     Microsoft.Office.Interop.Word.Paragraph para4 = document.Content.Paragraphs.Add(ref missing); 
     para4.Range.Text = "  Resi at- " + textBox11.Text + " :Vadodara."; 
     para4.Range.Font.Name = "Arial"; 
     para4.Range.Font.Size = 13; 
     para4.Range.Font.Bold = 0; 
     object objStart2 = para3.Range.Text.IndexOf("V"); 
     object objEnd2 = para3.Range.Start + para3.Range.Text.IndexOf("."); 

     Microsoft.Office.Interop.Word.Range rngBold2 = document.Range(ref objStart2, ref objEnd2); 
     rngBold2.Bold = 1; 
     para4.Range.InsertParagraphAfter(); 

回答

0

你可以試試這個....

private void InsertMultiFormatParagraph(string psText, int piSize, int piSpaceAfter = 10)  
{ 
    Word.Paragraph para = mdocWord.Content.Paragraphs.Add(ref mobjMissing); 

    para.Range.Text = psText; 
    // Explicitly set this to "not bold" 
    para.Range.Font.Bold = 0; 
    para.Range.Font.Size = piSize; 
    para.Format.SpaceAfter = piSpaceAfter; 

    object objStart = para.Range.Start; 
    object objEnd = para.Range.Start + psText.IndexOf(":"); 

    Word.Range rngBold = mdocWord.Range(ref objStart, ref objEnd); 
    rngBold.Bold = 1; 

    para.Range.InsertParagraphAfter(); 
} 
相關問題