У меня есть код для добавления текста html к моему документу docx. и это нормально, но это не работает с некоторыми тегами, и я не знаю почему.
Исправлено, если я получил fileStream, но мне не нужно его использовать, я получаю html данные в виде строки. Пожалуйста, помогите
using (WordprocessingDocument myDoc =
WordprocessingDocument.Open("Test2.docx", true))
{
//it works
//string html1 =
// @"<html>
// <head/>
//<body>
// hi
//</body>
// </html>";
//it doesn't work
var html = @"<html>
<head/>
<body>
<p><em>text</em></p>
</body>
</html>";
MainDocumentPart mainDocumenPart = myDoc.MainDocumentPart;
string htmlSectionID = "myhtmlID";
AlternativeFormatImportPart formatImportPart = mainDocumenPart
.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.Html, htmlSectionID);
//IT DOESN'T WORKS with html, but works with html1
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(html));
//if I get the same html string by open a file, it works
//using (FileStream fs = File.Open("Test.html", FileMode.Open))
formatImportPart.FeedData(ms);
AltChunk altChunk = new AltChunk();
altChunk.Id = htmlSectionID;
mainDocumenPart.Document.Body.Append(altChunk);
myDoc.MainDocumentPart.Document.Save();
}