473,385 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Word & C#


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!

--
If a "7–11" is open 24 hours a day, 365 days a year, why are there locks
on the door?

—Nick Featherman
Mar 21 '07 #1
8 3170
If the picture pasted over the text, does it means that you can drag
the picture and see the text?

Mar 21 '07 #2
ha*****@gmail.com wrote in news:1174506187.315079.245380
@e1g2000hsg.googlegroups.com:
If the picture pasted over the text, does it means that you can drag
the picture and see the text?

No,

nw.Content.Paste();

selects all the previous content of the document and then
it does the Paste.. so it changes everything to what
is in the clipboard at the moment..
So when I do UNDO in Word I actually see the things that
were before Pasting..

Some kind of overriding the method would be in order but ..
I don't have te certain knowledge to do so..

I believe I'm missing some easy method to insert picture
after last line..

--
If a "7–11" is open 24 hours a day, 365 days a year, why are there locks on
the door?

—Nick Featherman
Mar 21 '07 #3
bob

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!
Mar 21 '07 #4
bob <st**************@cutthis.adriley.co.nzwrote in
news:jo********************************@4ax.com:
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.
I will check it out. thanks bob!
--
If a "7–11" is open 24 hours a day, 365 days a year, why are there locks on
the door?

—Nick Featherman
Mar 21 '07 #5
for the record:

24-7

I used to work at 'Sharis' for years and years and years

and one day we had a gas leak or something; we had to shut down the
store.. and we realized that we didn't have locks on the door.

we had been open almost 10 years without ever shutting down
now re: C# and Office?

WTF; why don't you just use VBA I mean seriously here... Record a
macro; put it in word

and screw C#

On Mar 21, 11:17 am, Bllich <bllich_...@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!

--
If a "7-11" is open 24 hours a day, 365 days a year, why are there locks
on the door?

-Nick Featherman

Mar 22 '07 #6
"Todos Menos [MSFT]" <to**************@hotmail.comwrote in
news:11**********************@e1g2000hsg.googlegro ups.com:
now re: C# and Office?

WTF; why don't you just use VBA I mean seriously here... Record a
macro; put it in word

and screw C#
not that simple, its much more complex than the problem I
described, I need C# .. 'cause it's a segment of a whole system

--
If a "7–11" is open 24 hours a day, 365 days a year, why are there locks on
the door?

—Nick Featherman
Mar 22 '07 #7
it's a SEGMENT OF A SYSTEM?
C# is a kids programming language

'lets all jump on the trendy programming language of the month bus'

ROFL

On Mar 22, 10:31 am, Bllich <bllich_...@DELETEyahoo.comwrote:
"Todos Menos [MSFT]" <todos_menos_m...@hotmail.comwrote innews:11**********************@e1g2000hsg.googleg roups.com:
now re: C# and Office?
WTF; why don't you just use VBA I mean seriously here... Record a
macro; put it in word
and screw C#

not that simple, its much more complex than the problem I
described, I need C# .. 'cause it's a segment of a whole system

--
If a "7-11" is open 24 hours a day, 365 days a year, why are there locks on
the door?

-Nick Featherman

Mar 22 '07 #8
"Todos Menos [MSFT]" <to**************@hotmail.comwrote in
news:11**********************@e65g2000hsc.googlegr oups.com:
it's a SEGMENT OF A SYSTEM?
a part of a system!
not funny at all..
C# is a kids programming language

'lets all jump on the trendy programming language of the month bus'

ROFL
haha, god gives brain to everybody these days
--
If a "7–11" is open 24 hours a day, 365 days a year, why are there locks on
the door?

—Nick Featherman
Mar 23 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Petey | last post by:
Hi there! I am trying to print a document after merging some data into it using PHP COM and it seems to be very tempremental and doesn't work at all over network printers. When I say...
0
by: Chris J | last post by:
Hi all, ] I'm having a problem with Word 2002 when downloading a Word document with IE6. This is in an intranet application, and the download occurs through an ASP that does security checks...
1
by: Donald Nova | last post by:
I am building a system that allows a user to upload a MS Word file, using a HtmlInputFile control, and by using HTTPPostedFile.SaveAs("c:\uploads\myFile.doc") I can save the Word files to disk. ...
2
by: Steve | last post by:
I'm using Visual Studio .NET (not 2003), and am developing a class that works with Word theough the Office PIAs (Interop). I can open word and do things with it programatically, but I can't close...
6
by: Mark Rae | last post by:
Hi, My client has asked me to provide a "quick and dirty" way to export the contents of a DataGrid to both Excel for analysis and Word for editing and printing, so I'm investigating client-side...
3
by: Jay | last post by:
Hi, I need to read word document file in ASP.net and place it in a text box . How to do it ? i tried : Word.Application app = new Word.ApplicationClass(); object nullobj =...
3
by: Bishman | last post by:
Hi, I have some issues with the code below. These are: ONE: In code I open an existing document and 'attach' the Mail Merge data source, but the data is not poulating the merge fields...
2
by: Ola K | last post by:
Hi guys, I wrote a script that works *almost* perfectly, and this lack of perfection simply puzzles me. I simply cannot point the whys, so any help on it will be appreciated. I paste it all here,...
0
by: alivip | last post by:
I write code to get most frequent words in the file I won't to implement bigram probability by modifying the code to do the following: How can I get every Token (word) and ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.