翻譯|產品更新|編輯:李顯亮|2019-07-09 10:24:53.047|閱讀 453 次
概述:Aspose.Words for .NET更新至v19.7,為Markdown格式實現(xiàn)基本的讀寫器,同時實現(xiàn)了檢測SmartArt形狀的功能!接下來我們給大家介紹一下新版中引入的公告API的更改,并用示例實際闡述一下。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Aspose.Words for .NET是一種高級Word文檔處理API,用于執(zhí)行各種文檔管理和操作任務。API支持生成,修改,轉換,呈現(xiàn)和打印文檔,而無需在跨平臺應用程序中直接使用Microsoft Word。通過集成API,開發(fā)人員可以執(zhí)行的一些基本任務,例如設計具有標準郵件合并字段的全功能Microsoft Word報告,幾種常用格式之間的可靠轉換,頁面的高保真渲染,所有文檔元素的格式化等等。
Aspose.Words for .NET更新至v19.7,為Markdown格式實現(xiàn)基本的讀寫器,同時實現(xiàn)了檢測SmartArt形狀的功能!接下來我們給大家介紹一下新版中引入的公告API的更改,并用示例實際闡述一下。>>下載Aspose.Words for .NET最新試用版
Aspose.Words 19.7公共API的更改
在Revision類中添加了以下新屬性:
////// Gets the revision group. Returns null if the revision does not belong to any group. ///////// Revision has no group if revision type is RevisionType.StyleDefinitionChange or /// if the revision is not longer exist in document context (accepted/rejected). ///public RevisionGroup Group
使用案例:
Document doc = new Document(@"source.docx"); foreach (Revision revision in doc.Revisions) { string groupText = revision.Group != null ? "Revision group text: " + revision.Group.Text : "Revision has no group"; Console.WriteLine("Type: " + revision.RevisionType); Console.WriteLine("Author: " + revision.Author); Console.WriteLine("Date: " + revision.DateTime); Console.WriteLine("Revision text: " + revision.ParentNode.ToString(SaveFormat.Text)); Console.WriteLine(groupText); }
暫時支持以下Markdown功能:
增加了新的公開枚舉:
LoadFormat.Markdown SaveFormat.Markdown FileFormat.Markdown
添加了新的TxtSaveOptionsBase類:
////// The base class for specifying additional options when saving a document into a text based formats. ///public abstract class TxtSaveOptionsBase : SaveOptions
一些成員從TxtSaveOptions類移動到TxtSaveOptionsBase類:
////// Specifies the encoding to use when exporting in text formats. /// Default value isEncoding.UTF8'UTF-8' Charset. ///public Encoding Encoding ////// Specifies the string to use as a paragraph break when exporting in text formats. /////////The default value is.///public string ParagraphBreak ////// Specifies whether the program should attempt to preserve layout of tables when saving in the plain text format. /// The default value is false. ///public bool PreserveTableLayout //////Allows to specify whether the page breaks should be preserved during export.///The default value is false.///////// The property affects only page breaks that are inserted explicitly into a document. /// It is not related to page breaks that MS Word automatically inserts at the end of each page. ///public bool ForcePageBreaks ////// Specifies the way headers and footers are exported to the text formats. /// Default value is. ///public TxtExportHeadersFootersMode ExportHeadersFootersMode
功能的實現(xiàn)主要遵循CommonMark規(guī)范。在AW模型中,Markdown功能表示為相應的樣式或直接格式。因此,粗體和斜體表示為Font.Bold和Font.Italic。標題是標題1 - 標題6樣式的段落。引號是樣式名稱中帶有“引用”的段落。HorizontalRule是具有HorizontalRule形狀的段落。
使用案例1:如何生成以下Markdown文檔的重點:
Markdown treats asterisks (*) and underscores (_) as indicators of emphasis. You can write **bold** or *italic* text. You can also write ***BoldItalic***text.
DocumentBuilder builder = new DocumentBuilder(new Document()); builder.Writeln("Markdown treats asterisks (*) and underscores (_) as indicators of emphasis."); builder.Write("You can write "); builder.Font.Bold = true; builder.Write("bold"); builder.Font.Bold = false; builder.Write(" or "); builder.Font.Italic = true; builder.Write("italic"); builder.Font.Italic = false; builder.Writeln(" text. "); builder.Write("You can also write "); builder.Font.Bold = true; builder.Font.Italic = true; builder.Write("BoldItalic"); builder.Font.Bold = false; builder.Font.Italic = false; builder.Write("text."); builder.Document.Save("EmphasesExample.md");
使用案例2:如何使用標題生成以下Markdown文檔:
The following produces headings: # Heading1 ## Heading2 ### Heading3 #### Heading4 ##### Heading5 ###### Heading6 # **Bold Heading1**
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // By default Heading styles in Word may have bold and italic formatting. // If we do not want text to be emphasized, set these properties explicitly to false. builder.Font.Bold = false; builder.Font.Italic = false; builder.Writeln("The following produces headings:"); builder.ParagraphFormat.Style = doc.Styles["Heading 1"]; builder.Writeln("Heading1"); builder.ParagraphFormat.Style = doc.Styles["Heading 2"]; builder.Writeln("Heading2"); builder.ParagraphFormat.Style = doc.Styles["Heading 3"]; builder.Writeln("Heading3"); builder.ParagraphFormat.Style = doc.Styles["Heading 4"]; builder.Writeln("Heading4"); builder.ParagraphFormat.Style = doc.Styles["Heading 5"]; builder.Writeln("Heading5"); builder.ParagraphFormat.Style = doc.Styles["Heading 6"]; builder.Writeln("Heading6"); // Note, emphases are also allowed inside Headings: builder.Font.Bold = true; builder.ParagraphFormat.Style = doc.Styles["Heading 1"]; builder.Writeln("Bold Heading1"); doc.Save("HeadingsExample.md");
使用案例3:如何使用塊引號生成以下Markdown文檔:
We support blockquotes in Markdown: >*Lorem* >*ipsum* The quotes can be of any level and can be nested: >>>Quote level 3 >>>>Nested quote level 4 > >*Back to first level* > ### Headings are allowed inside Quotes
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("We support blockquotes in Markdown:"); builder.ParagraphFormat.Style = doc.Styles["Quote"]; builder.Writeln("Lorem"); builder.Writeln("ipsum"); builder.ParagraphFormat.Style = doc.Styles["Normal"]; builder.Writeln("The quotes can be of any level and can be nested:"); Style quoteLevel3 = doc.Styles.Add(StyleType.Paragraph, "Quote2"); builder.ParagraphFormat.Style = quoteLevel3; builder.Writeln("Quote level 3"); Style quoteLevel4 = doc.Styles.Add(StyleType.Paragraph, "Quote3"); builder.ParagraphFormat.Style = quoteLevel4; builder.Writeln("Nested quote level 4"); builder.ParagraphFormat.Style = doc.Styles["Quote"]; builder.Writeln(); builder.Writeln("Back to first level"); Style quoteLevel1WithHeading = doc.Styles.Add(StyleType.Paragraph, "Quote Heading 3"); builder.ParagraphFormat.Style = quoteLevel1WithHeading; builder.Write("Headings are allowed inside Quotes"); doc.Save("QuotesExample.md");
使用案例4:如何使用水平規(guī)則生成以下Markdown文檔:
We support Horizontal rules (Thematic breaks) in Markdown: -----
DocumentBuilder builder = new DocumentBuilder(new Document()); builder.Writeln("We support Horizontal rules (Thematic breaks) in Markdown:"); builder.InsertHorizontalRule(); builder.Document.Save("HorizontalRuleExample.md");
使用案例5:如何閱讀Markdown文檔:
// This is Markdown document that was produced in example of UC3. Document doc = new Document("QuotesExample.md"); // Let's remove Heading formatting from a Quote in the very last paragraph. Paragraph paragraph = doc.FirstSection.Body.LastParagraph; paragraph.ParagraphFormat.Style = doc.Styles["Quote"]; doc.Save("QuotesModifiedExample.md");
將以下新屬性添加到Shape類:
////// Returns true if this Shape has a SmartArt object. ///public bool HasSmartArt
使用案例:在文檔中使用SmartArt計算多個形狀。
Document doc = new Document(@"input.docx"); int count = 0; foreach (Shape shape in doc.GetChildNodes(NodeType.Shape, true)) { if (shape.HasSmartArt) count++; } Console.WriteLine("The document has {0} shapes with SmartArt.", count);
新的公共屬性TextShaperFactory已添加到LayoutOptions類。
public ITextShaperFactory TextShaperFactory { get; set; }
應通過單獨的nuget-packages提供ITextShaperFactory的實現(xiàn)。具體實現(xiàn)應創(chuàng)建一個表示字體的文本整形器,并計算文本的整形信息。下面是一個用法示例:
public void Test() { // Open a document Document doc = new Document("OpenType.Document.docx"); // When text shaper factory is set, layout starts to use OpenType features. // An Instance property returns static BasicTextShaperCache object wrapping HarfBuzzTextShaperFactory doc.LayoutOptions.TextShaperFactory = Aspose.Words.Shaping.HarfBuzz.HarfBuzzTextShaperFactory.Instance; // Render the document to PDF format doc.Save("OpenType.Document.pdf"); }
添加了一個用于從文本框中獲取父形狀的公共屬性,以允許客戶從鏈接的TextBox中查找鏈接的Shape。
////// Determines whether this TextBox can be linked to the target Textbox. ///public bool IsValidLinkTarget(TextBox target) { } ////// Returns or sets a TextBox that represents the next TextBox in a sequence of shapes. ///public TextBox Next { get; set; } ////// Returns a TextBox that represents the previous TextBox in a sequence of shapes. ///public TextBox Previous { get; } ////// Breaks the forward link for the specified TextBox, if such a link exists. ///////// BreakForwardLink() doesn't break all other links in the current sequence of shapes. /// For example: 1-2-3-4 sequence and BreakForwardLink at the 2-nd textbox will create /// two sequences 1-2, 3-4. ///public void BreakForwardLink() { } ////// Gets a parent shape for the TextBox. ///public Shape Parent { get { return mParent; } }
使用案例:創(chuàng)建從shape1.TextBox到shape2.TextBox的鏈接。
TextBox textBox1 = shape1.TextBox; TextBox textBox2 = shape2.TextBox; if (textBox1.IsValidLinkTarget(textBox2)) textBox1.Next = textBox2;
使用案例:檢查shape.TextBox是序列的頭部,尾部還是中間。
TextBox textBox = shape.TextBox; if ((textBox.Next != null) && (textBox.Previous == null)) { //The head of the sequence. } if ((textBox.Next != null) && (textBox.Previous != null)) { //The Middle of the sequence. } if ((textBox.Next == null) && (textBox.Previous != null)) { //The Tail of the sequence. }
使用案例:破壞shape.TextBox的鏈接。
TextBox textBox = shape.TextBox; // Break a forward link textBox.BreakForwardLink(); // Break a forward link by setting a null textBox.Next = null; // Break a link, which leads to this textbox if (textBox.Previous != null) textBox.Previous.BreakForwardLink();
ASPOSE技術交流QQ群(642018183)已開通,各類資源及時分享,歡迎交流討論!
掃描關注“慧聚IT”微信公眾號,及時獲取最新動態(tài)及最新資訊
本站文章除注明轉載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn