C# datagridview 快速导出数据到Excel

2021-01-27 12:12

阅读:612

标签:lex   数据   get   inter   board   clipboard   mic   csharp   count   

  private void copyAlltoClipboard()
        {
            dataGridView1.SelectAll();
            DataObject dataObj = dataGridView1.GetClipboardContent();
            if (dataObj != null)
                Clipboard.SetDataObject(dataObj);
        }

        /// 
        /// 导出数据到Excel
        /// 
        /// 
        /// 
        void btnExportData_Click(object sender, EventArgs e)
        {
            copyAlltoClipboard();
            Microsoft.Office.Interop.Excel.Application xlexcel;
            Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
            Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
            object misValue = System.Reflection.Missing.Value;
            xlexcel = new Microsoft.Office.Interop.Excel.Application();
            xlexcel.Visible = true;
            xlWorkBook = xlexcel.Workbooks.Add(misValue);
            xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
            for (int i = 1; i 

  

C# datagridview 快速导出数据到Excel

标签:lex   数据   get   inter   board   clipboard   mic   csharp   count   

原文地址:https://www.cnblogs.com/JasonBie/p/11946379.html


评论


亲,登录后才可以留言!