index > Visual Studio Tools for Office > font formating

font formating

hi all

i'm sending some data to a word document like this:

Microsoft.Office.Interop.Word.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();

wordApp.Visible = true;

object readOnly = true;

object isVisible = true;

object missing = System.Reflection.Missing.Value;

object document = settingsfolder + "\\" + filename;

Microsoft.Office.Interop.Word.Document oDoc = wordApp.Documents.Open(ref document,

ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing,

ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,

ref missing, ref missing, ref missing);

oDoc.Activate();

wordApp.Selection.TypeText(DateTime.Now.ToLongDateString());

wordApp.Selection.TypeParagraph();

wordApp.Selection.TypeParagraph();

wordApp.Selection.TypeText(title + " " + clientName +" "+clientSurname);

wordApp.Selection.TypeParagraph();

wordApp.Selection.TypeText(clientAddress);

wordApp.Selection.TypeParagraph();

wordApp.Selection.TypeText(clientTown + " " + clientPostalCode);

wordApp.Selection.TypeParagraph();

wordApp.Selection.TypeParagraph();

wordApp.Selection.TypeText("Dear " + clientName + " " + clientSurname);

now, how to set font size and names?

thanks in advance.




##
PedroSimao

Hi Pedro

Technically, you should address questions concerning any Office object model to the appropriate group listed in the "Please Read First" posting at the top of this forum

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=174275&SiteID=1

This forum is dedicated to discussions concerning the VSTO technology, which it appears you aren't using.

I can tell you that you ought to be working with RANGES in Word, not with the Selection object. Ranges give you more flexibility, they're faster and the screen won't "flash" as much since Word won't be mimicking user actions. When you have a Range, you have an object you can store in memory and manipulate at any time. Your multiple lines of code can be condensed into one command, and afterwards the Range object can be formatted "at leisure". For example:

Word.Range rng = oDoc.Content;
rng.Text = DateTime.Now.ToLongDateString() + "\n\n" + title + " " + clientName +" "+clientSurname + "\n" + clientAddress + "\n" + clientTown + " " + clientPostalCode;

rng.Font.Name = "Arial";
rng.Font.Size = 11;

//Position the range to just after the current range content
object directEnd = WdCollapseDirection.wdCollapseEnd;
rng.Collapse(ref directEnd);

rng.Text = "\n\nDear " + clientName + " " + clientSurname

rng.Font.Name = "Bookman Antiqua";
rng.Font.Size = 12;




-- Cindy Meister (Word MVP)
Cindy Meister
thank you Cindy Meister
PedroSimao
reply 3

You can use google to search for other answers

 

More Articles

• XP Style of WinForms using VSTO
• How can i add some contents chosen from building blocks to the do...
• Update the thread "Now Available: Visual Studio Tools for Of...
• VSTO Word Template & Custom Menus/Toolbars Best Practices
• VBA + VSTO
• WebService as DataSource for ListObjects
• InfoPath - WebService - BizTalk
• DrawImage and DrawLine and ActionsPaneControl
• xmlnode misbehavior in Word
• Excel PIA Problems
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Managed Code Extension and Active Docume
• Manipulating Excel
• Excel Instances Creating Multiple Custom
• How to Programmatically Retrieve Documen
• Adding dynamic menus and events in Outlook
• Disable VBA script "on click"
• Using a template on a template
• MicroSoft Office Word 12.0 dll gives Pro
• Add a control to PowerPoint slides
• Dynamic Range in Excelsheet
• Embed and Automate a Word Document by Us
• adding a button to the email message win
• VSTO SE Beta for office 2003
• Unspecified Error when trying to access
• Ability to lock worksheet

Hot Articles

• Publishing Custom Forms in Outlook
• Error while locking columns & cells
• save a document without the action pane
• ServerDocument failure dependant on the
• Dynamic Code Generation
• Best of Forum Q&A
• Excel SaveAs not working properly
• install addin in all office applications
• Try this a different way... which VS ver
• Global Address list - microsoft outlook
• VSTO Outlook Addin - Why doesn't my Prop
• VSTO Outlook Addin Setup on Client Works
• Edit box on toolbar
• VSTO - Outlook - Unload addin
• display image in listobject

Recommend Articles

• VSTO 2005 Install before VS 2005
• Serious Error while deleting the row
• ExcelSheet Deletion
• Retrieve all calendar items.
• Another deployment problem
• VSTO Excel Deployment; Need Help; Please
• Outlook 2003 Addin doesn't work on Windo
• show excel chart on a form in excel 2000.
• VSTO 2005 Beta2 ServerDocument sample in
• xsd document not "protected" f
• Generating New Word Doc from C# Applicat
• VSTO property for hidden Excel sheets
• VSTO deployment ??light solution.
• Is it possible to implement this button?
• Manipulating Excel