The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Document::OOXML::Part::WordprocessingML - WordprocessingML document part handling

VERSION

version 0.181410

ATTRIBUTES

xml

XML::LibXML::Document containing the parsed XML of the WordprocessingML part.

xpc

XML::LibXML::XPathContext that will be used to find elements in the WordprocessingML.

METHODS

new_from_xml($part_name, $xml, $strict)

Create a new instance based on XML data.

find_text_nodes($regex, $exclude_tables)

Returns a list of <w:t> elements (see XML::LibXML::Element) matching the regular expression.

First, all adjacent identical runs are merged (see "merge_runs"), then all text elements are matched against the regular expression. The runs with matching text are then split into "pre-match", "match" and "post-match" parts. The "match" parts are then returned.

This regular expression should not contain matching groups, as this will confuse the splitting code.

If $exclude_tables is true, the regular expression will not match text in tables. This option may change in the future.

style_text($regex, %style)

Sets the style options described by %style to all text parts of the document that match regular expression $regex.

Internally, this method uses "find_text_nodes" to do the heavy lifting of combining and splitting runs.

The regular expression should not contain matching groups, as this will confuse the splitting code.

The following style options are recognised (all are optional, but why would you call this method if you don't want to set/unset styling?):

  • bold

    Boolean value. If true, matching text will be made bold. If specified and false, matching text will be un-bolded.

  • italic

    Boolean value. If true, matching text will be made italic. If specified and false, matching text will be un-italiced.

  • underline_style

    String value. Matching text will get an underline of the specified style. If the key exists specified and the value is c<undef>, underline will be removed from the matching text.

    Allowed underline styles are:

        dash
        dashDotDotHeavy
        dashDotHeavy
        dashedHeavy
        dashLong
        dashLongHeavy
        dotDash
        dotDotDash
        dotted
        dottedHeavy
        double
        none
        single
        thick
        wave
        wavyDouble
        wavyHeavy
        words
  • underline_color

    Color value that will be used for the underline only.

  • color

    Color value, matching text will be given this color.

    Colors should be in the format: RRGGBB (red, green, blue components in hexadecimal, like used in HTML). The special value auto can be used to let the word processor decide the color.

    Note: unlike HTML, the color value should NOT be prefixed with "#". It should just be the six hexadecimal digits.

  • exclude_tables

    Boolean value. If true, text in tables will not be touched.

remove_spellcheck_markers

Remove all <w:proofErr> elements from the document. This removes the red "squigglies" until another spelling/grammar check is done.

extract_words

Extract a list of words form the document.

Returns a reference to an array containing the words.

merge_runs

Walks over all runs (<w:r>) in the document. If two adjacent runs in the same paragraph have identical properties, the contents of the second run are merged into the first run.

This makes it easier to find stretches of text for search/replace.

replace_text($search, $replace)

Replace all occurrences of $search with $replace in every text (<w:t>) element in the document.

Does not yet follow references, so text in headers, footers and other external parts of the document isn't changed.

SEE ALSO

AUTHOR

Martijn van de Streek <martijn@vandestreek.net>

COPYRIGHT AND LICENSE

This software is copyright (c) 2018 by Martijn van de Streek.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.