GrapeCity Word 文檔 (GcWord)
支持 Office Math 函數(shù)以及轉(zhuǎn)換為 MathML
GcWord 現(xiàn)在支持在 Word 文檔中創(chuàng)建和編輯 Office Math 內(nèi)容。GcWord 中的 OMath 支持包括完整的 API,可處理科學(xué)、數(shù)學(xué)和通用 Word 文檔中廣泛使用的數(shù)學(xué)符號(hào)、公式和方程。以下是通過 OMath 支持引入的新 API 的主要亮點(diǎn) -
- 用于在 GcWord 中表示 Office Math 內(nèi)容的兩個(gè)主要類是OMathParagraph和OMath。OMathParagraph表示包含 Office Math 內(nèi)容的段落,而OMath表示內(nèi)聯(lián) Office Math 區(qū)域,可以包含在 OMathParagraph 或常規(guī)段落中。
- 提供專門的類(例如OMathFunction、OMathEquationArray、OMathRadical等)來(lái)表示 OMath 區(qū)域內(nèi)的各種數(shù)學(xué)結(jié)構(gòu)。這些類派生自公共抽象OMathStruct基礎(chǔ)。
- 新的 RangeBase 屬性提供對(duì) Office Math 內(nèi)容的訪問:OMathParagraphs、OMaths、OMathStructs、OMathElements和OMathMatrixRows。
- 為了輕松添加 MS Word 支持的內(nèi)置方程,在RangeBase、OMathParagraph、OMath和OMathElement類上提供了方便的 Add/Insert 方法,它們接受標(biāo)識(shí)所需方程的OMathBuiltInEquation枚舉值。
- 包含一個(gè)實(shí)用程序MathMLConverter類,以便在 GcWord OMath 內(nèi)容和 MathML 之間輕松轉(zhuǎn)換。
以下代碼使用OMath類及其函數(shù)將方程添加到 Word 文件中:
var sampleDoc = new GcWordDocument();
var om = sampleDoc.Body.AddParagraph().AddOMathParagraph().AddOMath();
om.AddRun("Γ").Font.Italic = false;
om.AddDelimiter(new string[] { "z" });
om.AddRun("=");
var nary = om.AddNary("", "0", "∞", "∫");
nary.Base.AddSuperscript("t", "z-1");
nary.Base.AddSuperscript("e", "-t");
nary.Base.AddRun("dt");
om.AddRun("=");
var frac = om.AddFraction();
var superscript = frac.Numerator.AddSuperscript("e", "-");
superscript.Superscript.AddRun("γ").Font.Bidi = true; //w:cs was used
superscript.Superscript.AddRun("z");
frac.Denominator.AddRun("z");
nary = om.AddNary("", "k=1", "∞", "∏");
superscript = nary.Base.AddSuperscript("", "-1");
var delimiter = superscript.Base.AddDelimiter();
var item = delimiter.Items.Add();
item.AddRun("1+");
item.AddFraction("z", "k", null);
superscript = nary.Base.AddSuperscript("e", "z");
superscript.Superscript.AddRun("/").OMathFormat.IsLiteral = true; //m:lit used.
superscript.Superscript.AddRun("k");
om.AddRun(", γ≈0.577216");
sampleDoc.Save("MathEquation.docx");
新的幫助程序“Add<content object>(..)”方法可將內(nèi)容添加到 Word 文檔。
到目前為止,可以通過一種或多種方式在 Word 文檔中添加內(nèi)容對(duì)象。例如,可以通過段落創(chuàng)建構(gòu)造函數(shù)調(diào)用 - doc.Body.Paragraphs.Add(“text“) 或使用 paragraph.GetRange().Runs.Add(…) 添加段落的“runs”并創(chuàng)建這次通話之前的一段話。然而,在 v6.2 版本中,現(xiàn)在可以使用新的“AddRun(..)”方法直接在段落元素上創(chuàng)建連續(xù)句。
同樣,GcWord 為 Word 文檔中的每種內(nèi)容添加了“?Add?< content object>(..)”方法,以便它們可以直接添加到其父對(duì)象中,從而使代碼更短、更高效。現(xiàn)在可以使用新的 Helper 方法將每個(gè)對(duì)象直接添加到 Word 文檔中的不同部分或內(nèi)容對(duì)象:
- 桌子
- 段落
- 內(nèi)容控制
- 簡(jiǎn)單字段
- 超鏈接
- 雙向覆蓋
- OM數(shù)學(xué)段落
- 奧馬斯
- 跑步
- 腳注
- 尾注
- 復(fù)雜場(chǎng)
- 團(tuán)體形態(tài)
- 形狀
- 圖片
- 墨形
看一下下面的代碼,它使用新方法“?AddRun(..)?”將段落運(yùn)行添加到段落中:
GcWordDocument doc = new GcWordDocument();
// add paragraph with default formatted text
var p = doc.Body.AddParagraph("text1");
// add another text into the paragraph formatted with "Heading1" style
// previously code should look like: p.GetRange().Runs.Add("text2", doc.Styles[BuiltInStyleId.Heading1]);
// now the code is shorter and more clear what content can be added into the object
p.AddRun("text2", doc.Styles[BuiltInStyleId.Heading1]);
查看以下資源以查看新支持的幫助器方法的完整列表。
GcWord 模板中的轉(zhuǎn)義模板標(biāo)簽
如果要阻止數(shù)據(jù)模板引擎處理特定的數(shù)據(jù)模板標(biāo)記(即,在模板擴(kuò)展后在文檔中逐字引用它),請(qǐng)?jiān)跇?biāo)記的左雙大括號(hào)之前插入反斜杠。
以下代碼片段顯示了如何轉(zhuǎn)義否則會(huì)打印數(shù)據(jù)值的標(biāo)簽:
var dsPoint = new string[] { "2.2", "3.3", "4.4" };
var doc = new GcWordDocument();
doc.Body.Paragraphs.Add(@"\\{{dsPoint.value}:todouble():format(0.#%)}");
doc.DataTemplate.DataSources.Add("dsPoint", dsPoint);
doc.DataTemplate.Process(CultureInfo.GetCultureInfo("en-US"));
doc.Save("DocumentWithDoubleSlash.docx");
此外,要在模板標(biāo)記之前使用反斜杠而不禁用模板處理,GcWord 允許您插入兩個(gè)或多個(gè)反斜杠,具體取決于需要的數(shù)量。處理模板標(biāo)簽時(shí),它將從前置反斜杠中刪除一個(gè)反斜杠。
以下代碼向模板語(yǔ)法添加雙斜杠。處理模板語(yǔ)法時(shí),這將在生成的 Word 文件中添加一個(gè)反斜杠:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-644817.html
var dsPoint = new string[] { "2.2", "3.3", "4.4" };
var doc = new GcWordDocument();
doc.Body.Paragraphs.Add(@"\\{{dsPoint.value}:todouble():format(0.#%)}");
doc.DataTemplate.DataSources.Add("dsPoint", dsPoint);
doc.DataTemplate.Process(CultureInfo.GetCultureInfo("en-US"));
doc.Save("DocumentWithDoubleSlash.docx");
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-644817.html
到了這里,關(guān)于6.2.0在線編輯:GrapeCity Documents for Word (GcWord) Crack的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!