Click here to Skip to main content
15,885,546 members
Home / Discussions / C#
   

C#

 
GeneralRe: Need a multiline listview Windows Forms control Pin
Roman R.3-Jan-04 17:27
Roman R.3-Jan-04 17:27 
GeneralRe: Need a multiline listview Windows Forms control Pin
hammackj3-Jan-04 21:55
hammackj3-Jan-04 21:55 
GeneralRe: Need a multiline listview Windows Forms control Pin
Roman R.4-Jan-04 5:49
Roman R.4-Jan-04 5:49 
GeneralRe: Need a multiline listview Windows Forms control Pin
hammackj4-Jan-04 10:49
hammackj4-Jan-04 10:49 
GeneralCustom MessageBox buttons Pin
Broken God3-Jan-04 6:24
Broken God3-Jan-04 6:24 
GeneralRe: Custom MessageBox buttons Pin
Colin Angus Mackay3-Jan-04 6:51
Colin Angus Mackay3-Jan-04 6:51 
GeneralRe: Custom MessageBox buttons Pin
jconwell3-Jan-04 18:05
jconwell3-Jan-04 18:05 
GeneralUsing Word with C# Pin
Stephane David3-Jan-04 5:43
Stephane David3-Jan-04 5:43 
I've tried to used this article http://www.codeproject.com/csharp/CsAutomateWord.asp?target=Word to create a character sheet.

I have a CCharacter class, that contains all information about a character, and I want to generate a MS Word document with these information.

So I've created .dot document, with thinks like
Name _Name_ Age _Age_
in arrays (I've tried also without the array, directly in the text). _XXX_ is code that I will use for replacement.

Now, to the code:

// Create a Word application
Word.ApplicationClass vk_word_app = new Word.ApplicationClass();
// Open the .dot
object FileName =Directory.GetCurrentDirectory()+"\\Models\\Sheet.dot";
Word.Document vk_my_doc = vk_word_app.Documents.Open(...
// Create a new document
Word.Document vk_new_doc = vk_word_app.Documents.Add((...
// Copy the .dot into the new document
vk_my_doc.Select();
vk_word_app.Selection.Copy();
vk_new_doc.Select();
vk_word_app.Selection.PasteAndFormat(Word.WdRecoveryType.wdPasteDefault);
// close the .dot
vk_my_doc.Close( ref vk_false, ref vk_missing, ref vk_missing );

All the previous steps work. I get a new document, build from my template.

Now, I'd like to fill it with actual information. So I do this

// Select the new doc
vk_new_doc.Select();
// Define some variable
object vk_false = false;
object vk_true = true;
object vk_num = Word.WdFindWrap.wdFindStop;
object vk_find = "_Nom_";
object vk_replaceWith = Name_Familly; // This one is a member of CCharacter class
object vk_replace = Word.WdReplace.wdReplaceOne;

// Try to replace the text
vk_word_app.Selection.Find.Execute( ref vk_find,
ref vk_false, ref vk_false,
ref vk_false, ref vk_false, ref vk_false, ref vk_true,
ref vk_num, ref vk_false,
ref vk_replaceWith, ref vk_replace, ref vk_false,
ref vk_false, ref vk_false, ref vk_false );

And... it doesn't work.

I got this error:

System.Runtime.InteropServices.COMException (0x800706F7): Le relais a reçu des données incorrectes.
at Word.Find.Execute(Object& FindText, Object& MatchCase, Object& MatchWholeWord, Object& MatchWildcards, Object& MatchSoundsLike, Object& MatchAllWordForms, Object& Forward, Object& Wrap, Object& Format, Object& ReplaceWith, Object& Replace, Object& MatchKashida, Object& MatchDiacritics, Object& MatchAlefHamza, Object& MatchControl)

My form close, the word doc stays opened.


"Le relais a reçu des données incorrectes" would translate as "incorrect data received".


Any idea of a way to solve this would be greatly welcomed!
GeneralRe: Using Word with C# Pin
Heath Stewart3-Jan-04 8:03
protectorHeath Stewart3-Jan-04 8:03 
GeneralRe: Using Word with C# Pin
Stephane David3-Jan-04 9:58
Stephane David3-Jan-04 9:58 
GeneralRe: Using Word with C# Pin
Nick Parker3-Jan-04 10:05
protectorNick Parker3-Jan-04 10:05 
GeneralRe: Using Word with C# Pin
Stephane David3-Jan-04 10:16
Stephane David3-Jan-04 10:16 
GeneralRe: Using Word with C# Pin
Heath Stewart3-Jan-04 10:58
protectorHeath Stewart3-Jan-04 10:58 
GeneralRe: Using Word with C# Pin
Stephane David3-Jan-04 19:00
Stephane David3-Jan-04 19:00 
GeneralRe: Using Word with C# Pin
Heath Stewart3-Jan-04 19:02
protectorHeath Stewart3-Jan-04 19:02 
GeneralRe: Using Word with C# Pin
Stephane David3-Jan-04 19:40
Stephane David3-Jan-04 19:40 
GeneralRe: Using Word with C# Pin
Heath Stewart3-Jan-04 19:42
protectorHeath Stewart3-Jan-04 19:42 
GeneralRe: Using Word with C# Pin
Stephane David3-Jan-04 19:49
Stephane David3-Jan-04 19:49 
GeneralRe: Using Word with C# Pin
Stephane David8-Jan-04 11:04
Stephane David8-Jan-04 11:04 
GeneralDisabled toolbar images Pin
richjm3-Jan-04 2:47
richjm3-Jan-04 2:47 
GeneralRe: Disabled toolbar images Pin
Heath Stewart3-Jan-04 7:38
protectorHeath Stewart3-Jan-04 7:38 
Questionstart menu? Pin
warelord3-Jan-04 0:22
warelord3-Jan-04 0:22 
AnswerRe: start menu? Pin
leppie3-Jan-04 1:37
leppie3-Jan-04 1:37 
AnswerRe: start menu? Pin
Jan R Hansen3-Jan-04 1:37
Jan R Hansen3-Jan-04 1:37 
AnswerRe: start menu? Pin
Steve McLenithan3-Jan-04 6:50
Steve McLenithan3-Jan-04 6:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.