Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. Using Word i nC#

Using Word i nC#

Scheduled Pinned Locked Moved COM
csharpcomdata-structureshelpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stephane David
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups