2011-08-22 3 views

Répondre

1

J'ai trouvé une solution. Il était seulement nécessaire de casser la chaîne et pour chaque chaîne créer un paragraphe avec le formatage, sinon les éléments sont créés comme OpenXmlUnknownElement.

XDocument customXml = GenerateXmlForReport(report); 
      String customXmlId = AddCustomXml(document, customXml); 
      DataBind(document, customXml, customXmlId); 
      document.MainDocumentPart.Document.Body.GetFirstChild<SdtBlock>().RemoveAllChildren(); 
      string[] lines = Regex.Split(report.ReportTextBody, "</line>"); 
      foreach (var line in lines) 
      { 
       Paragraph p = new Paragraph(); 
       ParagraphProperties paragraphProperties1 = new ParagraphProperties(); 
       ParagraphStyleId paragraphStyleId1 = new ParagraphStyleId() { Val = "BodyText" }; 
       ParagraphMarkRunProperties paragraphMarkRunProperties1 = new ParagraphMarkRunProperties(); 
       RunFonts runFonts1 = new RunFonts() { Ascii = "Arial", HighAnsi = "Arial" }; 
       paragraphMarkRunProperties1.Append(runFonts1); 
       paragraphProperties1.Append(paragraphStyleId1); 
       paragraphProperties1.Append(paragraphMarkRunProperties1); 
       RunProperties runProperties1 = new RunProperties(); 
       RunStyle runStyle1 = new RunStyle() { Val = "PlaceholderText" }; 

       runProperties1.Append(runStyle1); 
       Run run = new Run(); 
       Text txt = new Text(line); 
       run.Append(txt); 
       p.Append(run); 
       document.MainDocumentPart.Document.Body.GetFirstChild<SdtBlock>().Append(p); 

      }     
Questions connexes