zoukankan      html  css  js  c++  java
  • Microsoft.Office.Interop.Word 创建word

    先将现有的劳动成功放在这里。有时间在加以完善!

    一、添加页眉


    1. using  System;  
    2. using  System.Collections.Generic;  
    3. using  System.ComponentModel;  
    4. using  System.Data;  
    5. using  System.Linq;  
    6. using  System.Text;  
    7. using  Word = Microsoft.Office.Interop.Word;  
    8. using  System.IO;  
    9. using  System.Reflection;  
    10. using  Microsoft.Office.Interop.Word;  
    11.   
    12.   
    13. namespace  WordCreateDLL  
    14. {  
    15.    public   class  AddHeader  
    16.     {  
    17.         public   static   void  AddSimpleHeader(Application WordApp, string  HeaderText)  
    18.         {  
    19.             //添加页眉   
    20.             WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView;  
    21.             WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader;  
    22.             WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(HeaderText);  
    23.             WordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;//设置左对齐   
    24.             WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument;  
    25.         }  
    26.         public   static   void  AddSimpleHeader(Application WordApp,  string  HeaderText, WdParagraphAlignment wdAlign)  
    27.         {  
    28.             //添加页眉   
    29.             WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView;  
    30.             WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader;  
    31.             WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(HeaderText);  
    32.             //WordApp.Selection.Font.Color = WdColor.wdColorDarkRed;//设置字体颜色   
    33.             WordApp.Selection.ParagraphFormat.Alignment = wdAlign;//设置左对齐   
    34.             WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument;  
    35.         }  
    36.         public   static   void  AddSimpleHeader(Application WordApp,  string  HeaderText, WdParagraphAlignment wdAlign,WdColor fontcolor, float  fontsize)  
    37.         {  
    38.             //添加页眉   
    39.             WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView;  
    40.             WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader;  
    41.             WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(HeaderText);  
    42.             WordApp.Selection.Font.Color =fontcolor;//设置字体颜色   
    43.             WordApp.Selection.Font.Size = fontsize;//设置字体大小   
    44.             WordApp.Selection.ParagraphFormat.Alignment = wdAlign;//设置对齐方式   
    45.             WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument;  
    46.         }  
    47.   
    48.   
    49.     }  
    50. }  
    1. using  
    2. System;   
    3. using System.Collections.Generic;   
    4. using System.ComponentModel;   
    5. using System.Data;   
    6. using System.Linq;   
    7. using System.Text;   
    8. using Word = Microsoft.Office.Interop.Word;   
    9. using System.IO;   
    10. using System.Reflection;   
    11. using Microsoft.Office.Interop.Word;   
    12. namespace WordCreateDLL   
    13. public class AddHeader { public static void  
    14. AddSimpleHeader(Application WordApp,string HeaderText) { //添加页眉   
    15. WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView;   
    16. WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader;   
    17. WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(HeaderText);   
    18. WordApp.Selection.ParagraphFormat.Alignment =   
    19. WdParagraphAlignment.wdAlignParagraphLeft;//设置左对齐   
    20. WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; }   
    21. public static void AddSimpleHeader(Application WordApp, string  
    22. HeaderText, WdParagraphAlignment wdAlign) { //添加页眉   
    23. WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView;   
    24. WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader;   
    25. WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(HeaderText);   
    26. //WordApp.Selection.Font.Color = WdColor.wdColorDarkRed;//设置字体颜色   
    27. WordApp.Selection.ParagraphFormat.Alignment = wdAlign;//设置左对齐   
    28. WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; }   
    29. public static void AddSimpleHeader(Application WordApp, string  
    30. HeaderText, WdParagraphAlignment wdAlign,WdColor fontcolor,float  
    31. fontsize) { //添加页眉 WordApp.ActiveWindow.View.Type =   
    32. WdViewType.wdOutlineView; WordApp.ActiveWindow.View.SeekView =   
    33. WdSeekView.wdSeekPrimaryHeader;   
    34. WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(HeaderText);   
    35. WordApp.Selection.Font.Color =fontcolor;//设置字体颜色   
    36. WordApp.Selection.Font.Size = fontsize;//设置字体大小   
    37. WordApp.Selection.ParagraphFormat.Alignment = wdAlign;//设置对齐方式   
    38. WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; } }   
    39. }  

    二、插入图片


    1. using  System;  
    2. using  System.Collections.Generic;  
    3. using  System.ComponentModel;  
    4. using  System.Data;  
    5. using  System.Linq;  
    6. using  System.Text;  
    7. using  Word = Microsoft.Office.Interop.Word;  
    8. using  System.IO;  
    9. using  System.Reflection;  
    10. using  Microsoft.Office.Interop.Word;  
    11.   
    12. namespace  WordCreateDLL  
    13. {  
    14.   public   class  AddPic  
    15.     {  
    16.       public   static   void  AddSimplePic(Document WordDoc,  string  FName,  float  Width,  float  Height,  object  An, WdWrapType wdWrapType)  
    17.       {  
    18.           //插入图片   
    19.           string  FileName = @FName; //图片所在路径   
    20.           object  LinkToFile =  false ;  
    21.           object  SaveWithDocument =  true ;  
    22.           object  Anchor = An;  
    23.           WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(FileName, ref  LinkToFile,  ref  SaveWithDocument,  ref  Anchor);  
    24.           WordDoc.Application.ActiveDocument.InlineShapes[1].Width = Width;//图片宽度   
    25.           WordDoc.Application.ActiveDocument.InlineShapes[1].Height = Height;//图片高度   
    26.           //将图片设置为四周环绕型   
    27.           Microsoft.Office.Interop.Word.Shape s = WordDoc.Application.ActiveDocument.InlineShapes[1].ConvertToShape();  
    28.           s.WrapFormat.Type = wdWrapType;  
    29.       }  
    30.   
    31.     }  
    32. }  
    1. using  
    2. System;   
    3. using System.Collections.Generic;   
    4. using System.ComponentModel;   
    5. using System.Data;   
    6. using System.Linq;   
    7. using System.Text;   
    8. using Word = Microsoft.Office.Interop.Word;   
    9. using System.IO;   
    10. using System.Reflection;   
    11. using Microsoft.Office.Interop.Word;   
    12. namespace WordCreateDLL   
    13. public class AddPic { public static void AddSimplePic(Document   
    14. WordDoc, string FName, float Width, float Height, object An, WdWrapType   
    15. wdWrapType) { //插入图片 string FileName = @FName;//图片所在路径 object   
    16. LinkToFile = falseobject SaveWithDocument = trueobject Anchor = An;   
    17. WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(FileName,   
    18. ref LinkToFile, ref SaveWithDocument, ref Anchor);   
    19. WordDoc.Application.ActiveDocument.InlineShapes[1].Width = Width;//图片宽度   
    20. WordDoc.Application.ActiveDocument.InlineShapes[1].Height =   
    21. Height;//图片高度 //将图片设置为四周环绕型 Microsoft.Office.Interop.Word.Shape s =   
    22. WordDoc.Application.ActiveDocument.InlineShapes[1].ConvertToShape();   
    23. s.WrapFormat.Type = wdWrapType; } }   
    24. }  

    三、插入表格


    1. using  System;  
    2. using  System.Collections.Generic;  
    3. using  System.ComponentModel;  
    4. using  System.Data;  
    5. using  System.Linq;  
    6. using  System.Text;  
    7. using  Word = Microsoft.Office.Interop.Word;  
    8. using  System.IO;  
    9. using  System.Reflection;  
    10. using  Microsoft.Office.Interop.Word;  
    11.   
    12. namespace  WordCreateDLL  
    13. {  
    14.    public   class  AddTable  
    15.     {  
    16.        public   static   void  AddSimpleTable(Application WordApp, Document WordDoc,  int  numrows,  int  numcolumns, WdLineStyle outStyle, WdLineStyle intStyle)  
    17.        {  
    18.            Object Nothing = System.Reflection.Missing.Value;  
    19.            //文档中创建表格   
    20.            Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, numrows, numcolumns, ref  Nothing,  ref  Nothing);  
    21.            //设置表格样式   
    22.            newTable.Borders.OutsideLineStyle = outStyle;  
    23.            newTable.Borders.InsideLineStyle = intStyle;  
    24.            newTable.Columns[1].Width = 100f;  
    25.            newTable.Columns[2].Width = 220f;  
    26.            newTable.Columns[3].Width = 105f;  
    27.   
    28.            //填充表格内容   
    29.            newTable.Cell(1, 1).Range.Text = "产品详细信息表" ;  
    30.            newTable.Cell(1, 1).Range.Bold = 2;//设置单元格中字体为粗体   
    31.            //合并单元格   
    32.            newTable.Cell(1, 1).Merge(newTable.Cell(1, 3));  
    33.            WordApp.Selection.Cells.VerticalAlignment =WdCellVerticalAlignment.wdCellAlignVerticalCenter;//垂直居中   
    34.            WordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;//水平居中   
    35.   
    36.            //填充表格内容   
    37.            newTable.Cell(2, 1).Range.Text = "产品基本信息" ;  
    38.            newTable.Cell(2, 1).Range.Font.Color =WdColor.wdColorDarkBlue;//设置单元格内字体颜色   
    39.            //合并单元格   
    40.            newTable.Cell(2, 1).Merge(newTable.Cell(2, 3));  
    41.            WordApp.Selection.Cells.VerticalAlignment =WdCellVerticalAlignment.wdCellAlignVerticalCenter;  
    42.   
    43.            //填充表格内容   
    44.            newTable.Cell(3, 1).Range.Text = "品牌名称:" ;  
    45.            newTable.Cell(3, 2).Range.Text = "品牌名称:" ;  
    46.            //纵向合并单元格   
    47.            newTable.Cell(3, 3).Select();//选中一行   
    48.            object  moveUnit = WdUnits.wdLine;  
    49.            object  moveCount = 5;  
    50.            object  moveExtend = WdMovementType.wdExtend;  
    51.            WordApp.Selection.MoveDown(ref  moveUnit,  ref  moveCount,  ref  moveExtend);  
    52.            WordApp.Selection.Cells.Merge();  
    53.   
    54.   
    55.            //插入图片   
    56.            string  FileName = @ "C:\1.jpg" ; //图片所在路径   
    57.            object  Anchor = WordDoc.Application.Selection.Range;  
    58.            float  Width = 200f; //图片宽度   
    59.            float  Height = 200f; //图片高度   
    60.   
    61.            //将图片设置为四周环绕型   
    62.            WdWrapType wdWrapType = Microsoft.Office.Interop.Word.WdWrapType.wdWrapSquare;  
    63.            AddPic.AddSimplePic(WordDoc, FileName, Width, Height, Anchor, wdWrapType);  
    64.   
    65.            newTable.Cell(12, 1).Range.Text = "产品特殊属性" ;  
    66.            newTable.Cell(12, 1).Merge(newTable.Cell(12, 3));  
    67.            //在表格中增加行   
    68.            WordDoc.Content.Tables[1].Rows.Add(ref  Nothing);  
    69.        }  
    70.   
    71.   
    72.     }  
    73. }  
    1. using  
    2. System;   
    3. using System.Collections.Generic;   
    4. using System.ComponentModel;   
    5. using System.Data;   
    6. using System.Linq;   
    7. using System.Text;   
    8. using Word = Microsoft.Office.Interop.Word;   
    9. using System.IO;   
    10. using System.Reflection;   
    11. using Microsoft.Office.Interop.Word;   
    12. namespace WordCreateDLL   
    13. public class AddTable { public static void AddSimpleTable(Application   
    14. WordApp, Document WordDoc, int numrows, int numcolumns, WdLineStyle   
    15. outStyle, WdLineStyle intStyle) { Object Nothing =   
    16. System.Reflection.Missing.Value; //文档中创建表格   
    17. Microsoft.Office.Interop.Word.Table newTable =   
    18. WordDoc.Tables.Add(WordApp.Selection.Range, numrows, numcolumns, ref  
    19. Nothing, ref Nothing); //设置表格样式 newTable.Borders.OutsideLineStyle =   
    20. outStyle; newTable.Borders.InsideLineStyle = intStyle;   
    21. newTable.Columns[1].Width = 100f; newTable.Columns[2].Width = 220f;   
    22. newTable.Columns[3].Width = 105f; //填充表格内容 newTable.Cell(1,   
    23. 1).Range.Text = "产品详细信息表"; newTable.Cell(1, 1).Range.Bold =   
    24. 2;//设置单元格中字体为粗体 //合并单元格 newTable.Cell(1, 1).Merge(newTable.Cell(1, 3));   
    25. WordApp.Selection.Cells.VerticalAlignment   
    26. =WdCellVerticalAlignment.wdCellAlignVerticalCenter;//垂直居中   
    27. WordApp.Selection.ParagraphFormat.Alignment =   
    28. WdParagraphAlignment.wdAlignParagraphCenter;//水平居中 //填充表格内容   
    29. newTable.Cell(2, 1).Range.Text = "产品基本信息"; newTable.Cell(2,   
    30. 1).Range.Font.Color =WdColor.wdColorDarkBlue;//设置单元格内字体颜色 //合并单元格   
    31. newTable.Cell(2, 1).Merge(newTable.Cell(2, 3));   
    32. WordApp.Selection.Cells.VerticalAlignment   
    33. =WdCellVerticalAlignment.wdCellAlignVerticalCenter; //填充表格内容   
    34. newTable.Cell(3, 1).Range.Text = "品牌名称:"; newTable.Cell(3,   
    35. 2).Range.Text = "品牌名称:"//纵向合并单元格 newTable.Cell(3, 3).Select();//选中一行   
    36. object moveUnit = WdUnits.wdLine; object moveCount = 5; object  
    37. moveExtend = WdMovementType.wdExtend; WordApp.Selection.MoveDown(ref  
    38. moveUnit, ref moveCount, ref moveExtend);   
    39. WordApp.Selection.Cells.Merge(); //插入图片 string FileName =   
    40. @"C:\1.jpg";//图片所在路径 object Anchor =   
    41. WordDoc.Application.Selection.Range; float Width = 200f;//图片宽度 float   
    42. Height = 200f;//图片高度 //将图片设置为四周环绕型 WdWrapType wdWrapType =   
    43. Microsoft.Office.Interop.Word.WdWrapType.wdWrapSquare;   
    44. AddPic.AddSimplePic(WordDoc, FileName, Width, Height, Anchor,   
    45. wdWrapType); newTable.Cell(12, 1).Range.Text = "产品特殊属性";   
    46. newTable.Cell(12, 1).Merge(newTable.Cell(12, 3)); //在表格中增加行   
    47. WordDoc.Content.Tables[1].Rows.Add(ref Nothing); } }   
    48. }  

    四、插入chart


    1. using  System;  
    2. using  System.Collections.Generic;  
    3. using  System.ComponentModel;  
    4. using  System.Data;  
    5. using  System.Linq;  
    6. using  System.Text;  
    7. using  Word = Microsoft.Office.Interop.Word;  
    8. using  System.IO;  
    9. using  System.Reflection;  
    10. using  Microsoft.Office.Interop.Word;  
    11. using  Microsoft.Office.Interop.Graph;  
    12. using  System.Windows.Forms;  
    13. using  System.Drawing;  
    14.   
    15.   
    16. namespace  WordCreateDLL  
    17. {  
    18.     public   class  AddChart  
    19.     {  
    20.         public   static   void  AddSimpleChart(Document WordDoc, Word.Application WordApp, Object oEndOfDoc,  string  [,]data)  
    21.         {  
    22.             //插入chart     
    23.             object  oMissing = System.Reflection.Missing.Value;  
    24.             Word.InlineShape oShape;  
    25.             object  oClassType =  "MSGraph.Chart.8" ;  
    26.             Word.Range wrdRng = WordDoc.Bookmarks.get_Item(ref  oEndOfDoc).Range;  
    27.             oShape = wrdRng.InlineShapes.AddOLEObject(ref  oClassType,  ref  oMissing,  
    28.                 ref  oMissing,  ref  oMissing,  ref  oMissing,  
    29.                 ref  oMissing,  ref  oMissing,  ref  oMissing);  
    30.   
    31.             //Demonstrate use of late bound oChart and oChartApp objects to   
    32.             //manipulate the chart object with MSGraph.   
    33.             object  oChart;  
    34.             object  oChartApp;  
    35.             oChart = oShape.OLEFormat.Object;  
    36.             oChartApp = oChart.GetType().InvokeMember("Application" ,BindingFlags.GetProperty,  null , oChart,  null );  
    37.   
    38.             //Change the chart type to Line.   
    39.             object [] Parameters =  new  Object[1];  
    40.             Parameters[0] = 4; //xlLine = 4   
    41.             oChart.GetType().InvokeMember("ChartType" , BindingFlags.SetProperty,  
    42.                 null , oChart, Parameters);  
    43.   
    44.   
    45.             Chart objChart = (Chart)oShape.OLEFormat.Object;  
    46.             objChart.ChartType = XlChartType.xlColumnClustered;  
    47.   
    48.             //绑定数据   
    49.             DataSheet dataSheet;  
    50.             dataSheet = objChart.Application.DataSheet;  
    51.             int  rownum=data.GetLength(0);  
    52.             int  columnnum=data.GetLength(1);  
    53.             for ( int  i=1;i<=rownum;i++ )  
    54.                 for  ( int  j = 1; j <= columnnum; j++)  
    55.                 {   
    56.                    dataSheet.Cells[i,j] =data[i-1,j-1];  
    57.        
    58.                 }  
    59.             
    60.             objChart.Application.Update();  
    61.             oChartApp.GetType().InvokeMember("Update" ,  
    62.                 BindingFlags.InvokeMethod, null , oChartApp,  null );  
    63.             oChartApp.GetType().InvokeMember("Quit" ,  
    64.                 BindingFlags.InvokeMethod, null , oChartApp,  null );  
    65.   
    66.             //设置大小   
    67.             oShape.Width = WordApp.InchesToPoints(6.25f);  
    68.             oShape.Height = WordApp.InchesToPoints(3.57f);  
    69.   
    70.         }  
    71.     }  
    72. }  
    1. using System;   
    2. using System.Collections.Generic;   
    3. using System.ComponentModel;   
    4. using System.Data;   
    5. using System.Linq;   
    6. using System.Text;   
    7. using Word = Microsoft.Office.Interop.Word;   
    8. using System.IO;   
    9. using System.Reflection;   
    10. using Microsoft.Office.Interop.Word;   
    11. using Microsoft.Office.Interop.Graph;   
    12. using System.Windows.Forms;   
    13. using System.Drawing;   
    14. namespace WordCreateDLL   
    15. {   
    16.     public class AddChart   
    17.     {   
    18.         public static void AddSimpleChart(Document WordDoc, Word.Application WordApp, Object oEndOfDoc, string [,]data)   
    19.         {   
    20.             //插入chart     
    21.             object oMissing = System.Reflection.Missing.Value;   
    22.             Word.InlineShape oShape;   
    23.             object oClassType = "MSGraph.Chart.8";   
    24.             Word.Range wrdRng = WordDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;   
    25.             oShape = wrdRng.InlineShapes.AddOLEObject(ref oClassType, ref oMissing,   
    26.                 ref oMissing, ref oMissing, ref oMissing,   
    27.                 ref oMissing, ref oMissing, ref oMissing);   
    28.             //Demonstrate use of late bound oChart and oChartApp objects to   
    29.             //manipulate the chart object with MSGraph.   
    30.             object oChart;   
    31.             object oChartApp;   
    32.             oChart = oShape.OLEFormat.Object;   
    33.             oChartApp = oChart.GetType().InvokeMember("Application",BindingFlags.GetProperty, null, oChart, null);   
    34.             //Change the chart type to Line.   
    35.             object[] Parameters = new Object[1];   
    36.             Parameters[0] = 4; //xlLine = 4   
    37.             oChart.GetType().InvokeMember("ChartType", BindingFlags.SetProperty,   
    38.                 null, oChart, Parameters);   
    39.             Chart objChart = (Chart)oShape.OLEFormat.Object;   
    40.             objChart.ChartType = XlChartType.xlColumnClustered;   
    41.             //绑定数据   
    42.             DataSheet dataSheet;   
    43.             dataSheet = objChart.Application.DataSheet;   
    44.             int rownum=data.GetLength(0);   
    45.             int columnnum=data.GetLength(1);   
    46.             for(int i=1;i<=rownum;i++ )   
    47.                 for (int j = 1; j <= columnnum; j++)   
    48.                 {    
    49.                    dataSheet.Cells[i,j] =data[i-1,j-1];   
    50.         
    51.                 }   
    52.              
    53.             objChart.Application.Update();   
    54.             oChartApp.GetType().InvokeMember("Update",   
    55.                 BindingFlags.InvokeMethod, null, oChartApp, null);   
    56.             oChartApp.GetType().InvokeMember("Quit",   
    57.                 BindingFlags.InvokeMethod, null, oChartApp, null);   
    58.             //设置大小   
    59.             oShape.Width = WordApp.InchesToPoints(6.25f);   
    60.             oShape.Height = WordApp.InchesToPoints(3.57f);   
    61.         }   
    62.     }   
    63. }  

    测试程序


    1. private   void  button3_Click( object  sender, EventArgs e)  
    2.        {  
    3.   
    4.   
    5.            object  oMissing = System.Reflection.Missing.Value;  
    6.            object  oEndOfDoc =  "\\endofdoc" /* \endofdoc is a predefined bookmark */   
    7.   
    8.            //Start Word and create a new document.   
    9.            Word.Application oWord;  
    10.            Word.Document oDoc;  
    11.            oWord = new  Word.Application();  
    12.            oWord.Visible = true ;  
    13.            oDoc = oWord.Documents.Add(ref  oMissing,  ref  oMissing,  
    14.                ref  oMissing,  ref  oMissing);  
    15.   
    16.            ////添加页眉   
    17.            String HeaderText = "石化盈科" ;  
    18.           // AddHeader.AddSimpleHeader(oWord, HeaderText);   
    19.            WdParagraphAlignment wdAlign = WdParagraphAlignment.wdAlignParagraphCenter;  
    20.            WdColor fontcolor = WdColor.wdColorBlue;  
    21.            float  fontsize = 10;  
    22.            //AddHeader.AddSimpleHeader(oWord, HeaderText, wdAlign);   
    23.            AddHeader.AddSimpleHeader(oWord, HeaderText, wdAlign,fontcolor,fontsize);  
    24.   
    25.            //Insert a paragraph at the beginning of the document.   
    26.            Word.Paragraph oPara1;  
    27.            oPara1 = oDoc.Content.Paragraphs.Add(ref  oMissing);  
    28.            oPara1.Range.Text = "Heading 1" ;  
    29.            oPara1.Range.Font.Bold = 1;  
    30.            oPara1.Format.SpaceAfter = 24;    //24 pt spacing after paragraph.   
    31.            oPara1.Range.InsertParagraphAfter();  
    32.   
    33.            //Insert a paragraph at the end of the document.   
    34.            Word.Paragraph oPara2;  
    35.            object  oRng = oDoc.Bookmarks.get_Item( ref  oEndOfDoc).Range;  
    36.            oPara2 = oDoc.Content.Paragraphs.Add(ref  oRng);  
    37.            oPara2.Range.Text = "Heading 2" ;  
    38.            oPara2.Format.SpaceAfter = 6;  
    39.            oPara2.Range.InsertParagraphAfter();  
    40.   
    41.            //插入文字   
    42.            Word.Paragraph oPara3;  
    43.            oRng = oDoc.Bookmarks.get_Item(ref  oEndOfDoc).Range;  
    44.            oPara3 = oDoc.Content.Paragraphs.Add(ref  oRng);  
    45.            oPara3.Range.Text = "This is a sentence of normal text. Now here is a table:" ;  
    46.            oPara3.Range.Font.Bold = 0;  
    47.            oPara3.Format.SpaceAfter = 24;  
    48.            oPara3.Range.InsertParagraphAfter();  
    49.   
    50.            string  text =  "zhangruichao " ;  
    51.            WdColor textcolor = fontcolor;  
    52.            float  textsize = 12;  
    53.            AddLine.AddSimpLine(oDoc, oEndOfDoc, oRng, text, textcolor, textsize);  
    54.   
    55.   
    56.            //插入表格   
    57.            WdLineStyle OutStyle = WdLineStyle.wdLineStyleThickThinLargeGap;  
    58.            WdLineStyle InStyle = WdLineStyle.wdLineStyleSingle;  
    59.            AddTable.AddSimpleTable(oWord, oDoc, 12, 3, OutStyle, InStyle);  
    60.   
    61.            //插入分页   
    62.            Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref  oEndOfDoc).Range;  
    63.            object  oCollapseEnd = Word.WdCollapseDirection.wdCollapseEnd;  
    64.            object  oPageBreak = Word.WdBreakType.wdPageBreak;  
    65.            wrdRng.Collapse(ref  oCollapseEnd);  
    66.            wrdRng.InsertBreak(ref  oPageBreak);  
    67.            wrdRng.Collapse(ref  oCollapseEnd);  
    68.            wrdRng.InsertAfter("We're now on page 2. Here's my chart:" );  
    69.            wrdRng.InsertParagraphAfter();  
    70.   
    71.            //Insert a chart.   
    72.            string [,] data= new   string [4,5];  
    73.   
    74.            data[0,1] = "第一月" ;  
    75.            data[0, 2] = "第二月" ;  
    76.            data[0, 3] = "第三月" ;  
    77.            data[0, 4] = "第四月" ;  
    78.   
    79.            data[1,0] = "东部" ;  
    80.            data[1,1] = "50" ;  
    81.            data[1,2] = "50" ;  
    82.            data[1,3] = "40" ;  
    83.            data[1,4] = "50" ;  
    84.   
    85.   
    86.            data[2,0] = "西部" ;  
    87.            data[2,1] = "60" ;  
    88.            data[2,2] = "60" ;  
    89.            data[2,3] = "70" ;  
    90.            data[2,4] = "80" ;  
    91.   
    92.            //data[3,6] = "0";   
    93.            data[3,0] = "中部" ;  
    94.            data[3,1] = "50" ;  
    95.            data[3,2] = "50" ;  
    96.            data[3,3] = "40" ;  
    97.            data[3,4] = "50" ;  
    98.   
    99.   
    100.   
    101.   
    102.            AddChart.AddSimpleChart(oDoc, oWord, oEndOfDoc, data);  
    103.   
    104.            wrdRng = oDoc.Bookmarks.get_Item(ref  oEndOfDoc).Range;  
    105.            wrdRng.InsertParagraphAfter();  
    106.            wrdRng.InsertAfter("THE END." );  
    107.   
    108.            //Close this form.   
    109.            this .Close();  
    110.   
    111.        }  
  • 相关阅读:
    敏捷开发读后感
    结对编程:电梯调度 (张恿、赵骞)
    软件工程 Individual Project
    [转]SQLServer 2008以上误操作数据库恢复方法——日志尾部备份
    下拉菜单demo---参考阿里云首页顶部下拉菜单
    走进spring之springmvc实战篇(二)
    剖析javascript全局变量和局部变量
    走进spring之springmvc实战篇(一)
    日常总结——JSP篇(补)
    我的程序员之路
  • 原文地址:https://www.cnblogs.com/chenbg2001/p/1685746.html
Copyright © 2011-2022 走看看