PDA

View Full Version : ارتباط با فایل ورد



farnoosh66
شنبه 25 خرداد 1392, 00:04 صبح
سلام دوستان
من میخوام برنامم یه فایل ورد و بگیره بخونه و ... ولی هرچی search کردم کدای مختلف گرفتم واسه Word.ApplicationClass به نحوی خطا میده. البته dll ورد هم اضافه کردما.
لطفا اگه منبعی دارین که بتونم راهنمایی بگیرم یا توش کدی باشه که یه ارتباط حتی خیلی کوچیک با ورد داشته باشه معرفی کنین
با تشکر

alexmcse
شنبه 25 خرداد 1392, 00:15 صبح
انتقال عکس به فایل ورد

private void button1_Click(object sender, EventArgs e)
{
// 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;
// set openfiledialog to select multiple image files
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Images (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF";
ofd.Title = "Select Image To Insert....";
ofd.Multiselect = true;
// if user select OK, then process for adding images
if (ofd.ShowDialog() == DialogResult.OK)
{
// iterating process for adding all images which is selected by filedialog
foreach (string filename in ofd.FileNames)
{
// now add the picture in active document reference
doc.InlineShapes.AddPicture(filename, 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);
}