life清者自清 2017-08-01 07:12 采纳率: 66.7%
浏览 1754
已结题

c# word文档插入图片,嵌入式设置失败,这是为什么?

代码如下:

                      object range = wordDoc.Paragraphs.Last.Range;
        object linkToFile = false;               //默认
        object saveWithDocument = true;               //默认

        string dir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
        InlineShape inlineShape = wordDoc.InlineShapes.AddPicture(dir + "\\test.jpg", ref linkToFile, ref saveWithDocument, ref range);//向文档中插入图片
        if (inlineShape.Height >= 300)
        {
            inlineShape.Width = inlineShape.Width * 300 / inlineShape.Height;
            inlineShape.Height = 300;
        }
        if (inlineShape.Width >= 300)
        {
            inlineShape.Height = inlineShape.Height * 300 / inlineShape.Width;
            inlineShape.Width = 300;
        }
        //Shape cShape = inlineShape.ConvertToShape();
        inlineShape.ConvertToShape().WrapFormat.Type = WdWrapType.wdWrapInline;//设置嵌入型

        //cShape.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoSendBehindText);
        //cShape.WrapFormat.Type = WdWrapType.wdWrapInline;
        wordApp.Selection.Text = "";
        wordApp.Selection.Paragraphs.OutlineLevel = WdOutlineLevel.wdOutlineLevelBodyText;
        wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
        wordApp.Selection.EndKey(6, 0);
        wordApp.Selection.Font.Name = "仿宋_GB2312";
        wordApp.Selection.Font.Name = "Times New Roman";
        wordApp.Selection.Font.Size = 16;
        wordApp.Selection.ParagraphFormat.LineSpacing = 18F;
        wordApp.Selection.Text = "\n";

有没有大神解释一下,主要是嵌入型格式设置失败,word大版本都是2010版。

  • 写回答

1条回答

  • shen_wei 2017-08-01 07:31
    关注
    评论

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services