如何通过 C# 在 aspose word 中更改 word office 段落方向

问题描述

我想通过 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();
}

我该怎么做?

enter image description here

解决方法

我找到了解决方案。 对于从右到左的方向,我们必须使用以下代码:

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();
}

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...