utilisation du correcteur de word en javascript
Bonjour,
je développe un éditeur de texte en HTML & javascript qui sera utilisé sur différents postes.
J'utilise le correcteur de word.
je souhaiterais utiliser le correcteur en fonction de la langue du document qui est écrit.
le problème est que lorsque la langue demandée n'est pas installée sur l'ordi, word fini le correcteur comme s'il n'y a aucune fautes dans le document.
Je souhaite donc savoir comment, en javascript, connaitre la liste des langues présentes sur l'ordi de l'utilisateur, afin de pouvoir l'avertir que le correcteur ne pourra pas faire sa correction.
J'espere avoir été assez clair.
Par avance merci.
pour info voici mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
function correcteurOrthographique(noeud)
{
// Lancement de Word
var langID;
var oWord = new ActiveXObject('Word.Application');
oWord.Visible = false;
oWord.WindowState = 2;
// Configuration du correcteur orthographique
oWord.Application.Options.CheckGrammarWithSpelling = true;
oWord.Application.Options.SuggestSpellingCorrections = true;
oWord.Application.Options.IgnoreUppercase = true;
oWord.Application.Options.AutoFormatDeleteAutoSpaces = false;
oWord.Application.ScreenUpdating = true;
switch(document.getElementById('edth_ppt').idt.substring(27))
{
case "GB":
langID = 2057;
break;
case "ES":
langID = 3082;
break;
case "AL":
langID = 1031;
break;
default:
langID = 1036;
break;
}
// Lancement de la correction du texte
var oWordDoc = oWord.Documents.Add();
corriger(noeud,oWord,oWordDoc,langID);
//alert("fin corriger");
// Liberation de Word
oWord.Documents.Close(0);
oWordDoc = null;
oWord.Top = 147;
oWord.Application.Quit();
oWord = null;
}
function corriger(noeud, oWord, oWordDoc, langID)
{
var wdDialogToolsSpellingAndGrammar = 828;
var nbBlancDeb;
var nbBlancFin;
var result;
for(var i=0; result!=0 && i<noeud.childNodes.length; i++)
{
if(noeud.childNodes[i].nodeType == 1)
{
if(noeud.childNodes[i].nodeName != "SPAN" || noeud.childNodes[i].edth_type != "var")
result = corriger(noeud.childNodes[i],oWord, oWordDoc, langID);
}
else
{
oWord.Visible = false;
oWord.WindowState = 2;
oWord.Top = 1000;
var textLine = noeud.childNodes[i].nodeValue;
var texteEncode;
nbBlancDeb = noeud.childNodes[i].nodeValue.length - (ltrim(noeud.childNodes[i].nodeValue)).length;
nbBlancFin = noeud.childNodes[i].nodeValue.length - (rtrim(noeud.childNodes[i].nodeValue)).length;
textLine = trim(textLine);
var firstLetterInUpperCase = (textLine.substring(0,1) == textLine.substring(0,1).toUpperCase())?true:false;
if (!firstLetterInUpperCase) textLine = textLine.substring(0,1).toUpperCase() + textLine.substring(1);
oWordDoc.Select();
oWord.Selection.Text = textLine;
if ((oWord.Selection.Range.SpellingErrors.Count > 0)||(oWord.Selection.Range.GrammaticalErrors.Count > 0))
{
oWord.Selection.LanguageID = langID;
result = oWord.Dialogs.Item(wdDialogToolsSpellingAndGrammar).Show();
oWordDoc.Select();
textLine = oWord.Selection.Text;
if (!firstLetterInUpperCase) textLine = textLine.substring(0,1).toLowerCase() + textLine.substring(1);
texteEncode = encodeURI(textLine);
texteEncode = texteEncode.replace(/%0D/g,"");
textLine = decodeURI(texteEncode);
textLine = blanc(nbBlancDeb) + textLine + blanc(nbBlancFin);
textLine = textLine.replace(/<BR>/g, "");
noeud.childNodes[i].nodeValue = textLine;
}
}
}
return result;
} |