Ignore spelling error in DocX file

拟墨画扇 提交于 2019-12-08 09:06:36

问题


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.


回答1:


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.




回答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.




回答3:


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);


来源:https://stackoverflow.com/questions/28549842/ignore-spelling-error-in-docx-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!