Ignore spelling error in DocX file
Asked Answered
C

3

0

Using OpenXML, I'm inserting some text into a document that I know will be marked as incorrectly spelled (because it's a product name) and will be marked with the angry red line/squiggly when the file is opened in Word. How can I mark the XML so that it knows that the spelling is correct for that word?

I've tried messing around with ProofError, putting it in various places with relation to my paragraph and my run and with different values for type, but can't figure out if there's a way to use that to mark something as not an error.

Charged answered 16/2, 2015 at 20:33 Comment(0)
A
2

ProofError is to actually mark the text run with the angry red line. To exclude the text in a run for spell/ grammar checks use noProof.

Lets say you got a word in a run as:

<w:p>
  <w:r>
    <w:t>Cfgcfgcyhgjguih</w:t>
   </w:r>
</w:p>

You can tell the spell/grammar checking engine of the word client to ignore this word for checks, in the run properties as below

<w:p>
  <w:rPr>
    <w:noProof w:val="true"/>
  </w:rPr>
  <w:r>
    <w:t>Cfgcfgcyhgjguih</w:t>
  </w:r>
</w:p>

You can also globally disable the spell/grammar checking engine to stop looking for errors in a document by specifying so in the documents settingspart as:

<w:proofState w:spelling="clean" w:grammar="clean"/>

The above prevents the client's spell/grammar checking to kick-in until the next edit made to the document.

Hope this helps.

Adessive answered 17/2, 2015 at 14:13 Comment(1)
That did it. Thanks. Don't know why I couldn't find that yesterday.Charged
T
2

If you're using the SDK, you can do the following to hide all spelling errors in the entire document:

var hideSpellingErrors = new HideSpellingErrors();            
hideSpellingErrors.Val = OnOffValue.FromBoolean(true);
document.MainDocumentPart.Document.Append(hideSpellingErrors);

This can be useful when - as in my case - you auto-generate a document from a template where you know all text is correctly spelled. Plus, when the content you add dynamically come from an external source or is full of domain-specific words - like pharmaceutical terms.

Trackandfield answered 13/6, 2018 at 8:4 Comment(0)
C
1

Just Added Snippet of code in c#.

creating instance of NoProof class and setting its value to true, then appending to instance of RunProperties

   NoProof np = new NoProof();
   np.Val = OnOffValue.FromBoolean(true);
   runProp.Append(np);
Commissary answered 6/6, 2016 at 19:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.