2011-05-26 4 views
0

J'ai un éditeur html dans ma page. Je veux stocker le texte dans le document de texte avec les styles comme gras, italique, etc .. Im en utilisant ce code à écrire dans le document de mot ..Éditeur html - Supprimer les balises

object strTextToWrite = txtdocument.Text.Trim(); 

     oWordApplic = new Word.ApplicationClass(); 
     object missing = System.Reflection.Missing.Value; 
     oDoc = oWordApplic.Documents.Add(ref missing, ref missing, ref missing, ref missing); 
     oDoc.Activate(); 
     string test = StripTagsCharArray(txtdocument.Text);   
     string test2 = test.Replace(" ", " "); 
     oWordApplic.Selection.TypeText(test2); 
object path =Server.MapPath("~/Documents/"+txtfrom_name.Text + ".doc"); 
     oDoc.SaveAs(ref path, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, 
      ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); 
     oDoc.Close(ref missing, ref missing, ref missing); 
     oWordApplic.Application.Quit(ref missing, ref missing, ref missing); 

La fonction split est

public static string StripTagsCharArray(string source) 
    { 
     char[] array = new char[source.Length]; 
     int arrayIndex = 0; 
     bool inside = false; 

     for (int i = 0; i < source.Length; i++) 
     { 
      char let = source[i]; 
      if (let == '<') 
      { 
       inside = true; 
       continue; 
      } 
      if (let == '>') 
      { 
       inside = false; 
       continue; 
      } 
      if (!inside) 
      { 
       array[arrayIndex] = let; 
       arrayIndex++; 
      } 
     } 
     return new string(array, 0, arrayIndex); 
    } 

maintenant im obtenir le texte en clair sans gras, italique .. J'ai besoin de gras, italique, souligner les fonctions dans mon document Word ,,, S'il vous plaît aidez-moi

Répondre

0

Un ancien format de document Word est-il nécessaire? Dans le cas où docx (format Word 2007/2010) est correct pour vous, puis essayez de convertir html en mot en utilisant MS Open XML SDK et this open source component. Il y a enough information pour comprendre comment utiliser ces deux composants. Et je dirais que c'est beaucoup plus rapide et plus sûr que les dll Interop avec des classes COM comme Word.ApplicationClass

Questions connexes