C#-Aspose.Words-操作word-插入图片示例
[WebMethod(Description = "仅供调试使用")]
public string TestInsert(String label, String imagename)
{
string tmppath = System.Web.HttpContext.Current.Server.MapPath("genword/RCJC/" + "RCJC_SG_YHZG01.doc");
// tmppath = @"F:\项目代码\移动执法\elaqsystemmanager\genword\RCJC\RCJC_SG_YHZG.doc";
//加@不需要转义,php中加@忽略警告(能不能忽略错误待定)
Aspose.Words.Document doc = new Aspose.Words.Document(tmppath);
// 也可以使用 Document,但是要注意导入Aspose.Words的包
Aspose.Words.DocumentBuilder entbuilder = new Aspose.Words.DocumentBuilder(doc);
Shape shape = new Shape(doc, ShapeType.Image);
//Bookmark myname = doc.Range.Bookmarks[label];
//myname.Text = "";
//doc.Range.Bookmarks[label].Remove();//这里是直接清除标签本身
string imgFilePath = System.Web.HttpContext.Current.Server.MapPath("images/" + imagename);//测试是写死AJ.doc
shape.ImageData.SetImage(imgFilePath);
shape.Width = 100;
shape.Height = 25;
shape.WrapType = WrapType.None;//设置图片的板式 嵌入式 四周等等
shape.BehindText = false;
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
shape.ZOrder = Convert.ToInt32(ts.TotalMilliseconds / 100000) ;//设置层级
shape.HorizontalAlignment = HorizontalAlignment.Right;
entbuilder.MoveToBookmark(label);
entbuilder.InsertNode(shape);
String saveUrl = HttpContext.Current.Server.MapPath("genword/RCJC/" + "RCJC_SG_YHZG01.doc");
doc.Save(saveUrl, SaveFormat.Doc);
return "111111111";
}
正文到此结束
- 本文标签: Aspose.Words
- 本文链接: https://code.jiangjiesheng.cn/article/9
- 版权声明: 本文由小江同学原创发布,转载请先联系本站长,谢谢。