我想让我的标题保持左右对齐

时间:2017-12-05 19:32:21

标签: c# winforms office-interop winforms-interop

我试图通过Microsoft将一些图像放入Word文档的标题中。 Office.Interop.Word。
我想将图片拉伸到文档的两个边界,但我无法这样做;每当我设置左右缩进时,它只会改变左缩进,就像图像只在左侧而不是在右侧拉伸,任何类型的帮助对我来说都是非常宝贵的。这是我正在尝试的片段:

foreach (Microsoft.Office.Interop.Word.Section wordSection in docWord.Sections)
{
    wordSection.PageSetup.HeaderDistance = 0;

    Microsoft.Office.Interop.Word.Range footerRange = wordSection.Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
    //footerRange.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdDarkRed;
    //footerRange.ParagraphFormat.LeftIndent = -(docWord.Application.CentimetersToPoints(3));
    footerRange.InlineShapes.AddPicture(@"C:\\test\\footer.png");

    Microsoft.Office.Interop.Word.Range headerRange = wordSection.Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
    //headerRange.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdDarkRed;
    MessageBox.Show((headerRange.ParagraphFormat.RightIndent - (docWord.Application.CentimetersToPoints(72))).ToString());
    //headerRange.ParagraphFormat.RightIndent = (docWord.Application.InchesToPoints(-1));
    //headerRange.ParagraphFormat.LeftIndent = -(docWord.Application.CentimetersToPoints(3));
    headerRange.ParagraphFormat.FirstLineIndent = -(docWord.Application.CentimetersToPoints(3));
    //MessageBox.Show(headerRange.ParagraphFormat.RightIndent.ToString());
    //headerRange.ParagraphFormat.SpaceBefore =0 ;
    headerRange.InlineShapes.AddPicture(@"C:\\test\\header.png");
}

1 个答案:

答案 0 :(得分:2)

我曾经使用过Microsoft.interope库。您做得正确。不幸的是,Microsoft.interope不提供对拉伸标头的支持。