1. using System;
    2. using System.Collections.Generic;
    3. using System.IO;
    4. using MSWord = Microsoft.Office.Interop.Word;
    5. using System.Drawing;
    6. using CalendarGenerationTool.Properties;
    7. namespace CalendarGenerationTool
    8. {
    9. public static partial class MyMethod
    10. {
    11. /// <summary>
    12. /// 获取电脑Local文件目录
    13. /// </summary>
    14. /// <returns>以字符串的形式返回Local文件目录</returns>
    15. public static string GetLocalDirectory()
    16. {
    17. return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
    18. }
    19. /// <summary>
    20. /// 创建文本域对象
    21. /// </summary>
    22. /// <param name="App">Word Application对象</param>
    23. /// <param name="name">对象名</param>
    24. /// <param name="str">显示文字</param>
    25. /// <returns>返回FormField对象</returns>
    26. public static MSWord.FormField CreatTextInput(this MSWord.Application App, string name, string str)
    27. {
    28. MSWord.FormField ffld = App.ActiveDocument.FormFields.Add(App.Selection.Range, MSWord.WdFieldType.wdFieldFormTextInput);
    29. ffld.Name = name;
    30. ffld.Result = str;
    31. return ffld;
    32. }
    33. /// <summary>
    34. /// 图片资源初始化
    35. /// </summary>
    36. public static void ImgFileInitialization()
    37. {
    38. List<string> zodiaclst = new List<string>() { "鼠1", "牛1", "虎1", "兔1", "龙1", "蛇1", "马1", "羊1", "猴1", "鸡1", "狗1", "猪1" };
    39. //List<string> zodiaclst = new List<string>() { "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪" };
    40. //List<string> imglist = new List<string>() { "Week", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec" };
    41. string localpath = $"{GetLocalDirectory()}\\CalendarToolImage";
    42. Directory.CreateDirectory(localpath);
    43. foreach (string str in zodiaclst)
    44. {
    45. if (!File.Exists($"{localpath}\\{str}.jpg"))
    46. {
    47. ((Bitmap)Resources.ResourceManager.GetObject(str, Resources.Culture)).Save(localpath + "\\" + str + ".jpg");
    48. }
    49. }
    50. //foreach (string str in imglist)
    51. //{
    52. // if (!File.Exists($"{localpath}\\{str}.png"))
    53. // {
    54. // ((Bitmap)Resources.ResourceManager.GetObject(str, Resources.Culture)).Save(localpath + "\\" + str + ".png");
    55. // }
    56. //}
    57. }
    58. }
    59. }