C#匯出Excel動態列

來源:互聯網
上載者:User

標籤:datagridview   style   blog   io   ar   color   os   sp   for   

一、用StreamWrite流對象,匯出Excel

 1、

 string _sPath = GenerateSalaryMonthlyReport(dgvSalarySum); System.Diagnostics.Process.Start(_sPath);

2、

 public String GenerateSalaryMonthlyReport(DataGridView dgvData)        {            String _sPath = String.Format(@".\{0}.txt", BaseClass.getGUID());            String _sGoal = String.Format(@"{0}{1}.xls", System.Configuration.ConfigurationManager.AppSettings["Statistic"],                                                         BaseClass.ExcelFileName("員工每月薪酬表"));            System.IO.StreamWriter _sw = new System.IO.StreamWriter(_sPath, false, Encoding.Default);            //表頭            _sw.WriteLine("人力寶人力資源管理系統V2.0");            _sw.WriteLine("薪酬管理模組 <<員工每月薪酬表>>");            _sw.WriteLine();            _sw.Write(String.Format("{0}\t", "序號"));            foreach (DataGridViewColumn dgvc in dgvData.Columns)            {                if (dgvc.Visible)                {                    _sw.Write(String.Format("{0}\t", dgvc.HeaderText));                }            }            _sw.Write(String.Format("{0}\t{1}\t{2}", "員工簽字", "日期", "備忘"));            _sw.WriteLine();            int i = 1;            foreach (DataGridViewRow dgvr in dgvData.Rows)            {                _sw.Write(String.Format("{0}", i));                for (int j = 0; j < dgvData.Columns.Count - 1; j++)                {                    if (dgvData.Columns[j].Visible)                    {                        if (j == 3)                        {                            _sw.Write(String.Format("\t‘{0}", dgvr.Cells[j].Value));                        }                        else                         {                         _sw.Write(String.Format("\t{0}", dgvr.Cells[j].Value));                        }                    }                }                i++;                _sw.WriteLine();            }            _sw.WriteLine();            _sw.WriteLine(String.Format("{0}\t\t{1}\t\t\t\t{2}\t\t{3}", "製表人", "製表日期", "審核人", "審核日期"));            _sw.Close();            System.IO.File.Move(_sPath, _sGoal);            return _sGoal;        }

 

C#匯出Excel動態列

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.