• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 195,  comments - 30,  trackbacks - 0

            protected void btn_Export_Click(object sender, EventArgs e)
                    {
                        ////刪除保存在服務器的數據
                        //string path1 = Server.MapPath(Request.ApplicationPath) + @"ShoesPic\報價單導出.xls";
                        //System.IO.File.Delete(path1);
                        string filepath=null;
                        GC.Collect();
                        //獲得模板頁的路徑
                        string strFileName = Server.MapPath(Request.ApplicationPath) + @"ShoesPic\template.xls";
                        //string strSaveFileName = Environment.CurrentDirectory + @"\excel\" + System.DateTime.Now.ToString().Replace(":", "").Replace("-", "").Replace(" ", "") + @".xls";
                        Application excel = new Application();
                        Workbook xBk;
                        object missing = System.Reflection.Missing.Value;
                        if (excel == null)
                        {
                            Response.Write("<script>alert('Can't access excel')</script>");
                        }
                        else
                        {
                            try
                            {
                                excel.Visible = true;
                                excel.UserControl = true;
                                //加載Excel模板文件
                                xBk = excel.Application.Workbooks.Open(strFileName, missing, true, missing, missing, missing, missing, missing, missing, true, missing, missing, missing, missing, missing);
                                Worksheet xSt = (Worksheet)xBk.Sheets[1];//第一個sheet頁
                                //xSt.Name = "報價單導出"; //這里修改sheet名稱
                                //xSt.Copy(Type.Missing, xBk.Sheets[1]); //復制xSt成一個新的sheet頁
                                //去讀取數據放入xSt
                                string quoteno = Request["c"].ToString();//獲得報價單編號
                                Basic.QuoteManager manager = new Basic.QuoteManager();
                                Model.Quote quote = manager.getQuotevalueByNo(quoteno);
                                string providername = quote.ProviderName;
                                string brand = quote.Brand;
                                string colthnob = quote.Colthnob;
                                string q_user = quote.Q_User;
                                string phone = quote.Phone;
                                string mobile = quote.Mobile;
                                string c_user = quote.C_User;
                                string principal = quote.Principal;
                                string leader = quote.Leader;
                                string picurl = quote.PicUrl;
                                string user = quote.User;
                                string remark = quote.Remark;
                                string q_date = quote.Q_Date.ToString();
                                string contract_price = quote.Contract_Price.ToString();
                                //報價單位
                                xSt.get_Range("B2", missing).Value2 = providername;
                                //品牌
                                xSt.get_Range("B3", missing).Value2 = brand;
                                //款號/工廠貨號
                                xSt.get_Range("B4", missing).Value2 = colthnob;
                                //報價人
                                xSt.get_Range("B5", missing).Value2 = q_user;
                                //聯系電話
                                xSt.get_Range("B6", missing).Value2 = phone;
                                //移動電話
                                xSt.get_Range("B7", missing).Value2 = mobile;
                                //日期/報價日期
                                xSt.get_Range("D2", missing).Value2 = q_date;
                                //核價人員
                                xSt.get_Range("D3", missing).Value2 = c_user;
                                //品牌負責人
                                xSt.get_Range("D4", missing).Value2 = principal;
                                //分管領導
                                xSt.get_Range("D5", missing).Value2 = leader;
                                //圖片/圖片地址
                                xSt.get_Range("D6", missing).Value2 = picurl;
                                //制單人
                                xSt.get_Range("D7", missing).Value2 = user;
                                //合同價
                                xSt.get_Range("F2", missing).Value2 = contract_price;
                                //備注
                                xSt.get_Range("F3", missing).Value2 = remark;

                                ////明細表數據
                                Basic.QuoteManager manager1 = new Basic.QuoteManager();
                                Model.QuoteDetail[] quotedetail = manager1.getQuoteDetailvalueByNo(quoteno);
                                int count = quotedetail.Length;
                                int rowsint = 10;
                                foreach (Model.QuoteDetail i in quotedetail)
                                {
                                    //item 項目
                                    xSt.Cells.get_Range("A" + rowsint, missing).Value2 = i.Item;
                                    //itemname 名稱
                                    xSt.Cells.get_Range("B" + rowsint, missing).Value2 = i.Itemname;
                                    //unit 單位
                                    xSt.Cells.get_Range("C" + rowsint, missing).Value2 = i.Unit;
                                    //q_dosage 單用量
                                    xSt.Cells.get_Range("D" + rowsint, missing).Value2 = i.Q_Dosage;
                                    // q_unitprice 單價
                                    xSt.Cells.get_Range("E" + rowsint, missing).Value2 = i.Q_UnitPrice;
                                    //q_price 金額
                                    xSt.Cells.get_Range("F" + rowsint, missing).Value2 = i.Q_Price;
                                    rowsint++;
                                }
                                //保存的時候會先保存在服務器上,然后再從服務器下載下來。
                               filepath = Server.MapPath(Request.ApplicationPath) + @"ShoesPic\報價單導出.xls";
                                xBk.Saved = true;
                                xBk.SaveCopyAs(filepath);
                                //退出excel

                                excel.Quit();
                                excel = null;
                                xBk = null;
                                xSt = null;
                                Process[] procs = Process.GetProcessesByName("excel");

                                foreach (Process pro in procs)
                                {
                                    pro.Kill();//沒有更好的方法,只有殺掉進程
                                }
                                GC.Collect();

                                System.IO.FileInfo file = new System.IO.FileInfo(filepath);
                                Response.Clear();
                                Response.Charset = "GB2312";
                                Response.ContentEncoding = System.Text.Encoding.UTF8;
                                // 添加頭信息,為"文件下載/另存為"對話框指定默認文件名
                                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));
                                // 添加頭信息,指定文件大小,讓瀏覽器能夠顯示下載進度
                                Response.AddHeader("Content-Length", file.Length.ToString());

                                // 指定返回的是一個不能被客戶端讀取的流,必須被下載
                                Response.ContentType = "application/ms-excel";

                                // 把文件流發送到客戶端
                                Response.WriteFile(file.FullName);
                                Response.Flush();//這個語句必須有,否則就不回彈出保存的對話框,搞了N久
                                // 停止頁面的執行
                                Response.End();
                            }
                            catch (Exception ex)
                            {
                            }
                            finally
                            {
                                if (File.Exists(filepath))
                                {
                                    File.Delete(filepath);
                                }
                            }
                        }
                      
                    }

            posted on 2011-03-21 13:53 luis 閱讀(853) 評論(0)  編輯 收藏 引用
            <2011年3月>
            272812345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            常用鏈接

            留言簿(3)

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            友情鏈接

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            久久人妻少妇嫩草AV无码专区 | 国产午夜免费高清久久影院| 日韩一区二区三区视频久久| 久久精品国产福利国产琪琪| 亚洲伊人久久成综合人影院| 伊人久久大香线蕉av不卡| 亚洲狠狠婷婷综合久久久久| 国产精品久久久久jk制服| 久久精品国产99久久久香蕉| 精品国产乱码久久久久久人妻| 久久综合久久综合久久综合| 色8激情欧美成人久久综合电| 97久久综合精品久久久综合| 香蕉久久AⅤ一区二区三区| 99久久精品免费观看国产| 久久国产亚洲精品无码| 久久久SS麻豆欧美国产日韩| 久久久精品久久久久久| 久久精品中文字幕第23页| 国产L精品国产亚洲区久久 | 亚洲精品国产美女久久久| 亚洲一区精品伊人久久伊人| 久久人人添人人爽添人人片牛牛| 久久久久国产亚洲AV麻豆| 久久久91人妻无码精品蜜桃HD| 久久久精品久久久久特色影视| 女同久久| 国产精品福利一区二区久久| 久久99精品国产自在现线小黄鸭| 久久精品人成免费| 2020最新久久久视精品爱| 无夜精品久久久久久| 国产成人精品久久二区二区| 性做久久久久久久久老女人| 欧美久久久久久午夜精品| 久久国产精品99精品国产| 久久国产成人午夜aⅴ影院 | 成人国内精品久久久久影院| 伊人久久精品影院| 99久久精品九九亚洲精品| 色偷偷久久一区二区三区|