友情链接1:21点 足球投注 投注网 明升体育 hg0088 葡京赌场 网上赌球 诈金花 澳门金沙网址 澳门银河网址 澳门银河 澳门银河官网 银河官网 威尼斯人 澳门威尼斯人 澳门威尼斯人官网 威尼斯人官网 金沙 澳门金沙 澳门金沙官网 金沙官网 现金网 赌球网 全讯网 明升国际 足球开户 ******官网 ******网址 现金赌博 澳门现金网 ******官方网站

DevExpress-GridControl鏁版嵁瀵煎嚭鍒癊XCEL « Carey's Blog - 寤栧媷鐨勫崥瀹

DevExpress-GridControl鏁版嵁瀵煎嚭鍒癊XCEL

鏃堕棿锛2013骞04鏈28鏃浣滆咃細Carey闃呰(10,748)璇勮(4)

灏咲evExpress-GridControl鏁版嵁瀵煎嚭鍒癊XCEL,鐩墠鐢ㄨ繃涓ょ,涓涓哄埄鐢℅ridControl鍑芥暟鎿嶄綔,涓涓虹敤娴(IO)鎿嶄綔.鍖哄埆鍦ㄤ簬鍓嶈呭彲浠ュ皢浣犲湪GridControl鎵瑙佹牸寮忓叏閮ㄥ鍏XCEL,姣斿鏈夋椂鍊欐垜浠湪Bands閲岄潰鎷栨嫿鍑烘潵鐨凾itle鏍峰紡,鍚庤呮渶澶т紭鐐瑰湪浜庨熷害寰堝揩,浜叉祴10W鏉℃暟鎹鍑哄彧闇2绉掑乏鍙;

No.1:鐢℅ridControl鍑芥暟瀵煎嚭鏁版嵁鍒癊XCEL,寤鸿璁剧疆Options涓婳ptionsPrint—AutoWidth=False,浣垮鍑哄悗鍗曞厓鏍煎搴︽牴鎹唴瀹归暱搴﹁嚜鍔ㄨ皟鏁.

SaveFileDialog fileDialog = new SaveFileDialog();
            fileDialog.Filter = "Excel鏂囦欢娄*.xls;";
            fileDialog.FileName = this.Text + DateTime.Now.ToString("yyMMddHHmm");
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                gridControl1.ExportToXls(fileDialog.FileName);
                XtraMessageBox.Show("鎿嶄綔鎴愬姛!", "鎿嶄綔鎻愮ず", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }

No.2:鐢ㄦ祦灏嗘暟鎹鍏XCEL.

#region 鐢ㄦ祦灏嗘暟鎹鍏ュ埌Excel涓
        public static void DataGridToExcel(DataTable dt, GridView dgv, string orderDateTime, string title)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "Execl (*.xls)娄*.xls娄 Execl (*.xlsx)娄*.xlsx";
            saveFileDialog.FilterIndex = 0;
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.CreatePrompt = true;
            saveFileDialog.Title = "瀵煎嚭Excel鏂囦欢鍒";

            DateTime now = SystemManage.GetTimeNow();
            saveFileDialog.FileName = title + orderDateTime;

            DialogResult dr = saveFileDialog.ShowDialog();
            if (dr == DialogResult.Cancel)
                return;
            Stream myStream;

            myStream = saveFileDialog.OpenFile();
            string fileName = saveFileDialog.FileName;
            if (fileName == "")
            {

                XtraMessageBox.Show("璇疯緭鍏ユ枃浠跺悕!", "鎿嶄綔鎻愮ず", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            StreamWriter sw = new StreamWriter(myStream, System.Text.Encoding.GetEncoding("gb2312"));
            string str = "";
            try
            {
                //鍐欐爣棰
                string stc = title + orderDateTime;

                sw.WriteLine(stc);
                for (int i = 0; i <= dgv.Columns.Count; i++)
                {
                    if (i == 0)
                    {
                        str += "搴忓彿";
                    }
                    else
                    {
                        if (dgv.Columns[i - 1].Visible == true)
                        {
                            str += "\t";
                            str += dgv.Columns[i - 1].Caption;
                        }

                    }
                }

                sw.WriteLine(str);
                int count = 0;
                //鍐欏唴瀹
                for (int j = 0; j < dt.Rows.Count; j++)
                {
                    count++;
                    string tempStr = "";
                    for (int k = 0; k < dt.Columns.Count + 1; k++)
                    {
                        if (k == 0)
                        {
                            tempStr = count.ToString();
                        }
                        else
                        {
                            if (dgv.Columns[k - 1].Visible == true)
                            {
                                tempStr += "\t";
                                tempStr += dt.Rows[j][k - 1].ToString().Trim();

                            }
                        }

                    }
                    sw.WriteLine(tempStr);

                }
                sw.Close();
                sw.Dispose();
                myStream.Close();
                myStream.Dispose();

                XtraMessageBox.Show("鎿嶄綔鎴愬姛!", "鎿嶄綔鎻愮ず", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            catch (Exception e)
            {

                XtraMessageBox.Show("鎿嶄綔澶辫触!", "鎿嶄綔鎻愮ず", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            finally
            {
                sw.Close();
                myStream.Close();

            }
        }
        #endregion

OK,璋冪敤灏辩畝鍗曚簡:

ClassName.DataGridToExcel(dt, gridView1, SystemManage.GetTimeNow().ToString(鈥測yMMddHHmmss鈥), this.Text + 鈥滄姤琛ㄢ);

澹版槑: 鏈枃閲囩敤 BY-NC-SA 鍗忚杩涜鎺堟潈 | Carey's Blog
杞浇璇锋敞鏄庤浆鑷DevExpress-GridControl鏁版嵁瀵煎嚭鍒癊XCEL

4鏉¤瘎璁
  1. 35绉掓潃缃鐣欒█浜:2013骞05鏈01鏃12:23

    鍗氭枃鏈夋洿鏂颁簡鍚楋紵濂戒箙娌℃潵杩囧挴

    • Carey鐣欒█浜:2013骞05鏈02鏃10:00

      鎴戜篃鎳掍簡寰堜箙浜

  2. 35绉掓潃缃鐣欒█浜:2013骞05鏈04鏃12:33

    涓嶆涓娆$殑鏉ヨ繃锛屾湁浠峰肩殑鍗氬锛屾敹钘忓厛~

  3. 灏辨槸鍝堝搱鐣欒█浜:2013骞05鏈12鏃00:58

    寰堜箙娌℃潵浜嗭紝鏈夋洿鏂帮紝鐩稿綋缁欏姏鍟妦

姝ゆ棩蹇楀凡鍏抽棴璇勮锛