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

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
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符