report_replace()

Read(31) Label: template file, replace,

Description:

Replace substrings of source strings in a template file with a specified string.

Syntax:

report_replace(D, a, b)

Note:

External library function (See The Programmer’s Reference).

 

The function regards the whole text in the template file as a source string and replaces one of its substrings a with string b. When both parameters a and b are sequences, replace a(i) with b(i) in order.

Parameter:

D

DocxChanger object.

a

A substring or a sequence of substrings of a source string to be replaced.

b

The target string or a sequence of strings.

Option:

@1

Replace the first substring only.

@c

Case insensitive.

@q

Do not replace the substring enclosed in quotation marks.

@w

Replace whole words only.

@s

Split sequence a and sequence b respectively as a sequence of single words and perform the replacement member by member in order.

Return value:

Boolean value

Example:

A

 

1

=report_open("D:\\wordFile.docx")

Read template file wordFile.docx.

2

=report_replace(A1,"sql","SPL")

Replace substring “sql” in the whole text of the template file with target string “SPL”; case sensitive.

For example, the text is “第1个大写SQL,第2个大写Sql,第1个小写sql,第2个小写sql。”. Perform the replacement and it becomes “第1个大写SQL,第2个大写Sql,第1个小写SPL,第2个小写SPL。”.

3

=report_replace@1(A1,"sql","SPL")

Replace the first substring “sql” in the whole text of the template file with target string “SPL”; case sensitive.

For example, the text is “第1个大写SQL,第2个大写Sql,第1个小写sql,第2个小写sql。”. Perform the replacement and it becomes “第1个大写SQL,第2个大写Sql,第1个小写SPL,第2个小写sql。”.

4

=report_replace@c(A1,"sql","SPL")

Replace substring “sql” in the whole text of the template file with target string “SPL”; case insensitive.

For example, the text is “第1个大写SQL,第2个大写Sql,第1个小写sql,第2个小写sql。”. Perform the replacement and it becomes “第1个大写SPL,第2个大写SPL,第1个小写SPL,第2个小写SPL。”.

5

=report_replace@q(A1,"sql","SPL")

Replace substring “sql” in the whole text of the template file with target string “SPL”; case sensitive, and won’t replace strings enclosed in quotation marks.

For example, the text is “引号内单词"SQLsqlMySQLmysql",引号外单词SQLsqlMySQLmysql。”. Perform the replacement and it becomes “引号内单词"SQLsqlMySQLmysql",引号外单词SQLSPLMySQLmySPL。”.

6

=report_replace@w(A1,"sql","SPL")

Replace substring “sql” in the whole text of the template file with target string “SPL”; case sensitive, and replace whole words only.

For example, the text is “引号内单词"SQLsqlMySQLmysql",引号外单词SQLsqlMySQLmysql。”. Perform the replacement and it becomes “引号内单词"SQLSPLMySQLmysql",引号外单词SQLSPLMySQLmysql。”.

7

=report_replace(A1,["sql"," 报表"],["SPL"," 集算器"])

Replace substrings sql and “报表” in the whole text of the template file with target string SPL and “集算器”in order; case sensitive.

For example, the text is “启动报表工具,编写sql脚本,创建报表组文件。”. Perform the replacement and it becomes “启动集算器工具,编写SPL脚本,创建集算器组文件。”.

8

=report_replace@s(A1,"sql, 报表","SPL, 集算器")

Split each of the sequences sql,报表” and SPL,集算器” into a sequence of single words and replace words in the former with those in the latter in order.

For example, the text is “启动报表工具,编写sql脚本,创建报表组文件。”. Perform the replacement and it becomes “启动集算器工具,编写SPL脚本,创建集算器组文件。”.

9

=report_write(A1,"D:\\outFile.docx")

 

Related function:

report_insert()

report_open()

report_write()