问题描述
我想通过 Aspose.Word 或 OpenXml Word (WordprocessingDocument) (C#) 更改方向。方法如下:
private static void AddHtmlToDoc()
{
var html = @"<html> <a href=""http://www.google.com/"" style=""color:#FF0000;"">Red Link</a><a href=""http://www.google.com/"" style=""color:#00FF00;"">Blue Link</a > </ html > ";
Aspose.Words.Document docAspose = new Words.Document();
Words.DocumentBuilder b1 = new DocumentBuilder(docAspose);
b1.InsertHtml(html);
docAspose.Save(dir2);
WordprocessingDocument doc = WordprocessingDocument.Open(dir2,true);
var documentPart = doc.MainDocumentPart.Document.Body;
Console.ReadKey();
}
我该怎么做?
解决方法
我找到了解决方案。 对于从右到左的方向,我们必须使用以下代码:
b1.CurrentParagraph.ParagraphFormat.Bidi
不幸的是我使用此代码之前
b1.InsertHtml(html);
但是当我在顶线之后使用它时,它确实有效。 那么以下方法有效:
private static void AddHtmlToDoc()
{
var html = @"<html> <a href=""http://www.google.com/"" style=""color:#FF0000;"">Red Link</a><a href=""http://www.google.com/"" style=""color:#00FF00;"">Blue Link</a > </ html > ";
Aspose.Words.Document docAspose = new Words.Document();
Words.DocumentBuilder b1 = new DocumentBuilder(docAspose);
b1.InsertHtml(html);
b1.CurrentParagraph.ParagraphFormat.Bidi = true;
docAspose.Save(dir2);
Console.ReadKey();
}