6.2.0 Online Editing: GrapeCity Documents for Word (GcWord) Crack

GrapeCity Word Document (GcWord)

Support for Office Math functions and conversion to MathML

GcWord now supports creating and editing Office Math content in Word documents. OMath support in GcWord includes a complete API for handling mathematical symbols, formulas and equations widely used in scientific, mathematical and general Word documents. Following are the key highlights of the new API introduced with OMath support −

  • The two main classes used to represent Office Math content in GcWord are OMathParagraph and OMath . OMathParagraph represents a paragraph containing Office Math content, while OMath represents an inline Office Math region, which can be contained within an OMathParagraph or a regular paragraph.
  • Provide specialized classes (such as OMathFunction , OMathEquationArray , OMathRadical, etc.) to represent various mathematical structures in the OMath area. These classes derive from the public abstract OMathStruct base.
  • The new RangeBase property provides access to Office Math content: OMathParagraphs , OMaths , OMathStructs , OMathElements , and OMathMatrixRows .
  • To easily add built-in equations supported by MS Word, convenient Add/Insert methods are provided on the RangeBase , OMathParagraph , OMath , and OMathElement classes, which accept an OMathBuiltInEquation enumeration value identifying the desired equation.
  • A utility MathMLConverter class is included for easy conversion between GcWord OMath content and MathML.

The following code uses the OMath class and its functions to add equations to a Word document:

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");

Omas

New helper "Add<content object>(..)" method to add content to a Word document.

As of now, there are one or more ways to add content objects to a Word document. For example, a paragraph can be created via a constructor call - doc.Body.Paragraphs.Add("text") or using paragraph.GetRange().Runs.Add(…) to add the "runs" of a paragraph and create a paragraph preceding this call talk. However, in v6.2 it is now possible to create runs directly on paragraph elements using the new "AddRun(..)" method.

Likewise, GcWord adds an "Add <content object>(..)" method to every kind of content in a Word document  so that they can be added directly to its parent object, making the code shorter and more efficient. Each object can now be added directly to a different section or content object in a Word document using a new Helper method:

  • table
  • paragraph
  • content control
  • simple field
  • Hyperlink
  • two-way coverage
  • OM Math Paragraph
  • Omas
  • running
  • footnote
  • endnote
  • complex field
  • Group form
  • shape
  • picture
  • Ink shape

Take a look at the following code, which uses the new method "  AddRun(..)  " to add a paragraph run to a paragraph:

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]);

Check out the following resources to see the full list of newly supported helper methods.

Escaping template tags in GcWord templates

If you want to prevent the data template engine from processing a particular data template tag (i.e. refer to it verbatim in the document after template expansion), insert a backslash before the tag's opening double brace.

The following code snippet shows how to escape labels that would otherwise print data values:

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");
copy

Escape Template Tags

Also, to use a backslash before a template tag without disabling template processing, GcWord allows you to insert two or more backslashes, depending on how many are needed. When processing template tags, it removes one backslash from the preceding one.

The following code adds double slashes to template syntax. When processing template syntax, this will add a backslash to the resulting Word file:

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");
copy

Add double slashes to template syntax

Guess you like

Origin blog.csdn.net/john_dwh/article/details/132243267