📄 macros
字号:
## AutoStart ##
begin
document.new(true);
selection.fontcolor := 0;
selection.fontname := 'Tahoma';
selection.fontsize := 16;
selection.fontbold := true;
document.typetext('Welcome to TArtFormula Macro World!');
document.clearselection;
paragraph.align := 2;
selection.fontsize := 10;
selection.fontbold := false;
document.typeparagraph;
document.typeparagraph;
paragraph.align := 0;
selection.fontbold := true;
document.typetext('TArtFormula');
selection.fontbold := false;
document.typetext(' lets you easily add scripting functionality to your application.');
document.typeparagraph;
document.typetext('This example show how to add macro engine to RichEditor.');
document.typeparagraph;
document.typeparagraph;
document.typetext('We implement three modules, to work with RichEditor objects:');
document.typeparagraph;
selection.fontbold := true;
document.typetext('Document');
paragraph.numbering := true;
document.typeparagraph;
document.typetext('Paragraph');
document.typeparagraph;
document.typetext('Selection');
document.typeparagraph;
paragraph.numbering := false;
document.typeparagraph;
selection.fontbold := false;
document.typetext('To Run/Edit macros press Macros button.'#13'To know more about Modules open Macro.rtf file.');
document.select(document.lineindex(document.posy-1)+26, 6);
selection.fontbold := true;
document.select(document.lineindex(document.posy+1)+33, 9);
selection.fontbold := true;
document.clearselection;
end
## CharTable ##
begin
var 'i', 'j' end;
document.new(true);
selection.fontname := 'Courier New';
selection.fontbold := true;
selection.fontunderline := true;
selection.fontsize := 10;
selection.fontcolor := $0ff0000;
document.typetext('Character table'#13#13);
selection.fontbold := false;
selection.fontcolor := 0;
selection.fontunderline := false;
for $i := 2; $i <= 15; $i++ do
for $j := 0; $j <= 15; $j++;
document.typetext(chr($i*16+$j));
end;
document.typeparagraph;
next;
end
## Calendar ##
begin
var 'i', 'y', 'j', 'd', 's' end;
define('m1',31);
define('m2',28);
define('m3',31);
define('m4',30);
define('m5',31);
define('m6',30);
define('m7',31);
define('m8',31);
define('m9',30);
define('m10',31);
define('m11',30);
define('m12',31);
$y := input('Year', 'Year:', year(now));
if not isnumber($y) then
msg('Is not a number!','Error',$10);
return(0);
endif;
if isleapyear($y) then $m2 := 29; endif;
document.new(true);
selection.fontname := 'Times new roman';
selection.fontsize := 16;
selection.fontcolor := $0ff0000;
selection.fontbold := true;
selection.fontunderline := false;
document.typetext(' '@$y@#13);
selection.fontsize := 10;
$s := '';
for $i := 1; $i<=7; $i++ do
$j := formatdate('ddd', encodedate(2001,1,$i));
$j := if length($j) > 3 ; leftstr($j,3);
if length($j) < 3;
$j@stringofchar(' ',3-length($j));
$j
end;
end;
$s := $s@' '@$j;
next;
$s := $s+' ';
selection.fontname := 'Courier New';
selection.fontsize := 12;
selection.fontunderline := true;
document.typetext(stringofchar(' ',30)@#13);
for $i:=1; $i<=12; $i++ do
selection.fontsize := 12;
selection.fontbold := true;
selection.fontcolor := $0ff0000;
selection.fontunderline := true;
$j := formatdate('" "mmmm',encodedate($y,$i,1));
document.typetext($j@stringofchar(' ',30-length($j))@#13);
selection.fontsize := 10;
selection.fontcolor := 0;
selection.fontunderline := false;
document.typetext($s);
document.select(document.lineindex(document.posy)+33,3);
selection.fontcolor := $0000ff;
document.setpos(36,document.posy);
selection.fontcolor := 0;
document.typeparagraph;
document.typeparagraph;
selection.fontbold := false;
$d := encodedate($y,$i,1);
document.typetext(stringofchar(' ',(dayofweek($d)-1)*5));
selection.fontbold := false;
for $j := 1; $j <= $m[$i]; $j++ do
if dayofweek($d) = 7 then
selection.fontcolor := $0000ff;
document.typetext(formatf('%4.0f',$j)@' '#13);
selection.fontcolor := 0;
selection.fontbold := false;
else
document.typetext(formatf('%4.0f',$j)@' ');
endd;
$d++;
next;
if dayofweek($d-1) <> 7 then document.typeparagraph; endif;
selection.fontsize := 12;
selection.fontbold := true;
selection.fontcolor := $0ff0000;
selection.fontunderline := true;
document.typetext(stringofchar(' ',30)@#13);
next;
selection.fontcolor := 0;
selection.fontsize := 8;
selection.fontbold := false;
selection.fontunderline := false;
selection.fontname := 'Times New Roman';
document.typetext(#13#13#13'This document was created by TArtFormula macro'#13'(c) Artem Parlyuk, 2000-2007');
if msg('Print calendar?','Ask',$24) = 6 then
document.print;
endif;
end
## ReplaceAll ##
begin
var 's', 'r', 'p' end;
$s := input('Search','String to search','Macro');
$r := input('Replace','String to replace','Script');
$p := pos($s, document.text);
while $p > 0 do
document.select($p,length($s));
selection.text := $r;
$p := pos($s, document.text);
wend;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -