using System.IO;
using System.Threading;
ThreadOutput to1 = new ThreadOutput();
to1.picName = pic;
to1.companyName = company;
to1.chuName = chu;
to1.traID = traid;
Thread tThread = new Thread(new ThreadStart(to1.WordSaveAs));
// 設定為後台線程,主要是為不影響主線程的結束
tThread.IsBackground = true;
tThread.Start();
//*******************
public class ThreadOutput
{
string pic = ""; //抬頭圖片
string company = ""; //名稱
int travelid = -1; //ID
string chu = ""; //名稱
/// <summary>
/// 抬頭圖片
/// </summary>
public string picName
{
set { pic = value; }
}
/// <summary>
/// 名稱
/// </summary>
public string companyName
{
set { company = value; }
}
/// <summary>
/// ID
/// </summary>
public int tralID
{
set { travelid = value; }
}
/// <summary>
/// 辦事處名稱
/// </summary>
public string chuName
{
set { banshichu = value; }
}
/// <summary>
/// 要分割的字元
/// </summary>
/// <param name="txt">分割的字元</param>
/// <param name="lex">所取的值</param>
/// <returns></returns>
public string splitText(object txt, int lex)
{
string label = txt.ToString();
if (label != "")
{
string[] strArr = label.Split('&');
if (strArr.Length >= lex)
return strArr[lex].ToString();
else
return "";
}
else
{
return "";
}
}
//另存抬頭
public void WordSaveAs()
{
//擷取檔案清單
string sd = AppDomain.CurrentDomain.BaseDirectory + "travel_new\\doc\\";
string[] files = Directory.GetFiles(sd);
foreach (string f in files)
{
if (f.LastIndexOf("\\") != -1)
{
string strFile = f.Substring(f.LastIndexOf("\\") + 1);
string strLast = strFile.Substring(strFile.Length - 3, 3);
if (strLast.ToLower() == "doc")
{
string strName = strFile.Substring(0, strFile.Length - 4);
string fileName = strName + ".doc";//用戶端儲存的檔案名稱
string filePath = AppDomain.CurrentDomain.BaseDirectory + "travel_new\\doc\\" + fileName;//路徑
if (company != "")
{
//判斷行程路線文檔說明是否存在,不存在則建立替代文檔,否則調用已存在的logo文檔。
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "travel_new\\doc\\logo\\" + strName + "_" + company + "_logo.doc") == false)
{
if (pic != "")
{
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"\" + pic))
{
//進行logo標誌替代,並另存新檔新文檔。
OutputWod.CreatWordDocument(strName, filePath, fileName, pic, company);
}
}
}
}
}
}
}
}
}