如何使用c#在Word的标题中的表格单元格中插入和调整图像大小?

时间:2017-08-23 19:36:53

标签: c# ms-word interop

我有这个方法在我的文档中插入标题。 我想在标题的表格的第一个单元格中插入一张图片。此外,我想在该图像下键入一行文本,但在同一单元格中。 但是我在" shape.Width = 60;"和崩溃的话。有人能帮助我吗?

public void insertHeader()
    {

        foreach (Word.Section section in ObjDoc.Sections)
        {
            Word.Table TablaHdr;
            Word.Range headerRange = section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
            TablaHdr = ObjDoc.Tables.Add(headerRange, 1, 2, ref ObjMiss, ref ObjMiss);

            TablaHdr.Columns[1].SetWidth(ObjWord.MillimetersToPoints(57.9f), Word.WdRulerStyle.wdAdjustNone);
            TablaHdr.Columns[2].SetWidth(ObjWord.MillimetersToPoints(98.1f), Word.WdRulerStyle.wdAdjustNone);

            TablaHdr.Borders[Word.WdBorderType.wdBorderHorizontal].Visible = true;
            TablaHdr.Borders[Word.WdBorderType.wdBorderVertical].Visible = true;
            TablaHdr.Borders[Word.WdBorderType.wdBorderTop].Visible = true;
            TablaHdr.Borders[Word.WdBorderType.wdBorderLeft].Visible = true;
            TablaHdr.Borders[Word.WdBorderType.wdBorderRight].Visible = true;
            TablaHdr.Borders[Word.WdBorderType.wdBorderBottom].Visible = true;


            var shape = TablaHdr.Cell(1,1).Range.InlineShapes.AddPicture(@"D:\logo.png", false, true);
            shape.Width=60;
            shape.Height=60;

        }
    }

0 个答案:

没有答案