/// <summary> 在文档中插入一些内容,但是不自动换行 </summary> /// <param name="position"> 文字从哪个位置插入</param> /// <param name="data"> 输入的数据 </param> /// <param name="style"> 新添加的内容的样式的名称 </param> /// <returns>返回的范围为新添加的内容所占的区域,与原内容无关</returns> public Range InsertText(string data, int position, WordStyle style = WordStyle.Follow) { var rg = Document.Range(position, position); rg.InsertAfter(data); WordStyles.SetStyle(rg, style); return(rg); }
/// <summary> 在文档正文中插入一张图片</summary> /// <param name="picPath">图片的文件路径</param> /// <param name="width">图片的宽度,单位为 point </param>> /// <param name="height">图片的高度,单位为 point </param>> /// <returns></returns> public InlineShape InsertPicture(int position, string picPath, float width, float height, WordStyle style = WordStyle.Picture) { var rg = Document.Range(position, position); InlineShape shape = rg.InlineShapes.AddPicture(picPath); shape.Width = width; shape.Height = height; WordStyles.SetStyle(shape.Range, style); return(shape); }
/// <summary> 在文档中插入一个表格 </summary> /// <param name="startIndex">表格起始的位置</param> /// <param name="data"> 表格所对应的数据,包含表头。同一行的元素之间用制表符分隔,多行之间用换行符分隔 </param> /// <param name="rows"> 表格的行数 </param> /// <param name="columns"> 表格的列数 </param> public Table InsertTable(Document doc, int startIndex, string data, int rows, int columns, WordStyle style = WordStyle.Table) { Range rg = doc.Range(Start: startIndex, End: startIndex); // rg.Text = data; Table tb = rg.ConvertToTable(Separator: WdTableFieldSeparator.wdSeparateByTabs, NumRows: rows, NumColumns: columns); WordStyles.SetStyle(tb, style); return(tb); }