-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRibbon1.cs
3824 lines (3199 loc) · 182 KB
/
Ribbon1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using Microsoft.Office.Tools.Ribbon;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
using System.Windows.Forms;//MessageBox,ColorDialog
using Microsoft.VisualBasic;//inputbox
using Microsoft.Win32;//registry
using System.Drawing;//color
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions; //正则表达式
using System.Diagnostics;
using System.Threading.Tasks;
using System.Net.NetworkInformation;
using System.Drawing.Imaging;
namespace WordAddIn1
{
public partial class Ribbon1
{
Word.Application app;
//全局路径
#if DEBUG
public static string FDscendHome = "D:\\code\\WordAddIn1\\FDscend";
#endif
#if !DEBUG
public static string FDscendHome = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\FDscend";
#endif
public static string ControlKey = FDscendHome + Properties.Resources.ControlKey;
public static string CheckUpdateFile = FDscendHome + Properties.Resources.CheckUpdateFile;
public static string SettingsFile = FDscendHome + Properties.Resources.SettingsFile;
public static string ChangeCharList = FDscendHome + Properties.Resources.PresetChangeCharList;
public static string CharMatchList = FDscendHome + Properties.Resources.PresetCharMatchList;
public static string PresetCodeFile = FDscendHome + Properties.Resources.PresetCodeFile;
public static string PresetCodeLatexFile = FDscendHome + Properties.Resources.PresetCodeLatexFile;
public static string PresetCodeMDFile = FDscendHome + Properties.Resources.PresetCodeMDFile;
public static string PresetCode4File = FDscendHome + Properties.Resources.PresetCode4File;
public static string PresetToolsBoxShadeColor = FDscendHome + Properties.Resources.PresetToolsBoxShadeColor;
public static string PresetToolsBoxTable = FDscendHome + Properties.Resources.PresetToolsBoxTable;
public static string XMTsetting = FDscendHome + Properties.Resources.PresetXMTsetting;
public static string highlight_index = FDscendHome + Properties.Resources.highlight_index;
public static string PresetHighlight = FDscendHome + Properties.Resources.PresetHighlight;
public static string PresetMathTools = FDscendHome + Properties.Resources.PresetMathTools;
public static string tempFile = FDscendHome + "\\temp";
public static string scriptsDic = FDscendHome + "\\scripts";
public static string presetsDir = FDscendHome + "\\Presets";
public static string latest_info = FDscendHome + "\\latest.json";
public static string temp_websource_htm = FDscendHome + "\\temp\\temp.htm";
public static string temp_pic_path = FDscendHome + "\\temp\\temp_pic_path";
public static string pdf_path = FDscendHome + "\\说明文档.pdf";
public static string readme_path = FDscendHome + "\\readme.html";
//全局常量
public const string KeyDefault = "default";
public const string KeyXMT = "xmt";
public const string KeyCode = "code";
public const string KeyCode2 = "codeB";
public const string KeyCodeLatex = "codeL";
public const string KeyCode4 = "code4";
public const string KeyToolsBox = "tools";
public const string KeyRunCode = "runCode";
public const string KeyBrowser = "browser";
public const string KeyMathList = "math";
public const string KeyTestGroup = "test";
public const string KeyPdfTools = "pdf";
public const string KeyAdmin = "admin";
//全局变量
Color CodeBackcolor1 = Color.FromArgb(226, 239, 217);//代码背景颜色
Color CodeBackcolor2 = Color.White;//代码背景颜色
Color CodeBorderLine = Color.FromArgb(112, 173, 71);//代码竖线颜色
Color CodeTxtColor = Color.FromArgb(165, 165, 165);
//string CodeFontName = "新宋体";
//double CodeFontSize = 9.5;
Word.WdColor codeMD_CurrentColor;
Word.WdColor code4_CurrentColor;
ColorDialog MyColorDialog = new ColorDialog();
string codeChoice = "python";
static int codeOutputCount = 0;
static int codeOutputTotal = 0;
static int gbtOutputCount = 1;
int XMT_styleChoice = 0;
int mathMod = 1;
string connector_symbol = "-";
//窗体句柄字典
private Dictionary<int, Microsoft.Office.Tools.CustomTaskPane> HwndPaneDic_tab = new Dictionary<int, Microsoft.Office.Tools.CustomTaskPane> { };
private Dictionary<int, Microsoft.Office.Tools.CustomTaskPane> HwndPaneDic_tableColor = new Dictionary<int, Microsoft.Office.Tools.CustomTaskPane> { };
private Dictionary<int, Microsoft.Office.Tools.CustomTaskPane> HwndPaneDic_ChangeChar = new Dictionary<int, Microsoft.Office.Tools.CustomTaskPane> { };
private Dictionary<int, Microsoft.Office.Tools.CustomTaskPane> HwndPaneDic_CharMatch = new Dictionary<int, Microsoft.Office.Tools.CustomTaskPane> { };
private Dictionary<int, Microsoft.Office.Tools.CustomTaskPane> HwndPaneDic_highlight = new Dictionary<int, Microsoft.Office.Tools.CustomTaskPane> { };
//侧面板
Microsoft.Office.Tools.CustomTaskPane FileTabPane;
Microsoft.Office.Tools.CustomTaskPane tableColoringPane;
Microsoft.Office.Tools.CustomTaskPane changCharPane;
Microsoft.Office.Tools.CustomTaskPane charMatchPane;
Microsoft.Office.Tools.CustomTaskPane highlightPane;
Microsoft.Office.Tools.CustomTaskPane simpleBrowserPane;
// 样式是否存在 int 默认 0
int maintitle_bool;
int title_1_bool;
int title_2_bool;
int maintext_bool;
int codeMD_bool;
int paraShandingChoice = 1;
int styleShadingChoice = 1;
//标签栏
static int fileTabPaneHeight = 83;
public List<string> DocNamesList = new List<string>();
public static JObject ImportJSON(string jsonfile)
{
StreamReader reader = File.OpenText(jsonfile);
JsonTextReader jsonTextReader = new JsonTextReader(reader);
JObject jsonObject = (JObject)JToken.ReadFrom(jsonTextReader);
reader.Close();
return jsonObject;
}
public static string ReadjsonFun(string jsonfile, string key)
{
//StreamReader reader = File.OpenText(jsonfile);
//JsonTextReader jsonTextReader = new JsonTextReader(reader);
//JObject jsonObject = (JObject)JToken.ReadFrom(jsonTextReader);
//reader.Close();
JObject jsonObject = ImportJSON(jsonfile);
string value = jsonObject[key].ToString();
return value;
}
public static void SetjsonFun(string jsonfile, JObject jsonObject)
{
/*StreamReader reader = File.OpenText(jsonfile);
JsonTextReader jsonTextReader = new JsonTextReader(reader);
JObject jsonObject = (JObject)JToken.ReadFrom(jsonTextReader);
jsonObject[key] = value;
reader.Close();*/
string output = Newtonsoft.Json.JsonConvert.SerializeObject(jsonObject, Newtonsoft.Json.Formatting.Indented);
File.WriteAllText(jsonfile, output);
}
//暂时用不到
public static void AddjsonFun(string jsonfile, JObject JStemp)
{
//string JsonString = File.ReadAllText(jsonfile);
StreamReader reader = File.OpenText(jsonfile);
JsonTextReader jsonTextReader = new JsonTextReader(reader);
JObject jobject = (JObject)JToken.ReadFrom(jsonTextReader);
//JObject jobject = JObject.Parse(JsonString);
//JObject newkey = new JObject(new JProperty(key, value));
jobject.Last.AddAfterSelf(JStemp);
//jobject.Add(newkey);
string convertString = Convert.ToString(jobject);
File.WriteAllText(jsonfile, convertString);
}
private bool BoolKey(string key)
{
switch (key)
{
case KeyDefault:
group_tuisong.Visible = false;
code.Visible = false;
break;
case KeyXMT:
group_tuisong.Visible = true;
break;
case KeyCode:
code.Visible = true;
break;
case KeyCode2:
Code2.Visible = true;
break;
case KeyCodeLatex:
CodeLatex.Visible = true;
break;
case KeyCode4:
CodeGroup4.Visible = true;
break;
case KeyToolsBox:
ToolsBox.Visible = true;
break;
case KeyRunCode:
runCodeGroup.Visible = true;
break;
case KeyMathList:
mathList.Visible = true;
break;
case KeyTestGroup:
testGroup.Visible = true;
break;
case KeyPdfTools:
pdfToolsGroup.Visible = true;
break;
case KeyAdmin:
KeyAllTrue();
break;
default:
return false;
}
return true;
}
private bool BoolKeyState(string key, string jsonfile)
{
switch (key)
{
case KeyDefault:
//group_tuisong.Visible = false;
//code.Visible = false;
break;
case KeyXMT:
if (ReadjsonFun(jsonfile, "state_"+ KeyXMT) == "1")
{
group_tuisong.Visible = true;
return true;
}
else
group_tuisong.Visible = false;
break;
case KeyCode:
if (ReadjsonFun(jsonfile, "state_"+ KeyCode) == "1")
{
code.Visible = true;
return true;
}
else
code.Visible = false;
break;
case KeyCode2:
if (ReadjsonFun(jsonfile, "state_" + KeyCode2) == "1")
{
Code2.Visible = true;
return true;
}
else
Code2.Visible = false;
break;
case KeyCodeLatex:
if (ReadjsonFun(jsonfile, "state_" + KeyCodeLatex) == "1")
{
CodeLatex.Visible = true;
return true;
}
else
CodeLatex.Visible = false;
break;
case KeyCode4:
if (ReadjsonFun(jsonfile, "state_" + KeyCode4) == "1")
{
CodeGroup4.Visible = true;
return true;
}
else
CodeGroup4.Visible = false;
break;
case KeyToolsBox:
if (ReadjsonFun(jsonfile, "state_" + KeyToolsBox) == "1")
{
ToolsBox.Visible = true;
return true;
}
else
ToolsBox.Visible = false;
break;
case KeyRunCode:
if (ReadjsonFun(jsonfile, "state_" + KeyRunCode) == "1")
{
runCodeGroup.Visible = true;
return true;
}
else
runCodeGroup.Visible = false;
break;
case KeyBrowser:
if (ReadjsonFun(jsonfile, "state_" + KeyBrowser) == "1")
{
simpleBrowser.Visible = true;
return true;
}
else
simpleBrowser.Visible = false;
break;
case KeyMathList:
if (ReadjsonFun(jsonfile, "state_" + KeyMathList) == "1")
{
mathList.Visible = true;
return true;
}
else
mathList.Visible = false;
break;
case KeyTestGroup:
if (ReadjsonFun(jsonfile, "state_" + KeyTestGroup) == "1")
{
testGroup.Visible = true;
return true;
}
else
testGroup.Visible = false;
break;
case KeyPdfTools:
if (ReadjsonFun(jsonfile, "state_" + KeyPdfTools) == "1")
{
pdfToolsGroup.Visible = true;
return true;
}
else
pdfToolsGroup.Visible = false;
break;
case KeyAdmin:
if (ReadjsonFun(jsonfile, "state_"+KeyAdmin) == "1")
{
KeyAllTrue();
return true;
}
break;
default:
return false;
}
return true;
}
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
app = Globals.ThisAddIn.Application;
//重置临时文件夹
if (Directory.Exists(tempFile))
{
Directory.Delete(tempFile, true);
Directory.CreateDirectory(tempFile);
}
else Directory.CreateDirectory(tempFile);
//颜色对话框自定义颜色集
MyColorDialog.CustomColors = new int[] { 14282722, 13684944, 13298939, 14869500 };
//
#if DEBUG
//KeyAllTrue();
KeyStateLoad();
#endif
#if !DEBUG
KeyStateLoad();
//FileTabOnOff.Visible = false;
#endif
//代码相关颜色初始化
JObject js = ImportJSON(PresetCodeFile);
CodeBackcolor1 = ReadCodeTHINGcolor(int.Parse(js["DefaultPreset"].ToString()), "CodeBackcolor1");
CodeBackcolor2 = ReadCodeTHINGcolor(int.Parse(js["DefaultPreset"].ToString()), "CodeBackcolor2");
CodeBorderLine = ReadCodeTHINGcolor(int.Parse(js["DefaultPreset"].ToString()), "CodeBorderLine");
JObject js_codeMD = ImportJSON(PresetCodeMDFile);
int r = int.Parse(js_codeMD["ParaShadingColor_r"].ToString());
int g = int.Parse(js_codeMD["ParaShadingColor_g"].ToString());
int b = int.Parse(js_codeMD["ParaShadingColor_b"].ToString());
codeMD_CurrentColor = GetColor(Color.FromArgb(r, g, b));
JObject js_code4 = ImportJSON(PresetCode4File);
r = int.Parse(js_code4["DefaultShadingColor_r"].ToString());
g = int.Parse(js_code4["DefaultShadingColor_g"].ToString());
b = int.Parse(js_code4["DefaultShadingColor_b"].ToString());
code4_CurrentColor = GetColor(Color.FromArgb(r, g, b));
// 文案
JObject js_xmt = ImportJSON(XMTsetting);
string authorChoice = js_xmt["author"].ToString();
if (authorChoice == "1") author.Image = Properties.Resources.office;
if (authorChoice == "2") author.Image = Properties.Resources.wps;
if (authorChoice == "3") author.Image = Properties.Resources.document;
if (authorChoice == "4") author.Image = Properties.Resources.computer;
if (authorChoice == "5")
{
if (js_xmt["author_new"].ToString() == "") author.Image = Properties.Resources.add;
else
{
author.Image = Properties.Resources.署名;
author_new.Image = Properties.Resources.署名;
author_new.Label = js_xmt["author_new"].ToString();
}
}
//check update
JObject js_update = ImportJSON(CheckUpdateFile);
if (js_update["auto_check"].ToString() == "yes")
{
if (GetNetStatus("api.github.com")) AutoUpdate();
}
//math list
JObject js_math = ImportJSON(PresetMathTools);
mathMod = (int)js_math["default_mod"];
connector_symbol = js_math["connector_symbol"].ToString();
mathChangeMod.Label = "模式 " + js_math["default_mod"].ToString();
mathMod3.SuperTip = mathMod3.SuperTip.Replace("(1-1)", "(1" + connector_symbol + "1)");
mathMod4.SuperTip = mathMod4.SuperTip.Replace("(1-1)", "(1" + connector_symbol + "1)");
try
{
visSplit.Checked = Globals.ThisAddIn.Application.ActiveWindow.View.ShowHiddenText;
}
catch (Exception)
{
;
}
if (mathMod == 3 || mathMod == 4) visMathClick(true);
else visMathClick(false);
}
bool GetNetStatus(string ping_url)
{
Ping ping = new Ping();
try
{
PingReply pingReply = ping.Send(ping_url);
if (pingReply.Status == IPStatus.Success)
{
return true;
}
else
{
return false;
}
}
catch
{
return false;
}
}
void AutoUpdate()
{
//check update
JObject js = ImportJSON(CheckUpdateFile);
string strTime = js["latest_date"].ToString();
double fre_day = double.Parse(js["delay_day"].ToString());
DateTime dt_latest = Convert.ToDateTime(strTime);
DateTime dt_check = dt_latest.AddDays(fre_day);
DateTime dt_now = DateTime.Now;
if (dt_check < dt_now) //检查上次更新时间
{
//检查版本
if (File.Exists(latest_info))
{
File.Delete(latest_info);
}
string url = Properties.Resources.latest_info_url;
WebClient webClient = new WebClient();
webClient.Headers.Add("user-agent", "Mozilla/4.0 ((compatible; MSIE 8.0; Windows NT 6.1;.NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729;)");
ServicePointManager.SecurityProtocol = (SecurityProtocolType)48
| (SecurityProtocolType)192
| (SecurityProtocolType)768
| (SecurityProtocolType)3072;
webClient.DownloadFile(url, latest_info);
JObject js_latest = ImportJSON(latest_info);
Version ver_cur = new Version(Properties.Resources.current_ver);
string latest_version = js_latest["tag_name"].ToString().Substring(1);
Version ver_latest = new Version(latest_version);
if (ver_cur < ver_latest)
{
DialogResult dr = MessageBox.Show("插件更新啦,去看看吧!\r\n\r\n当前版本:" + Properties.Resources.current_ver + "\r\n最新版本:" + latest_version, "分点作答", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign, false);
if (dr == DialogResult.OK)
{
System.Diagnostics.Process.Start(Properties.Resources.github_code_url);
}
}
js["latest_date"] = dt_now.ToString("d");
SetjsonFun(CheckUpdateFile, js);
}
}
void KeyAllTrue()
{
group_tuisong.Visible = true;
code.Visible = true;
Code2.Visible = true;
CodeLatex.Visible = true;
CodeGroup4.Visible = true;
ToolsBox.Visible = true;
runCodeGroup.Visible = true;
simpleBrowser.Visible = true;
}
public void KeyStateLoad()
{
//string key;
JObject jstemp = ImportJSON(ControlKey);
foreach (JProperty jp in jstemp.Properties())
{
string key_temp = jp.Value.ToString();
BoolKeyState(key_temp, ControlKey);
}
}
private void button_header_Click(object sender, RibbonControlEventArgs e)
{
//设置页眉
JObject js = ImportJSON(XMTsetting);
int nullkey = 1;
string header_text = js["header_text"].ToString();
if (header_text == "")
{
string key = Interaction.InputBox("输入自定义页眉", "页眉设置").ToString();
if (key == "")
{
nullkey = 0;
}
else
{
js["header_text"] = key;
header_text = key;
SetjsonFun(XMTsetting, js);
}
}
if (nullkey == 1)
{
foreach (Word.Section section in app.Application.ActiveDocument.Sections)
{
Word.Range headerRange = section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
headerRange.Fields.Add(headerRange, Word.WdFieldType.wdFieldPage);
headerRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
headerRange.Font.Name = js["heade_font"].ToString();
headerRange.Text = header_text;
}
}
}
private void button_footer_Click(object sender, RibbonControlEventArgs e)
{
//设置页脚
JObject js = ImportJSON(XMTsetting);
int nullkey = 1;
string footer_text = js["footer_text"].ToString();
if (footer_text == "")
{
string key = Interaction.InputBox("输入自定义页脚", "页脚设置").ToString();
if (key == "")
{
nullkey = 0;
}
else
{
js["footer_text"] = key;
footer_text = key;
SetjsonFun(XMTsetting, js);
}
}
if (nullkey == 1)
{
foreach (Word.Section wordSection in app.Application.ActiveDocument.Sections)
{
Word.Range footerRange = wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
footerRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;
//footerRange.Font.ColorIndex = Word.WdColorIndex.wdBlack;
//footerRange.Font.Size = 11;
footerRange.Font.Name = js["footer_font"].ToString();
footerRange.Text = footer_text;
}
}
}
private void button_font_Click(object sender, RibbonControlEventArgs e)
{
//替换全文字体
// Set the Range to the first paragraph.
//Word.Document document = app.Application.ActiveDocument;
//Word.Range rng = document.Paragraphs[1].Range;
Word.Range rng = app.Application.ActiveDocument.Content;
rng.Font.Size = 12;
rng.Font.Name = "宋体";
rng.Select();
//MessageBox.Show("Formatted Range");
}
private void button_MainTitle_Click(object sender, RibbonControlEventArgs e)
{
//大标题
//获取预设
JObject js = ImportJSON(XMTsetting);
string title_name = js["style"][XMT_styleChoice]["title"].ToString();
string docx_file = presetsDir + js["style"][XMT_styleChoice]["docx_file"].ToString();
Globals.ThisAddIn.Application.Selection.ClearFormatting();
for (int i = 1; i < Globals.ThisAddIn.Application.ActiveDocument.Styles.Count; i++)
{
//MessageBox.Show(Globals.ThisAddIn.Application.ActiveDocument.Styles[i].NameLocal);
if(Globals.ThisAddIn.Application.ActiveDocument.Styles[i].NameLocal== title_name)
{
maintitle_bool = 1;
break;
}
}
if (maintitle_bool == 0)
{
// CreatMainTitleStyle();
CopyStyle(docx_file, title_name);
maintitle_bool = 1;
}
Globals.ThisAddIn.Application.Selection.set_Style(title_name);
//换竖线
object Replace_String = "|"; //要替换的字符
object ms = System.Type.Missing;
object Replace = Word.WdReplace.wdReplaceAll;//设置替换方式:一,全部替换;二,只替换一个;三,一个都不替换。
object ReplaceWith = "|"; //最终替换成的字符
//执行Word自带的查找/替换功能函数
Globals.ThisAddIn.Application.Selection.Find.Execute(ref Replace_String, ref ms, ref ms, ref ms, ref ms, ref ms, ref ms, ref ms, ref ms, ref ReplaceWith, ref Replace, ref ms, ref ms, ref ms, ref ms);
Microsoft.Office.Core.DocumentProperties properties;
properties = (Microsoft.Office.Core.DocumentProperties)app.Application.ActiveDocument.BuiltInDocumentProperties;
properties["Title"].Value = Globals.ThisAddIn.Application.Selection.Paragraphs[1].Range.Text;
}
void CopyStyle(string source, string styleName)
{
string activeDocPath = app.ActiveDocument.Path + "\\" + app.ActiveDocument.Name;
Globals.ThisAddIn.Application.OrganizerCopy(source, activeDocPath, styleName, Word.WdOrganizerObject.wdOrganizerObjectStyles);
}
void CreatMainTitleStyle()
{
Globals.ThisAddIn.Application.ActiveDocument.Styles.Add("标题_XMT", Word.WdStyleType.wdStyleTypeParagraph);
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].AutomaticallyUpdate = false;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.NameFarEast = "宋体";
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.NameAscii = "宋体";
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.NameOther = "宋体";
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.Name = "宋体";
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.Size = 14;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.Bold = 1;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.Italic = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.Underline = Word.WdUnderline.wdUnderlineNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.UnderlineColor = Word.WdColor.wdColorAutomatic;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.StrikeThrough = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.Outline = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.Emboss = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.Shadow = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.Hidden = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.SmallCaps = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.AllCaps = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.Color = Word.WdColor.wdColorAutomatic;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.Engrave = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.Superscript = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.Subscript = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.Scaling = 100;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.Kerning = 1;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.Animation = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.DisableCharacterSpaceGrid = false;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.EmphasisMark = Word.WdEmphasisMark.wdEmphasisMarkNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.Ligatures = Word.WdLigatures.wdLigaturesNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.NumberSpacing = Word.WdNumberSpacing.wdNumberSpacingDefault;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.NumberForm = Word.WdNumberForm.wdNumberFormDefault;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.StylisticSet = Word.WdStylisticSet.wdStylisticSetDefault;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Font.ContextualAlternates = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.LeftIndent = app.CentimetersToPoints(0);
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.RightIndent = app.CentimetersToPoints(0);
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.SpaceBefore = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.SpaceBeforeAuto = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.SpaceAfter = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.SpaceAfterAuto = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.LineSpacingRule = Word.WdLineSpacing.wdLineSpaceSingle;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.WidowControl = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.KeepWithNext = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.KeepTogether = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.PageBreakBefore = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.NoLineNumber = 0;
//Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.Hyphenation = 1;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.FirstLineIndent = app.CentimetersToPoints(0);
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.OutlineLevel = Word.WdOutlineLevel.wdOutlineLevel1;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.CharacterUnitLeftIndent = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.CharacterUnitRightIndent = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.CharacterUnitFirstLineIndent = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.LineUnitBefore = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.LineUnitAfter = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.MirrorIndents = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.TextboxTightWrap = Word.WdTextboxTightWrap.wdTightNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.CollapsedByDefault = 0;
//Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.AutoAdjustRightIndent = 1;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.DisableLineHeightGrid = 0;
//Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.FarEastLineBreakControl = 1;
//Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.WordWrap = 1;
//Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.HangingPunctuation = 1;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.HalfWidthPunctuationOnTopOfLine = 0;
//Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.AddSpaceBetweenFarEastAndAlpha = 1;
//Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.AddSpaceBetweenFarEastAndDigit = 1;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.BaseLineAlignment = Word.WdBaselineAlignment.wdBaselineAlignAuto;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].NoSpaceBetweenParagraphsOfSameStyle = false;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.TabStops.ClearAll();
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.Shading.Texture = Word.WdTextureIndex.wdTextureNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.Shading.ForegroundPatternColor = Word.WdColor.wdColorAutomatic;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.Shading.BackgroundPatternColor = Word.WdColor.wdColorAutomatic;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.Borders[Word.WdBorderType.wdBorderLeft].LineStyle = Word.WdLineStyle.wdLineStyleNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.Borders[Word.WdBorderType.wdBorderRight].LineStyle = Word.WdLineStyle.wdLineStyleNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.Borders[Word.WdBorderType.wdBorderTop].LineStyle = Word.WdLineStyle.wdLineStyleNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.Borders[Word.WdBorderType.wdBorderBottom].LineStyle = Word.WdLineStyle.wdLineStyleNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.Borders.DistanceFromTop = 1;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.Borders.DistanceFromRight = 4;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.Borders.DistanceFromLeft = 4;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].ParagraphFormat.Borders.DistanceFromBottom = 1;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].NoSpaceBetweenParagraphsOfSameStyle = false;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].set_BaseStyle("");
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题_XMT"].Frame.Delete();
}
void CreatTitle1Style()
{
Globals.ThisAddIn.Application.ActiveDocument.Styles.Add("标题1_XMT", Word.WdStyleType.wdStyleTypeParagraph);
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].AutomaticallyUpdate = false;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.NameFarEast = "宋体";
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.NameAscii = "宋体";
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.NameOther = "宋体";
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.Name = "宋体";
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.Size = (float)10.5;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.Bold = 1;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.Italic = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.Underline = Word.WdUnderline.wdUnderlineNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.UnderlineColor = Word.WdColor.wdColorAutomatic;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.StrikeThrough = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.Outline = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.Emboss = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.Shadow = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.Hidden = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.SmallCaps = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.AllCaps = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.Color = Word.WdColor.wdColorAutomatic;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.Engrave = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.Superscript = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.Subscript = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.Scaling = 100;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.Kerning = 1;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.Animation = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.DisableCharacterSpaceGrid = false;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.EmphasisMark = Word.WdEmphasisMark.wdEmphasisMarkNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.Ligatures = Word.WdLigatures.wdLigaturesNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.NumberSpacing = Word.WdNumberSpacing.wdNumberSpacingDefault;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.NumberForm = Word.WdNumberForm.wdNumberFormDefault;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.StylisticSet = Word.WdStylisticSet.wdStylisticSetDefault;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Font.ContextualAlternates = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.LeftIndent = app.CentimetersToPoints(0);
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.RightIndent = app.CentimetersToPoints(0);
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.SpaceBefore = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.SpaceBeforeAuto = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.SpaceAfter = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.SpaceAfterAuto = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.LineSpacingRule = Word.WdLineSpacing.wdLineSpaceSingle;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.WidowControl = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.KeepWithNext = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.KeepTogether = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.PageBreakBefore = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.NoLineNumber = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.FirstLineIndent = app.CentimetersToPoints(0);
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.OutlineLevel = Word.WdOutlineLevel.wdOutlineLevel1;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.CharacterUnitLeftIndent = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.CharacterUnitRightIndent = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.CharacterUnitFirstLineIndent = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.LineUnitBefore = 1;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.LineUnitAfter = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.MirrorIndents = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.TextboxTightWrap = Word.WdTextboxTightWrap.wdTightNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.CollapsedByDefault = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.DisableLineHeightGrid = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.HalfWidthPunctuationOnTopOfLine = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.BaseLineAlignment = Word.WdBaselineAlignment.wdBaselineAlignAuto;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].NoSpaceBetweenParagraphsOfSameStyle = false;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.TabStops.ClearAll();
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.Shading.Texture = Word.WdTextureIndex.wdTextureNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.Shading.ForegroundPatternColor = Word.WdColor.wdColorAutomatic;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.Shading.BackgroundPatternColor = Word.WdColor.wdColorAutomatic;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.Borders[Word.WdBorderType.wdBorderLeft].LineStyle = Word.WdLineStyle.wdLineStyleNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.Borders[Word.WdBorderType.wdBorderRight].LineStyle = Word.WdLineStyle.wdLineStyleNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.Borders[Word.WdBorderType.wdBorderTop].LineStyle = Word.WdLineStyle.wdLineStyleNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.Borders[Word.WdBorderType.wdBorderBottom].LineStyle = Word.WdLineStyle.wdLineStyleNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.Borders.DistanceFromTop = 1;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.Borders.DistanceFromRight = 4;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.Borders.DistanceFromLeft = 4;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].ParagraphFormat.Borders.DistanceFromBottom = 1;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].NoSpaceBetweenParagraphsOfSameStyle = false;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].set_BaseStyle("");
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题1_XMT"].Frame.Delete();
}
void CreatTitle2Style()
{
Globals.ThisAddIn.Application.ActiveDocument.Styles.Add("标题2_XMT", Word.WdStyleType.wdStyleTypeParagraph);
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].AutomaticallyUpdate = false;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.NameFarEast = "宋体";
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.NameAscii = "宋体";
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.NameOther = "宋体";
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.Name = "宋体";
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.Size = (float)10.5;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.Bold = 1;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.Italic = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.Underline = Word.WdUnderline.wdUnderlineNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.UnderlineColor = Word.WdColor.wdColorAutomatic;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.StrikeThrough = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.Outline = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.Emboss = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.Shadow = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.Hidden = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.SmallCaps = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.AllCaps = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.Color = Word.WdColor.wdColorAutomatic;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.Engrave = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.Superscript = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.Subscript = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.Scaling = 100;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.Kerning = 1;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.Animation = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.DisableCharacterSpaceGrid = false;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.EmphasisMark = Word.WdEmphasisMark.wdEmphasisMarkNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.Ligatures = Word.WdLigatures.wdLigaturesNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.NumberSpacing = Word.WdNumberSpacing.wdNumberSpacingDefault;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.NumberForm = Word.WdNumberForm.wdNumberFormDefault;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.StylisticSet = Word.WdStylisticSet.wdStylisticSetDefault;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Font.ContextualAlternates = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.LeftIndent = app.CentimetersToPoints(0);
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.RightIndent = app.CentimetersToPoints(0);
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.SpaceBefore = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.SpaceBeforeAuto = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.SpaceAfter = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.SpaceAfterAuto = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.LineSpacingRule = Word.WdLineSpacing.wdLineSpaceSingle;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.WidowControl = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.KeepWithNext = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.KeepTogether = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.PageBreakBefore = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.NoLineNumber = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.FirstLineIndent = app.CentimetersToPoints(0);
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.OutlineLevel = Word.WdOutlineLevel.wdOutlineLevel2;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.CharacterUnitLeftIndent = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.CharacterUnitRightIndent = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.CharacterUnitFirstLineIndent = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.LineUnitBefore = (float)0.5;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.LineUnitAfter = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.MirrorIndents = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.TextboxTightWrap = Word.WdTextboxTightWrap.wdTightNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.CollapsedByDefault = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.DisableLineHeightGrid = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.HalfWidthPunctuationOnTopOfLine = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.BaseLineAlignment = Word.WdBaselineAlignment.wdBaselineAlignAuto;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].NoSpaceBetweenParagraphsOfSameStyle = false;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.TabStops.ClearAll();
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.Shading.Texture = Word.WdTextureIndex.wdTextureNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.Shading.ForegroundPatternColor = Word.WdColor.wdColorAutomatic;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.Shading.BackgroundPatternColor = Word.WdColor.wdColorAutomatic;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.Borders[Word.WdBorderType.wdBorderLeft].LineStyle = Word.WdLineStyle.wdLineStyleNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.Borders[Word.WdBorderType.wdBorderRight].LineStyle = Word.WdLineStyle.wdLineStyleNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.Borders[Word.WdBorderType.wdBorderTop].LineStyle = Word.WdLineStyle.wdLineStyleNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.Borders[Word.WdBorderType.wdBorderBottom].LineStyle = Word.WdLineStyle.wdLineStyleNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.Borders.DistanceFromTop = 1;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.Borders.DistanceFromRight = 4;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.Borders.DistanceFromLeft = 4;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].ParagraphFormat.Borders.DistanceFromBottom = 1;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].NoSpaceBetweenParagraphsOfSameStyle = false;
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].set_BaseStyle("");
Globals.ThisAddIn.Application.ActiveDocument.Styles["标题2_XMT"].Frame.Delete();
}
void CreatMainTextStyle()
{
Globals.ThisAddIn.Application.ActiveDocument.Styles.Add("正文_XMT", Word.WdStyleType.wdStyleTypeParagraph);
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].AutomaticallyUpdate = false;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.NameFarEast = "宋体";
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.NameAscii = "宋体";
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.NameOther = "宋体";
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.Name = "宋体";
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.Size = (float)10.5;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.Bold = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.Italic = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.Underline = Word.WdUnderline.wdUnderlineNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.UnderlineColor = Word.WdColor.wdColorAutomatic;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.StrikeThrough = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.Outline = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.Emboss = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.Shadow = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.Hidden = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.SmallCaps = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.AllCaps = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.Color = Word.WdColor.wdColorAutomatic;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.Engrave = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.Superscript = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.Subscript = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.Scaling = 100;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.Kerning = 1;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.Animation = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.DisableCharacterSpaceGrid = false;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.EmphasisMark = Word.WdEmphasisMark.wdEmphasisMarkNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.Ligatures = Word.WdLigatures.wdLigaturesNone;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.NumberSpacing = Word.WdNumberSpacing.wdNumberSpacingDefault;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.NumberForm = Word.WdNumberForm.wdNumberFormDefault;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.StylisticSet = Word.WdStylisticSet.wdStylisticSetDefault;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.ContextualAlternates = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].ParagraphFormat.LeftIndent = app.CentimetersToPoints(0);
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].ParagraphFormat.RightIndent = app.CentimetersToPoints(0);
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].ParagraphFormat.SpaceBefore = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].ParagraphFormat.SpaceBeforeAuto = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].ParagraphFormat.SpaceAfter = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].ParagraphFormat.SpaceAfterAuto = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].ParagraphFormat.LineSpacingRule = Word.WdLineSpacing.wdLineSpaceSingle;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphJustify;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].ParagraphFormat.WidowControl = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].ParagraphFormat.KeepWithNext = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].ParagraphFormat.KeepTogether = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].ParagraphFormat.PageBreakBefore = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].ParagraphFormat.NoLineNumber = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].ParagraphFormat.FirstLineIndent = Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].Font.Size * 2;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].ParagraphFormat.OutlineLevel = Word.WdOutlineLevel.wdOutlineLevelBodyText;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].ParagraphFormat.CharacterUnitLeftIndent = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].ParagraphFormat.CharacterUnitRightIndent = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].ParagraphFormat.CharacterUnitFirstLineIndent = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].ParagraphFormat.LineUnitBefore = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].ParagraphFormat.LineUnitAfter = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].ParagraphFormat.MirrorIndents = 0;
Globals.ThisAddIn.Application.ActiveDocument.Styles["正文_XMT"].ParagraphFormat.TextboxTightWrap = Word.WdTextboxTightWrap.wdTightNone;