如何在Word中生成流程图:代码如下
///////创建两个节点
Word = Microsoft.Office.Interop.Word;
Word = Microsoft.Office.Interop.Word;
Word.Application aap=new Word.Application ();
Word.Document doc=app.Documents.open(参数省略);word.Shape sp = doc.Shapes.AddCanvas(0, 0, 414, 150, ref tmr);
sp.Name = "shap1";
Word.Shape lab = sp.CanvasItems.AddLabel(Core.MsoTextOrientation.msoTextOrientationHorizontal, x, 0, y, 20);
lab.Name="lab1";
lab.TextFrame.TextRange.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
lab.TextFrame.TextRange.Text = "la1";
lab.PickUp();
lab = sp.CanvasItems.AddLabel(Core.MsoTextOrientation.msoTextOrientationHorizontal, 0, 0, 100, 30);
lab.Apply();
lab.Name = "lab_2";
lab.TextFrame.TextRange.Text = "lab_1";
/////////////////////////////链接节点
RectangleF rt = new Rectangle();
object tt="shap1";
Word.Shape tm = doc.Shapes.get_Item(ref tt);
object num=1;
//lab_1
Word.Shape lab1=tm.CanvasItems.get_Item(ref num);
rt.X = (x);
rt.Y = (0 + 20/2);
//lab_2
num=2;
Word.Shape lab2 = tm.CanvasItems.get_Item(ref num);
rt.Width =( 0 + 100);
rt.Height = (0+30/2);
object tmm = lab1;
doc.Shapes.AddConnector(Microsoft.Office.Core.MsoConnectorType.msoConnectorElbow, rt.X, rt.Y, rt.Width, rt.Height).Select(ref tmm);
app.Selection.ShapeRange.Line.EndArrowheadStyle = Core.MsoArrowheadStyle.msoArrowheadTriangle;
app.Selection.ShapeRange.Flip(Microsoft.Office.Core.MsoFlipCmd.msoFlipHorizontal);
app.Selection.ShapeRange.Flip(Microsoft.Office.Core.MsoFlipCmd.msoFlipVertical);
//错误发生在下面语句;错误是参数错误
app.Selection.ShapeRange.ConnectorFormat.BeginConnect(out lab1,2);
app.Selection.ShapeRange.ConnectorFormat.EndConnect(out lab2,4);
处理这个错误。还有一个不明就是 doc.shapes.AddConnector()函数中的第二到第五个参数 是单位是 厘米 还是像素或者是寸或者是什么。我用觉得是 像素。可是怎么转换 。还有一个问题 word.shape.top 属性的值的单位是什么是像素还是厘米;
///////创建两个节点
Word = Microsoft.Office.Interop.Word;
Word = Microsoft.Office.Interop.Word;
Word.Application aap=new Word.Application ();
Word.Document doc=app.Documents.open(参数省略);word.Shape sp = doc.Shapes.AddCanvas(0, 0, 414, 150, ref tmr);
sp.Name = "shap1";
Word.Shape lab = sp.CanvasItems.AddLabel(Core.MsoTextOrientation.msoTextOrientationHorizontal, x, 0, y, 20);
lab.Name="lab1";
lab.TextFrame.TextRange.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
lab.TextFrame.TextRange.Text = "la1";
lab.PickUp();
lab = sp.CanvasItems.AddLabel(Core.MsoTextOrientation.msoTextOrientationHorizontal, 0, 0, 100, 30);
lab.Apply();
lab.Name = "lab_2";
lab.TextFrame.TextRange.Text = "lab_1";
/////////////////////////////链接节点
RectangleF rt = new Rectangle();
object tt="shap1";
Word.Shape tm = doc.Shapes.get_Item(ref tt);
object num=1;
//lab_1
Word.Shape lab1=tm.CanvasItems.get_Item(ref num);
rt.X = (x);
rt.Y = (0 + 20/2);
//lab_2
num=2;
Word.Shape lab2 = tm.CanvasItems.get_Item(ref num);
rt.Width =( 0 + 100);
rt.Height = (0+30/2);
object tmm = lab1;
doc.Shapes.AddConnector(Microsoft.Office.Core.MsoConnectorType.msoConnectorElbow, rt.X, rt.Y, rt.Width, rt.Height).Select(ref tmm);
app.Selection.ShapeRange.Line.EndArrowheadStyle = Core.MsoArrowheadStyle.msoArrowheadTriangle;
app.Selection.ShapeRange.Flip(Microsoft.Office.Core.MsoFlipCmd.msoFlipHorizontal);
app.Selection.ShapeRange.Flip(Microsoft.Office.Core.MsoFlipCmd.msoFlipVertical);
//错误发生在下面语句;错误是参数错误
app.Selection.ShapeRange.ConnectorFormat.BeginConnect(out lab1,2);
app.Selection.ShapeRange.ConnectorFormat.EndConnect(out lab2,4);
处理这个错误。还有一个不明就是 doc.shapes.AddConnector()函数中的第二到第五个参数 是单位是 厘米 还是像素或者是寸或者是什么。我用觉得是 像素。可是怎么转换 。还有一个问题 word.shape.top 属性的值的单位是什么是像素还是厘米;
http://support.microsoft.com/kb/162101/zh-cn
http://support.microsoft.com/kb/162101/zh-cn