Thanks a lot Nicholas! Do you know how to do it for late-binding though?
I'm having a hard time finding any examples of this. I'm not sure what
string to pass to InvokeMember to get the Range. And then once I have the
range, I'm not sure what string to pass to InvokeMember to tell it to
format
for double spacing or page breaks.
To give you an idea of how I'm doing it, here is how I create the
document,
make it visible, set the font size, set it to bold, and write out some
text.
It's different than standard MS Word Automation and neccessary because it
needs to work with Office 97 and up:
Type WordType = Type.GetTypeFromProgID("Word.Application");
Object WordApp = Activator.CreateInstance(WordType);
WordType.InvokeMember("Visible", BindingFlags.SetProperty, null, WordApp,
new object[]{true});
Object WordDoc = WordApp.GetType().InvokeMember( "Documents",
BindingFlags.GetProperty, null, WordApp, null );
WordDoc = WordDoc.GetType().InvokeMember( "Add",
BindingFlags.InvokeMethod,
null, WordDoc, null );
Object WordSelection = WordApp.GetType().InvokeMember( "Selection",
BindingFlags.GetProperty, null, WordApp, null );
Object WordFont = WordSelection.GetType().InvokeMember( "Font",
BindingFlags.GetProperty, null, WordSelection, null );
WordType.InvokeMember("Size", BindingFlags.SetProperty, null, WordFont,
new
object[]{10});
WordType.InvokeMember("Bold", BindingFlags.SetProperty, null, WordFont,
new
object[]{true});
WordType.InvokeMember("TypeText", BindingFlags.InvokeMethod, null,
WordSelection, new object[]{"MY WONDERFUL TEXT"});
"Nicholas Paldino [.NET/C# MVP]" <
[email protected]>
wrote
in
message John,
In order to insert a page break, you have to get a range of text
where
you want to insert the page break, and then make the call:
// range is the range of text.
range.InsertBreak(wdPageBreak);
I'm not sure which enumeration wdPageBreak is from (or if it is
defined
as a static variable on a type), but that's the value you need.
As for the double spacing, you want to take the range of text, and do
this:
// Double space the range of text:
range.ParagraphFormat.LineSpacingRule = wdLineSpaceDouble;
Once again, you will have to find the type that wdLineSpaceDouble is
associated with.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Hey folks,
I'm creating an MS Word document in a C# Windows application. Because
the
client base has so many different versions of Word they are using, I
opted
to go with late binding to create the document.
**Everything works great, but I can't figure out how to do 2 things:
1) Double Spacing
2) Insert a Page Break
Anyone got any sample code or know of a good page on the web that shows
how
to do this?
(BTW...Posted similar message last week without a response. Sorry for
the
double post)