using System;
using System.Collections.Generic;
using System.IO;
using MSWord = Microsoft.Office.Interop.Word;
using System.Drawing;
using CalendarGenerationTool.Properties;
namespace CalendarGenerationTool
{
public static partial class MyMethod
{
/// <summary>
/// 获取电脑Local文件目录
/// </summary>
/// <returns>以字符串的形式返回Local文件目录</returns>
public static string GetLocalDirectory()
{
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
}
/// <summary>
/// 创建文本域对象
/// </summary>
/// <param name="App">Word Application对象</param>
/// <param name="name">对象名</param>
/// <param name="str">显示文字</param>
/// <returns>返回FormField对象</returns>
public static MSWord.FormField CreatTextInput(this MSWord.Application App, string name, string str)
{
MSWord.FormField ffld = App.ActiveDocument.FormFields.Add(App.Selection.Range, MSWord.WdFieldType.wdFieldFormTextInput);
ffld.Name = name;
ffld.Result = str;
return ffld;
}
/// <summary>
/// 图片资源初始化
/// </summary>
public static void ImgFileInitialization()
{
List<string> zodiaclst = new List<string>() { "鼠1", "牛1", "虎1", "兔1", "龙1", "蛇1", "马1", "羊1", "猴1", "鸡1", "狗1", "猪1" };
//List<string> zodiaclst = new List<string>() { "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪" };
//List<string> imglist = new List<string>() { "Week", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec" };
string localpath = $"{GetLocalDirectory()}\\CalendarToolImage";
Directory.CreateDirectory(localpath);
foreach (string str in zodiaclst)
{
if (!File.Exists($"{localpath}\\{str}.jpg"))
{
((Bitmap)Resources.ResourceManager.GetObject(str, Resources.Culture)).Save(localpath + "\\" + str + ".jpg");
}
}
//foreach (string str in imglist)
//{
// if (!File.Exists($"{localpath}\\{str}.png"))
// {
// ((Bitmap)Resources.ResourceManager.GetObject(str, Resources.Culture)).Save(localpath + "\\" + str + ".png");
// }
//}
}
}
}