OpenXML的AddAlternativeFormatImportPart是否尊重内联CSS样式?

时间:2018-06-29 20:25:21

标签: c# openxml openxml-sdk

我将HTML导入到word文档中,我将body标签中的宽度设置为max-width:10px,但文本不受影响。

    using (WordprocessingDocument doc = WordprocessingDocument.Open(@"mydoc.docx", true))
    {
      var mainPart = document.MainDocumentPart; 
      string altChunkId = "AltChunkID" + "R" + Guid.NewGuid().ToString();
      MainDocumentPart mainDocPart = doc.MainDocumentPart;
      string html = "<html><head></head> <body style='max-width: 10px;'>" + actualhtml + "</body></html>";

       AlternativeFormatImportPart formatImportPart = 
         document.MainDocumentPart.AddAlternativeFormatImportPart
          (AlternativeFormatImportPartType.Html, altChunkId);

       MemoryStream ms = new MemoryStream(newUTF8Encoding(true).GetPreamble().Concat(Encoding.UTF8.GetBytes(html)).ToArray());
            formatImportPart.FeedData(ms);
            mainDocPart.Document.Body.Append(new Paragraph(
          new Run(new RunProperties(new AltChunk() 
          { Id = altChunkId }), 
           (new AltChunkProperties(new MatchSource() {Val = true })))));


    }

注意:如果我使用上述HTML并在浏览器中打开,则宽度是正确的。

0 个答案:

没有答案