Hi,
Had a bit of a muck around with this.
The following code inserts the bitmap beside the text.
Needs more work obviously. But the key seems to be using the
inlineshapes collection.
I would trample little old ladies underfoot to reach a decent book
that gave advanced use of the word PIA.
Beyond the basic open and insert text it appears there are just
snippets in articles.
Code follows:
hth
Bob
private void button1_Click(object sender, EventArgs e)
{
if (this.oFD1.ShowDialog() == DialogResult.OK)
{
string sDoc;
sDoc = this.oFD1.FileName;
InsertPicture(sDoc);
}
}
void InsertPicture(string sDoc)
{
try
{
word.Application mapp = new word.Application();
mapp.Visible = false;
object template = Type.Missing;
object newTemplate = Type.Missing;
object documentType = Type.Missing;
object optional = Type.Missing;
object visible = false;
object lTrue = true;
object lFalse = false;
object oDoc = sDoc;
Bitmap MyBitmap = new Bitmap("C:\\MyImage.jpg");
word._Document doc2 = mapp.Documents.Open(ref oDoc,
ref optional, ref lTrue, ref lFalse, ref optional,
ref optional, ref optional, ref optional, ref
optional,
ref optional, ref optional, ref lTrue, ref lFalse,
ref optional, ref lTrue);
IEnumerator en = doc2.Paragraphs.GetEnumerator();
en.MoveNext();
word.Paragraph p1 = (word.Paragraph)en.Current;
word.Range r = p1.Range;
object ro = r;
r.InsertAfter("Test String");
//doc2.Content.InsertFile("C:\\ADR Logo.jpg", ref
optional, ref lTrue, ref lFalse, ref lFalse);
doc2.InlineShapes.AddPicture("C:\\ADR Logo.jpg", ref
lFalse, ref lTrue, ref ro);
object saveChanges = true;
object originalFormat = Type.Missing;
object routeDocument = Type.Missing;
doc2.Close(ref saveChanges, ref originalFormat, ref
routeDocument);
mapp.Quit(ref saveChanges, ref originalFormat, ref
routeDocument);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
On Wed, 21 Mar 2007 18:17:31 +0000 (UTC), Bllich
<bl********@DELETEyahoo.comwrote:
>
hello,
I have winForm app and I have some text and pictures that I
want to save into a word file when I read it from a database.
I don't know how many text or pictures do I have for one
value in a database, it varies from record to record..
I've seen some classes on the net, but I want to use one from
Microsoft, so I Added a reference Microsoft Word 9.0 object library
and done:
private void button1_Click(object sender, EventArgs e)
{
Word.DocumentClass nw = new Word.DocumentClass();
nw.Content.InsertAfter("fff");
Bitmap MyBitmap = new Bitmap("C:\\a.jpg");
Clipboard.SetImage(MyBitmap);
nw.Content.Paste();
Clipboard.Clear();
nw.Save();
}
and I don't see text
"fff"
when Word window comes up, I just see the "a.jpg" image...
though when I do - undo (Ctrl+Z), I get the "fff"
so I know it pasted the image over the text!
I know that using clipboard is out of the question ;)
and obvieously doesn't work..
Please help!