コード例 #1
0
        /// <summary>
        /// 执行导出
        /// </summary>
        /// <returns></returns>
        public string Excute()
        {
            if (_ContractType.ContractTemplate != null)
            {
                if (!Directory.Exists(_TempWordLocation))
                {
                    Directory.CreateDirectory(_TempWordLocation);
                }
                //生成临时word文档
                byte[]     bytes = _ContractType.ContractTemplate;
                FileStream fs    = new FileStream(_TempWordName, FileMode.Create, FileAccess.Write);
                fs.Write(bytes, 0, bytes.Length);
                fs.Flush();
                fs.Close();

                Application app           = new Application();
                object      nothing       = Type.Missing;
                object      localPatho    = _TempWordName;
                object      NEWlocalPatho = _NewTempWordName;

                Document doc =
                    app.Documents.Add(ref localPatho, ref nothing, ref nothing, ref nothing);
                try
                {
                    List <EmployeeContractBookMark> employeeContractBookMarkList =
                        _GetEmployeeContract.GetRealEmployeeContractBookMarkByContractID(_ContractID);
                    if (employeeContractBookMarkList != null && employeeContractBookMarkList.Count > 0)
                    {
                        foreach (EmployeeContractBookMark mark in employeeContractBookMarkList)
                        {
                            object name = mark.BookMarkName;
                            if (doc.Bookmarks != null)
                            {
                                doc.Bookmarks.get_Item(ref name).Range.Text = mark.BookMarkValue;
                            }
                        }
                    }
                    object fileFormat = WdSaveFormat.wdFormatTemplate97;
                    doc.SaveAs(ref NEWlocalPatho, ref fileFormat, ref nothing, ref nothing,
                               ref nothing, ref nothing, ref nothing,
                               ref nothing, ref nothing, ref nothing,
                               ref nothing, ref nothing, ref nothing,
                               ref nothing, ref nothing, ref nothing);
                    return(_NewTempWordName);
                }
                finally
                {
                    doc.Close(ref nothing, ref nothing, ref nothing);
                    app.Quit(ref nothing, ref nothing, ref nothing);
                }
            }
            return("");
        }
コード例 #2
0
        public List <EmployeeContractBookMark> GetRealEmployeeContractBookMarkByContractID(int contractID)
        {
            GetEmployeeContract GetEmployeeContract = new GetEmployeeContract();

            return(GetEmployeeContract.GetRealEmployeeContractBookMarkByContractID(contractID));
        }