原創|產品更新|編輯:李顯亮|2021-02-18 10:00:40.893|閱讀 272 次
概述:Aspose.Words for .Net更新至新版本v21.2,此常規的每月版本中有86項改進和修復,包括9項新功能的發布,歡迎下載體驗。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Aspose.Words for .Net是一種高級Word文檔處理API,用于執行各種文檔管理和操作任務。API支持生成,修改,轉換,呈現和打印文檔,而無需在跨平臺應用程序中直接使用Microsoft Word。2021年2月更新來啦,.NET版Aspose.Words更新至v21.2新版本!
主要特點如下:
>>你可以點擊這里下載Aspose.Words for .NET v21.2測試體驗。
| 關鍵 | 概括 | 類別 |
| WORDSNET-21363 | 支持為LINQ Reporting Engine動態添加組合框和下拉列表項 | 新功能 |
| WORDSNET-6146 | 允許從OLE對象提取可見的純文本 | 新功能 |
| WORDSNET11848 | 添加保存選項以模仿MS Word行為或不模仿創建,修改和打印日期 | 新功能 |
| WORDSNET-6125 | 添加選項以將文檔中的圖像導出為SVG格式的HTML | 新功能 |
| WORDSNET-10148 | 提供移動到段落中特定字符的能力 | 新功能 |
| WORDSNET-20863 | 在Azure上將DOCX轉換為PDF時,內容控制日期會更改 | 新功能 |
| WORDSNET-21639 | LegacyMode = false時,Range.Replace引發System.IndexOutOfRangeException | 新功能 |
| WORDSNET-21183 | 將自定義字體樣式設置為“鏈接到主題”字體不起作用 | 新功能 |
| WORDSNET-20546 | ComHelper.Open不會使用Delphi從流中導入RTF | 新功能 |
| WORDSNET-20414 | PdfDocumentReader插件鏡像希伯來語文本 | 增強功能 |
| WORDSNET-9605 | 支持DrawingML 3D效果的渲染 | 增強功能 |
| WORDSNET-15833 | 改善在MS Word 97中創建的渲染形狀線的兼容性 | 增強功能 |
| WORDSNET-10441 | 支持Word 6.0 / 95的圖形對象 | 增強功能 |
| WORDSNET-2799 | 嘗試恢復損壞的進口文件 | 增強功能 |
| WORDSNET-1738 | 在保存DOCX文件期間優化內存使用 | 增強功能 |
| WORDSNET-21652 | 沒有將生成器名稱寫入XamlFixed / XamlFlow / XamlFlowPack / HtmlFixed文檔 | 增強功能 |
完整更新細則請參考:【Aspose.Words for .NET v21.2更新說明】
用例如下:
Document doc = new Document(docPath); SaveOptions saveOptions = new PdfSaveOptions(); saveOptions.UpdateLastPrintedProperty = true; doc.Save(pdfPath, saveOptions);
向Font對象添加了新的公共屬性:

還添加了相應的公共枚舉:

用例:說明如何創建和使用主題樣式。
Document doc = new Document("input.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToDocumentEnd();
builder.Writeln();
// Create some style with theme font properties.
Style style = doc.Styles.Add(StyleType.Paragraph, "ThemedStyle");
style.Font.ThemeFont = ThemeFont.Major;
style.Font.ThemeColor = ThemeColor.Accent5;
style.Font.TintAndShade = 0.3;
builder.ParagraphFormat.StyleName = "ThemedStyle";
builder.Writeln("Text with themed style");
// Get just inserted run.
Run run = (Run)((Paragraph)builder.CurrentParagraph.PreviousSibling).FirstChild;
Console.WriteLine("Theme color: {0}", run.Font.ThemeColor);
Console.WriteLine("Color: {0}\n", run.Font.Color);
Console.WriteLine("TintAndShade: {0:N2}\n", run.Font.TintAndShade);
Console.WriteLine("Theme font: {0}", run.Font.ThemeFont);
Console.WriteLine("Font: {0}\n", run.Font.Name);
Console.WriteLine("Theme font Ascii: {0}", run.Font.ThemeFontAscii);
Console.WriteLine("Font Ascii: {0}\n", run.Font.NameAscii);
Console.WriteLine("Theme font Bi: {0}", run.Font.ThemeFontBi);
Console.WriteLine("Font Bi: {0}\n", run.Font.NameBi);
Console.WriteLine("Theme font EastAsian: {0}", run.Font.ThemeFontFarEast);
Console.WriteLine("Font EastAsian: {0}\n", run.Font.NameFarEast);
Console.WriteLine("Theme font Other: {0}", run.Font.ThemeFontOther);
Console.Write("Font Other: {0}", run.Font.NameOther);
/*
This code example produces the following results:
Theme color: Accent5
Color: Color [Empty]
TintAndShade: 0.30
Theme font: Major
Font: Calibri Light
Theme font Ascii: Major
Font Ascii: Calibri Light
Theme font Bi: Major
Font Bi: Times New Roman
Theme font EastAsian: Major
Font EastAsian: Times New Roman
Theme font Other: Major
Font Other: Calibri Light
*/
用例:介紹如何通過應用主題字體“無”將非主題字體名稱更改為主題字體,反之亦然。
// Create new document with themes.
Document doc = new Document();
doc.Theme.MinorFonts.Latin = "Algerian";
doc.Theme.MinorFonts.EastAsian = "Aharoni";
doc.Theme.MinorFonts.ComplexScript = "Andalus";
// Check original theme font.
Font font = doc.Styles["Normal"].Font;
Console.WriteLine("Originally the Normal style theme font is: {0}\n", font.ThemeFont);
// Apply theme font 'Minor'
font.ThemeFont = ThemeFont.Minor;
Console.WriteLine("'Minor' theme font is applied:");
Console.WriteLine("Theme font: {0}", font.ThemeFont);
Console.WriteLine("Font: {0}\n", font.Name);
Console.WriteLine("Theme font Ascii: {0}", font.ThemeFontAscii);
Console.WriteLine("Font Ascii: {0}\n", font.NameAscii);
Console.WriteLine("Theme font Bi: {0}", font.ThemeFontBi);
Console.WriteLine("Font Bi: {0}\n", font.NameBi);
Console.WriteLine("Theme font EastAsian: {0}", font.ThemeFontFarEast);
Console.WriteLine("Font EastAsian: {0}\n", font.NameFarEast);
Console.WriteLine("Theme font Other: {0}", font.ThemeFontOther);
Console.WriteLine("Font Other: {0}\n\n", font.NameOther);
// Set non-theme font.
font.ThemeFont = ThemeFont.None;
Console.WriteLine("'None' theme font is applied:");
Console.WriteLine("Theme font: {0}", font.ThemeFont);
Console.WriteLine("Font: {0}\n", font.Name);
Console.WriteLine("Theme font Ascii: {0}", font.ThemeFontAscii);
Console.WriteLine("Font Ascii: {0}\n", font.NameAscii);
Console.WriteLine("Theme font Bi: {0}", font.ThemeFontBi);
Console.WriteLine("Font Bi: {0}\n", font.NameBi);
Console.WriteLine("Theme font EastAsian: {0}", font.ThemeFontFarEast);
Console.WriteLine("Font EastAsian: {0}\n", font.NameFarEast);
Console.WriteLine("Theme font Other: {0}", font.ThemeFontOther);
Console.Write("Font Other: {0}\n", font.NameOther);
/*
This code example produces the following results:
Originally the Normal style theme font is: None
'Minor' theme font is applied:
Theme font: Minor
Font: Algerian
Theme font Ascii: Minor
Font Ascii: Algerian
Theme font Bi: Minor
Font Bi: Andalus
Theme font EastAsian: Minor
Font EastAsian: Aharoni
Theme font Other: Minor
Font Other: Algerian
'None' theme font is applied:
Theme font: None
Font: Algerian
Theme font Ascii: None
Font Ascii: Algerian
Theme font Bi: None
Font Bi: Andalus
Theme font EastAsian: None
Font EastAsian: Aharoni
Theme font Other: None
Font Other: Algerian
*/
用例:介紹如何通過應用一些簡單的字體名稱將非主題字體名稱更改為主題字體,反之亦然。
// Create new document with themes.
Document doc = new Document();
doc.Theme.MinorFonts.Latin = "Algerian";
doc.Theme.MinorFonts.EastAsian = "Aharoni";
doc.Theme.MinorFonts.ComplexScript = "Andalus";
// Check original theme font.
Font font = doc.Styles["Normal"].Font;
Console.WriteLine("Originally the Normal style theme font is: {0}\n", font.ThemeFont);
// Apply theme font 'Minor'
font.ThemeFont = ThemeFont.Minor;
Console.WriteLine("'Minor' theme font is applied:");
Console.WriteLine("Theme font: {0}", font.ThemeFont);
Console.WriteLine("Font: {0}\n", font.Name);
Console.WriteLine("Theme font Ascii: {0}", font.ThemeFontAscii);
Console.WriteLine("Font Ascii: {0}\n", font.NameAscii);
Console.WriteLine("Theme font Bi: {0}", font.ThemeFontBi);
Console.WriteLine("Font Bi: {0}\n", font.NameBi);
Console.WriteLine("Theme font EastAsian: {0}", font.ThemeFontFarEast);
Console.WriteLine("Font EastAsian: {0}\n", font.NameFarEast);
Console.WriteLine("Theme font Other: {0}", font.ThemeFontOther);
Console.WriteLine("Font Other: {0}\n\n", font.NameOther);
// Set non-theme font name.
font.Name = "Arial";
Console.WriteLine("Non-themed font name is applied:");
Console.WriteLine("Theme font: {0}", font.ThemeFont);
Console.WriteLine("Font: {0}\n", font.Name);
Console.WriteLine("Theme font Ascii: {0}", font.ThemeFontAscii);
Console.WriteLine("Font Ascii: {0}\n", font.NameAscii);
Console.WriteLine("Theme font Bi: {0}", font.ThemeFontBi);
Console.WriteLine("Font Bi: {0}\n", font.NameBi);
Console.WriteLine("Theme font EastAsian: {0}", font.ThemeFontFarEast);
Console.WriteLine("Font EastAsian: {0}\n", font.NameFarEast);
Console.WriteLine("Theme font Other: {0}", font.ThemeFontOther);
Console.Write("Font Other: {0}", font.NameOther);
/*
This code example produces the following results:
Originally the Normal style theme font is: None
'Minor' theme font is applied:
Theme font: Minor
Font: Algerian
Theme font Ascii: Minor
Font Ascii: Algerian
Theme font Bi: Minor
Font Bi: Andalus
Theme font EastAsian: Minor
Font EastAsian: Aharoni
Theme font Other: Minor
Font Other: Algerian
Non-themed font name is applied:
Theme font: None
Font: Arial
Theme font Ascii: None
Font Ascii: Arial
Theme font Bi: None
Font Bi: Arial
Theme font EastAsian: None
Font EastAsian: Arial
Theme font Other: None
Font Other: Arial
*/
用例:說明如何通過應用主題字體顏色“無”將非主題顏色更改為主題顏色,反之亦然。
Document doc = new Document();
// Check original theme color.
Font font = doc.Styles["Normal"].Font;
Console.WriteLine("Originally the Normal style theme color is: {0} and RGB color is: {1}\n", font.ThemeColor, font.Color);
// Apply theme color.
font.ThemeColor = ThemeColor.Accent2;
Console.WriteLine("'Accent2' theme color is applied:");
Console.WriteLine("Theme color: {0}", font.ThemeColor);
Console.WriteLine("RGB color: {0}\n", font.Color);
// Set theme color back to 'None'.
font.ThemeColor = ThemeColor.None;
Console.WriteLine("Theme color 'None' is applied:");
Console.WriteLine("Theme color: {0}", font.ThemeColor);
Console.WriteLine("RGB color: {0}", font.Color);
/*
This code example produces the following results:
Originally the Normal style theme color is: None and RGB color is: Color [Empty]
'Accent2' theme color is applied:
Theme color: Accent2
RGB color: Color [Empty]
Theme color 'None' is applied:
Theme color: None
RGB color: Color [Empty]
*/
用例:說明如何通過應用一些簡單的RGB顏色將非主題字體名稱更改為主題字體名稱,反之亦然。
Document doc = new Document();
// Check original theme color.
Font font = doc.Styles["Normal"].Font;
Console.WriteLine("Originally the Normal style theme color is: {0} and RGB color is: {1}\n", font.ThemeColor, font.Color);
// Apply theme color.
font.ThemeColor = ThemeColor.Accent2;
Console.WriteLine("'Accent2' theme color is applied:");
Console.WriteLine("Theme color: {0}", font.ThemeColor);
Console.WriteLine("RGB color: {0}\n", font.Color);
// Set simple RGB color.
font.Color = Color.Blue;
font.ThemeColor = ThemeColor.None;
Console.WriteLine("RGB color is applied:");
Console.WriteLine("Theme color: {0}", font.ThemeColor);
Console.WriteLine("RGB color: {0}", font.Color);
/*
This code example produces the following results:
Originally the Normal style theme color is: None and RGB color is: Color [Empty]
'Accent2' theme color is applied:
Theme color: Accent2
RGB color: Color [Empty]
RGB color is applied:
Theme color: None
RGB color: Color [A=255, R=0, G=0, B=255]
*/
用例:說明如何使用Font.TintAndShade屬性。
Document doc = new Document();
Font font = doc.Styles["Normal"].Font;
font.ThemeColor = ThemeColor.Accent6;
font.TintAndShade = -0.25;
Console.WriteLine("TintAndShade is set to {0:N2}", font.TintAndShade);
Console.WriteLine("Theme color: {0}", font.ThemeColor);
Console.WriteLine("RGB color: {0}", font.Color);
/*
This code example produces the following results:
TintAndShade is set to -0.25
Theme color: Accent6
RGB color: Color [Empty]
*/
向FindReplaceOptions對象添加了一個新的公共屬性:
用例:說明如何使用SmartParagraphBreakReplacement屬性。
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create two tables with paragraph and inner table in first cell:
// ┌───────────────────────┐
// │ TEXT1? │
// │ ┌───────────────────┐ │
// │ |? | |
// | └───────────────────┘ │
// └───────────────────────┘
// ┌───────────────────────┐
// │ TEXT2? │
// │ ┌───────────────────┐ │
// │ |? | |
// | └───────────────────┘ │
// └───────────────────────┘
builder.StartTable();
builder.InsertCell();
builder.Write("TEXT1");
builder.StartTable();
builder.InsertCell();
builder.EndTable();
builder.EndTable();
builder.Writeln();
builder.StartTable();
builder.InsertCell();
builder.Write("TEXT2");
builder.StartTable();
builder.InsertCell();
builder.EndTable();
builder.EndTable();
builder.Writeln();
FindReplaceOptions options = new FindReplaceOptions();
// When the following option is set to 'true',
// Aspose.Words will remove paragraph's text completely with its paragraph mark.
options.SmartParagraphBreakReplacement = true;
doc.Range.Replace(new Regex(@"TEXT1&p"), "", options);
// But if the option is set to 'false',
// Aspose.Words will mimic Word and remove only paragraph's text and leaves the paragraph mark intact.
options.SmartParagraphBreakReplacement = false;
doc.Range.Replace(new Regex(@"TEXT2&p"), "", options);
doc.Save("out.docx");
// This code example produces the following results:
// ┌───────────────────────┐
// │ ┌───────────────────┐ │
// │ |? | |
// | └───────────────────┘ │
// └───────────────────────┘
// ┌───────────────────────┐
// │ ? │
// │ ┌───────────────────┐ │
// │ |? | |
// | └───────────────────┘ │
// └───────────────────────┘
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn