Pulling Fonts from Word
Sorry if this is in the wrong forum. I have the following problem:
I have an app that generates plain-text reports and then pushes the plain text into Word to leverage styles and formatting and other Word nice-ities. Now the client would like to be able to change the look of text from the application. My plan is to define Styles in their Word template, pull them back into the app, and use their attributes to format text in a rich text box. Obviously there are a lot of tricky things to deal with here, but the one I am presently stuck on is how to assign the properties from the Word style to the text in the rich text box? Here's what I have:
Dim appword As New Word.ApplicationClass
appword.Documents.Add()
Dim docword As Word.Document = appword.ActiveDocument
Dim wdstyle As Word.Styles = docword.Styles
Dim wdfont As Word.Font
Try
wdfont = wdstyle.Item("Heading 1").Font
*RichTextBox1.SelectionFont = wdfont
Catch ex As Exception
MsgBox(ex.Message)
End Try
docword.Close(False)
appword.Quit()
The idea is that the user puts text in the rich text box, selects it, right clicks, and picks the style from the context menu. Then format the text using the coinciding style from the Word template. Right now it always throws "Specified Cast is not valid" on the line with the asterisk. Basically I'm looking for a way to convert a Word.Font into a System.Drawing.Font. Any help is greatly appreciated. I don't need working code or anything, just to be pointed in the right direction.
Thanks
Mike
|