版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、怎么在C#中用計時器關閉任務管理器2010-07-05 20:48引用命名空間: using System.Diagnostics;計時器事件中的代碼: private void timer1_Tick(object sender, EventArgs e) try this.Activate(); Process myProcess = Process.GetProcesses(); foreach (Process p in myProcess) if (p.ProcessName = "taskmgr") p.Kill(); return; catch (Except
2、ion ex) Console.WriteLine(ex.Message); /5、N個人圍成一圈,由編號為1的人開始報數(shù),報到單數(shù)的退出,報到雙數(shù)的留下。求當只留一個人時,這個人是原來的幾號? using System;using System.Collections.Generic;using System.Text;using System.IO;using System.Collections;namespace Word class TheFive public void GetNum() Console.WriteLine("請輸入圍圈人的總數(shù):"); int
3、sum = int.Parse(Console.ReadLine(); int num = new intsum; int s = sum; int i = 0; int q = 0; int y = 0; int e = 0; for (; i < sum; i+) numi = i + 1; if (i = (sum - 1) i = 0; break; while (s > 1) int j = 0; j = i; int k = i; for (; i < sum; i+)/246 /012345 /135 if (sum > 1) if (j + 1) % 2
4、 = 1) if (numi > 0) numi = 0; s-; /123456 j+; if (s = 1) break;/020406 if (s = 1) break; e = 0; q = 0; for (i = 0; i < sum; i+) if (numi = 0) q+; else nume = numi; e+; if (i = (sum - 1) y = sum - q; for (i = sum - 1; i > 0; i-) if (q > 0) numi = 0; q-; else break; if (q = 0) break; i = 0
5、; for (i = 0; i < sum; i+) if (numi > 0) Console.WriteLine(); Console.WriteLine("留下來的是第0位!",numi); break; Excel導出類2010-05-24 16:35using System;using System.Collections.Generic;using System.Text;using System.IO;using System.Data;using System.Windows.Forms;using Microsoft.Office.Intero
6、p.Excel;namespace AssetsManage.Operation class Export private static System.Windows.Forms.DataGridView gridView; private static System.Windows.Forms.ToolStripProgressBar toolStripProgressBar1; private static Timer time; private static DataSet objSet = new DataSet(); private static SaveFileDialog sav
7、eFileDialog = new SaveFileDialog(); private static SaveFileDialog saveFileDialog2 = new SaveFileDialog(); public static System.Windows.Forms.DataGridView _gridView get return gridView; set gridView = value; public static System.Windows.Forms.ToolStripProgressBar _toolStripProgressBar1 get return too
8、lStripProgressBar1; set toolStripProgressBar1 = value; public static Timer _time get return time; set time = value; public static DataSet _objSet get return objSet; set objSet.Clear(); objSet = value; /導出當前頁DataGridView中的數(shù)據(jù)到EXcel中 public static void ExportTOExcel() if (gridView.Rows.Count = 0) Messa
9、geBox.Show("沒有數(shù)據(jù)可供導出!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; else saveFileDialog.Filter = "Execl files (*.xls)|*.xls" saveFileDialog.FilterIndex = 0; saveFileDialog.RestoreDirectory = true; saveFileDialog.CreatePrompt = true; saveFileDialog.T
10、itle = "導出文件保存路徑" saveFileDialog.ShowDialog(); string strName = saveFileDialog.FileName; if (strName.Length != 0) toolStripProgressBar1.Visible = true; System.Reflection.Missing miss = System.Reflection.Missing.Value; Microsoft.Office.Interop.Excel.ApplicationClass excel = new Microsoft.Of
11、fice.Interop.Excel.ApplicationClass(); excel.Application.Workbooks.Add(true); ; excel.Visible = false;/若是true,則在導出的時候會顯示EXcel界面。 if (excel = null) MessageBox.Show("EXCEL無法啟動!", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error); return; Microsoft.Office.Interop.Excel.Workbooks boo
12、ks = (Microsoft.Office.Interop.Excel.Workbooks)excel.Workbooks; Microsoft.Office.Interop.Excel.Workbook book = (Microsoft.Office.Interop.Excel.Workbook)(books.Add(miss); Microsoft.Office.Interop.Excel.Worksheet sheet = (Microsoft.Office.Interop.Excel.Worksheet)book.ActiveSheet; sheet.Name = "te
13、st" /生成字段名稱 for (int i = 0; i < gridView.ColumnCount; i+) excel.Cells1, i + 1 = gridView.Columnsi.HeaderText.ToString(); /填充數(shù)據(jù) for (int i = 0; i < gridView.RowCount - 1; i+) for (int j = 0; j < gridView.ColumnCount; j+) if (gridViewj, i.Value = typeof(string) excel.Cellsi + 2, j + 1 =
14、"" + gridViewi, j.Value.ToString(); else excel.Cellsi + 2, j + 1 = gridViewj, i.Value.ToString(); toolStripProgressBar1.Value += 100 / gridView.RowCount; sheet.SaveAs(strName, miss, miss, miss, miss, miss, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, miss, miss, miss); boo
15、k.Close(false, miss, miss); books.Close(); excel.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(sheet); System.Runtime.InteropServices.Marshal.ReleaseComObject(book); System.Runtime.InteropServices.Marshal.ReleaseComObject(books); System.Runtime.InteropServices.Marshal.ReleaseComObj
16、ect(excel); GC.Collect(); MessageBox.Show("數(shù)據(jù)已經成功導出到:" + saveFileDialog.FileName.ToString(), "導出完成", MessageBoxButtons.OK, MessageBoxIcon.Information); toolStripProgressBar1.Value = 0; toolStripProgressBar1.Visible = false; /- /導出整個DataGridView中的數(shù)據(jù)到Excel中 public static void Expor
17、tTOExcel2() if (gridView.Rows.Count = 0) MessageBox.Show("沒有數(shù)據(jù)可供導出!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; else saveFileDialog2.Filter = "Execl files (*.xls)|*.xls" saveFileDialog2.FilterIndex = 0; saveFileDialog2.RestoreDirectory = true; /sa
18、veFileDialog2.CreatePrompt = true; saveFileDialog2.Title = "導出文件保存路徑" saveFileDialog2.FileName = null; saveFileDialog2.ShowDialog(); string FileName = saveFileDialog2.FileName; if (FileName.Length != 0) toolStripProgressBar1.Visible = true; System.Data.DataTable dt = objSet.Tables0; FileSt
19、ream objFileStream; StreamWriter objStreamWriter; string strLine = "" objFileStream = new FileStream(FileName, FileMode.OpenOrCreate, FileAccess.Write); objStreamWriter = new StreamWriter(objFileStream, System.Text.Encoding.Unicode); toolStripProgressBar1.Value = 0; for (int i = 0; i <
20、dt.Columns.Count; i+) strLine = strLine + dt.Columnsi.ColumnName.ToString() + Convert.ToChar(9); objStreamWriter.WriteLine(strLine); strLine = "" for (int i = 0; i < dt.Rows.Count; i+) strLine = strLine + (i + 1) + Convert.ToChar(9); for (int j = 1; j < dt.Columns.Count; j+) strLine
21、= strLine + dt.Rowsij.ToString() + Convert.ToChar(9); objStreamWriter.WriteLine(strLine); toolStripProgressBar1.Value += 100 / dt.Rows.Count; strLine = "" objStreamWriter.Close(); objFileStream.Close(); MessageBox.Show("數(shù)據(jù)已經成功導出到:" + saveFileDialog2.FileName.ToString(), "導出完
22、成", MessageBoxButtons.OK, MessageBoxIcon.Information); toolStripProgressBar1.Value = 0; toolStripProgressBar1.Visible = false; / /導出到XML(整個數(shù)據(jù)源) public static void ExportTOXML() if (gridView.Rows.Count = 0) MessageBox.Show("沒有數(shù)據(jù)可供導出!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; else saveFileDialog2.Filter = "XML file
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025個人購房合同范文
- 2025二級建造師《施工承包與物資采購合同的內容》課后練習
- 牙科正畸固定矯治器的構成與安裝
- 2024年醫(yī)院醫(yī)療美容服務人員勞動合同3篇
- 2024年度新型暖氣管道鋪設及維修服務合同
- 2024年精裝修樣板房項目協(xié)議范例版B版
- 簽約會員合同范例
- 占用房屋合同范例
- 商丘工學院《機械工程訓練A》2023-2024學年第一學期期末試卷
- 商洛學院《綠色建筑》2023-2024學年第一學期期末試卷
- 2022年08月內蒙古自治區(qū)文物考古研究院自主公開招聘5人筆試題庫含答案解析
- 地質大勘查地球化學課件05水化學找礦、氣體勘查及生物勘查
- 杭州灣跨海大橋鋼樁腐蝕防護
- 軟件版本說明
- 大學人工智能期末考試題
- 《基于PLC的五層電梯控制系統(tǒng)設計(論文)》10000字
- 2023-2024學年湖南省漣源市初中語文七年級上冊期末評估試卷
- 2023-2024學年山東省青島市小學語文二年級上冊期末通關試題
- GB/T 26158-2010中國未成年人人體尺寸
- 納米酶研究進展
- 應用統(tǒng)計學實驗指導書
評論
0/150
提交評論