3 Replies - 800 Views - Last Post: 24 September 2012 - 01:45 PM Rate Topic: -----

#1 TFenge  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-September 12

An automation process using either MS word or a Rich Text input box.

Posted 23 September 2012 - 02:45 AM

I am fairly new to C# so am still researching, and testing my skills in this programming language.

I am trying to make a program that will be able to detect the font type of each character, and insert a word in front of it, or move to another line, or insert a word after it, depending on the type of font.

I would like to have the text in a text box from a form then have the new document open up in ms word after clicking a button.
This button would convert a normal document with varous fonts into a prescribe document.

How would I go about achieving this?

what sites should I be looking at?

What parts of C# do I need to understand to put this together?

Thanks in advance.

Thomas

Is This A Good Question/Topic? 0
  • +

Replies To: An automation process using either MS word or a Rich Text input box.

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3549
  • View blog
  • Posts: 10,993
  • Joined: 05-May 12

Re: An automation process using either MS word or a Rich Text input box.

Posted 23 September 2012 - 07:37 AM

What do you have so far? Do you have a rough outline of your program design?

Look closely at the RichTextBox documentation in MSDN. You'll probably want the text change notifications to discover when the user is typing or pasting. You'll need the various selection format properties to detect the fonts within a selection. And you'll need the insert and append functions to put in your extra text.

Personally, I wouldn't go into automating Word. I would just have the RichTextBox save its contents as a .RTF file, and then start a word.exe passing in that file.

This post has been edited by Skydiver: 23 September 2012 - 07:37 AM

Was This Post Helpful? 0
  • +
  • -

#3 TFenge  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-September 12

Re: An automation process using either MS word or a Rich Text input box.

Posted 24 September 2012 - 12:51 PM

Personally, I wouldn't go into automating Word. I would just have the RichTextBox save its contents as a .RTF file, and then start a word.exe passing in that file.

Can you go into more detail about how you would achieve this please ?
Why would this be better than automating word?

Thanks
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3549
  • View blog
  • Posts: 10,993
  • Joined: 05-May 12

Re: An automation process using either MS word or a Rich Text input box.

Posted 24 September 2012 - 01:45 PM

RichTextBox.SaveFile(): http://msdn.microsof...y/e4a710b1.aspx
Process.Start(): http://msdn.microsof...y/53ezey2s.aspx

Pass the same file name that was passed to RichTextBox.SaveFile() to Process.Start(). Simple two or three lines of code.

To do the Word automation, you'll have to:
1) Import the Word type libary and generate on Interop assembly (or find the official interop assemblies).
2) Remember to package the interop assembly with your program when its time to ship.
3) Handle runtime errors if Word is not installed on target machine.
4) Create the Word automation object.
5) Tell the automation object to create a new document.
6) For each of the different text and object ranges in the RichTextBox:
a. Get the format ranges within the text/object range
b. Automate Word to insert the text/object
c. Apply the formatting for that range
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1