VS 2010 使用小積累

ctrl+k,ctrl+d代碼自動整理快捷鍵
ctrl+e,c     註釋選中的代碼
ctrl+e,u     取消註釋選中的代碼c#

streamwrite 的聲明 using system.io;ide

c# 調用計算器的方法:System.Diagnostics.Process.Start("calc.exe");
 調用記事本的方法:System.Diagnostics.Process.Start("notepad.exe");excel

//將datagridview中的數據轉換成excel數據的方法:對象

public bool ExportDataGridview(DataGridView gridView,bool isShowExcle)
        {
            if (gridView.Rows.Count == 0)
                return false;
            //創建Excel對象string

            Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();it

            //Microsoft.Office.Interop.Excel._Application excel = new Microsoft.Office.Interop.Excel.ApplicationClass();  io

            excel.Application.Workbooks.Add(true);
            excel.Visible = isShowExcle;
            //生成字段名稱
            for (int i = 0; i < gridView.ColumnCount; i++)
            {
                excel.Cells[1, i + 1] = gridView.Columns[i].HeaderText;
            }
            //填充數據
            for (int i = 0; i < gridView.RowCount-1; i++)
            {
                for (int j = 0; j < gridView.ColumnCount; j++)
                {
                    if (gridView[j, i].ValueType == typeof(string))
                    {
                        excel.Cells[i + 2, j + 1] = "'" + gridView[j, i].Value.ToString();
                    }
                    else
                    {
                        excel.Cells[i + 2, j + 1] = gridView[j, i].Value.ToString();
                    }
                }
            }
            return true;
        }class

相關文章
相關標籤/搜索