Microsoft.Office.Interop.Word 创建word

     原文出处 http://blog.csdn.net/zrchao/archive/2009/08/04/4407788.aspx

 

     搜集了Microsoft.Office.Interop.Word生产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. }  
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Linq; using System.Text; using Word = Microsoft.Office.Interop.Word; using System.IO; using System.Reflection; using Microsoft.Office.Interop.Word; namespace WordCreateDLL { public class AddHeader { public static void AddSimpleHeader(Application WordApp,string HeaderText) { //添加页眉 WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView; WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader; WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(HeaderText); WordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;//设置左对齐 WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; } public static void AddSimpleHeader(Application WordApp, string HeaderText, WdParagraphAlignment wdAlign) { //添加页眉 WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView; WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader; WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(HeaderText); //WordApp.Selection.Font.Color = WdColor.wdColorDarkRed;//设置字体颜色 WordApp.Selection.ParagraphFormat.Alignment = wdAlign;//设置左对齐 WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; } public static void AddSimpleHeader(Application WordApp, string HeaderText, WdParagraphAlignment wdAlign,WdColor fontcolor,float fontsize) { //添加页眉 WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView; WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader; WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(HeaderText); WordApp.Selection.Font.Color =fontcolor;//设置字体颜色 WordApp.Selection.Font.Size = fontsize;//设置字体大小 WordApp.Selection.ParagraphFormat.Alignment = wdAlign;//设置对齐方式 WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; } } }

二、插入图片


  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. }  
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Linq; using System.Text; using Word = Microsoft.Office.Interop.Word; using System.IO; using System.Reflection; using Microsoft.Office.Interop.Word; namespace WordCreateDLL { public class AddPic { public static void AddSimplePic(Document WordDoc, string FName, float Width, float Height, object An, WdWrapType wdWrapType) { //插入图片 string FileName = @FName;//图片所在路径 object LinkToFile = false; object SaveWithDocument = true; object Anchor = An; WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(FileName, ref LinkToFile, ref SaveWithDocument, ref Anchor); WordDoc.Application.ActiveDocument.InlineShapes[1].Width = Width;//图片宽度 WordDoc.Application.ActiveDocument.InlineShapes[1].Height = Height;//图片高度 //将图片设置为四周环绕型 Microsoft.Office.Interop.Word.Shape s = WordDoc.Application.ActiveDocument.InlineShapes[1].ConvertToShape(); s.WrapFormat.Type = wdWrapType; } } }

三、插入表格


  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. }  
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Linq; using System.Text; using Word = Microsoft.Office.Interop.Word; using System.IO; using System.Reflection; using Microsoft.Office.Interop.Word; namespace WordCreateDLL { public class AddTable { public static void AddSimpleTable(Application WordApp, Document WordDoc, int numrows, int numcolumns, WdLineStyle outStyle, WdLineStyle intStyle) { Object Nothing = System.Reflection.Missing.Value; //文档中创建表格 Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, numrows, numcolumns, ref Nothing, ref Nothing); //设置表格样式 newTable.Borders.OutsideLineStyle = outStyle; newTable.Borders.InsideLineStyle = intStyle; newTable.Columns[1].Width = 100f; newTable.Columns[2].Width = 220f; newTable.Columns[3].Width = 105f; //填充表格内容 newTable.Cell(1, 1).Range.Text = "产品详细信息表"; newTable.Cell(1, 1).Range.Bold = 2;//设置单元格中字体为粗体 //合并单元格 newTable.Cell(1, 1).Merge(newTable.Cell(1, 3)); WordApp.Selection.Cells.VerticalAlignment =WdCellVerticalAlignment.wdCellAlignVerticalCenter;//垂直居中 WordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;//水平居中 //填充表格内容 newTable.Cell(2, 1).Range.Text = "产品基本信息"; newTable.Cell(2, 1).Range.Font.Color =WdColor.wdColorDarkBlue;//设置单元格内字体颜色 //合并单元格 newTable.Cell(2, 1).Merge(newTable.Cell(2, 3)); WordApp.Selection.Cells.VerticalAlignment =WdCellVerticalAlignment.wdCellAlignVerticalCenter; //填充表格内容 newTable.Cell(3, 1).Range.Text = "品牌名称:"; newTable.Cell(3, 2).Range.Text = "品牌名称:"; //纵向合并单元格 newTable.Cell(3, 3).Select();//选中一行 object moveUnit = WdUnits.wdLine; object moveCount = 5; object moveExtend = WdMovementType.wdExtend; WordApp.Selection.MoveDown(ref moveUnit, ref moveCount, ref moveExtend); WordApp.Selection.Cells.Merge(); //插入图片 string FileName = @"C:/1.jpg";//图片所在路径 object Anchor = WordDoc.Application.Selection.Range; float Width = 200f;//图片宽度 float Height = 200f;//图片高度 //将图片设置为四周环绕型 WdWrapType wdWrapType = Microsoft.Office.Interop.Word.WdWrapType.wdWrapSquare; AddPic.AddSimplePic(WordDoc, FileName, Width, Height, Anchor, wdWrapType); newTable.Cell(12, 1).Range.Text = "产品特殊属性"; newTable.Cell(12, 1).Merge(newTable.Cell(12, 3)); //在表格中增加行 WordDoc.Content.Tables[1].Rows.Add(ref Nothing); } } }

四、插入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. }  
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Linq; using System.Text; using Word = Microsoft.Office.Interop.Word; using System.IO; using System.Reflection; using Microsoft.Office.Interop.Word; using Microsoft.Office.Interop.Graph; using System.Windows.Forms; using System.Drawing; namespace WordCreateDLL { public class AddChart { public static void AddSimpleChart(Document WordDoc, Word.Application WordApp, Object oEndOfDoc, string [,]data) { //插入chart object oMissing = System.Reflection.Missing.Value; Word.InlineShape oShape; object oClassType = "MSGraph.Chart.8"; Word.Range wrdRng = WordDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; oShape = wrdRng.InlineShapes.AddOLEObject(ref oClassType, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); //Demonstrate use of late bound oChart and oChartApp objects to //manipulate the chart object with MSGraph. object oChart; object oChartApp; oChart = oShape.OLEFormat.Object; oChartApp = oChart.GetType().InvokeMember("Application",BindingFlags.GetProperty, null, oChart, null); //Change the chart type to Line. object[] Parameters = new Object[1]; Parameters[0] = 4; //xlLine = 4 oChart.GetType().InvokeMember("ChartType", BindingFlags.SetProperty, null, oChart, Parameters); Chart objChart = (Chart)oShape.OLEFormat.Object; objChart.ChartType = XlChartType.xlColumnClustered; //绑定数据 DataSheet dataSheet; dataSheet = objChart.Application.DataSheet; int rownum=data.GetLength(0); int columnnum=data.GetLength(1); for(int i=1;i<=rownum;i++ ) for (int j = 1; j <= columnnum; j++) { dataSheet.Cells[i,j] =data[i-1,j-1]; } objChart.Application.Update(); oChartApp.GetType().InvokeMember("Update", BindingFlags.InvokeMethod, null, oChartApp, null); oChartApp.GetType().InvokeMember("Quit", BindingFlags.InvokeMethod, null, oChartApp, null); //设置大小 oShape.Width = WordApp.InchesToPoints(6.25f); oShape.Height = WordApp.InchesToPoints(3.57f); } } }

测试程序


  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.        }  

 

你可能感兴趣的:(学习笔记,object,parameters,application,null,string,产品)