PDA

View Full Version : حرفه ای: اعمال تغییرات از داخل فرم روی فایل word



cerezaei65
دوشنبه 20 شهریور 1391, 07:29 صبح
سلام
یه برنامه دارم میخوام فایل تمپلت word که طراحی کردم و توی دیتابیس قرار دادم رو بگیره و تصویر داخلشو اون آدرس عکسی که کاربر میده عوض کنه و جای دیگه ذخیره کنه( بهتره داخله دیتابیس باشه)
مشکلم اینه که چجوری عکس داخل فایل word رو عوض کنم!؟
این کارو خوده نرم افزار کنه!
ممنون از جوابهایی که میخواهید بدید!:لبخندساده:

cerezaei65
دوشنبه 20 شهریور 1391, 11:08 صبح
کسی نبود کمک کنه:گریه:
کد زیر یه عکس اضافه میکنه و اینکه از فایلی که من گذاشتم استفاده نمیکنه!


// first we are creating application of word.
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();

// now creating new document.
WordApp.Documents.Add();

// see word file behind your program

WordApp.Visible = true;

// get the reference of active document
Microsoft.Office.Interop.Word.Document doc = WordApp.ActiveDocument;

// get the range
Microsoft.Office.Interop.Word.Range drange = doc.Range();

// now add the picture in active document reference and store the reference of picture in inlineshape object
Microsoft.Office.Interop.Word.InlineShape picture = drange.InlineShapes.AddPicture("c:\\logo.gif", Type.Missing, Type.Missing, Type.Missing);

// noew add the hyperlink to object of inlineshape
drange.Hyperlinks.Add(picture, "http:\\www.c-sharpcorner.com", Type.Missing, Type.Missing, Type.Missing, Type.Missing);

// file is saved.
doc.SaveAs("c:\\hello.doc", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
// application is now quit.
WordApp.Quit(Type.Missing, Type.Missing, Type.Missing);