




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、怎么在C#中用計(jì)時(shí)器關(guān)閉任務(wù)管理器2010-07-05 20:48引用命名空間: using System.Diagnostics;計(jì)時(shí)器事件中的代碼: 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個(gè)人圍成一圈,由編號(hào)為1的人開(kāi)始報(bào)數(shù),報(bào)到單數(shù)的退出,報(bào)到雙數(shù)的留下。求當(dāng)只留一個(gè)人時(shí),這個(gè)人是原來(lái)的幾號(hào)? using System;using System.Collections.Generic;using System.Text;using System.IO;using System.Collections;namespace Word class TheFive public void GetNum() Console.WriteLine("請(qǐng)輸入圍圈人的總數(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("留下來(lái)的是第0位!",numi); break; Excel導(dǎo)出類(lèi)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; /導(dǎo)出當(dāng)前頁(yè)DataGridView中的數(shù)據(jù)到EXcel中 public static void ExportTOExcel() if (gridView.Rows.Count = 0) Messa
9、geBox.Show("沒(méi)有數(shù)據(jù)可供導(dǎo)出!", "提示", 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 = "導(dǎo)出文件保存路徑" 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,則在導(dǎo)出的時(shí)候會(huì)顯示EXcel界面。 if (excel = null) MessageBox.Show("EXCEL無(wú)法啟動(dòng)!", "錯(cuò)誤", 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" /生成字段名稱(chēng) 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ù)已經(jīng)成功導(dǎo)出到:" + saveFileDialog.FileName.ToString(), "導(dǎo)出完成", MessageBoxButtons.OK, MessageBoxIcon.Information); toolStripProgressBar1.Value = 0; toolStripProgressBar1.Visible = false; /- /導(dǎo)出整個(gè)DataGridView中的數(shù)據(jù)到Excel中 public static void Expor
17、tTOExcel2() if (gridView.Rows.Count = 0) MessageBox.Show("沒(méi)有數(shù)據(jù)可供導(dǎo)出!", "提示", 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 = "導(dǎo)出文件保存路徑" 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ù)已經(jīng)成功導(dǎo)出到:" + saveFileDialog2.FileName.ToString(), "導(dǎo)出完
22、成", MessageBoxButtons.OK, MessageBoxIcon.Information); toolStripProgressBar1.Value = 0; toolStripProgressBar1.Visible = false; / /導(dǎo)出到XML(整個(gè)數(shù)據(jù)源) public static void ExportTOXML() if (gridView.Rows.Count = 0) MessageBox.Show("沒(méi)有數(shù)據(jù)可供導(dǎo)出!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; else saveFileDialog2.Filter = "XML file
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 中班班主任學(xué)期工作計(jì)劃范文(4篇)
- 施工材料購(gòu)銷(xiāo)合同范本
- 線下體驗(yàn)店服務(wù)協(xié)議
- 綠化行業(yè)技術(shù)交流協(xié)議
- 濕式除塵設(shè)備租賃合同(3篇)
- 和人合伙開(kāi)店合同協(xié)議
- 次品蔬菜購(gòu)銷(xiāo)合同協(xié)議
- 性勞動(dòng)合同協(xié)議
- 樓頂廣告布合同協(xié)議
- 微信定制開(kāi)發(fā)合同協(xié)議
- 美國(guó)加征關(guān)稅從多個(gè)角度全方位解讀關(guān)稅課件
- “皖南八?!?024-2025學(xué)年高一第二學(xué)期期中考試-英語(yǔ)(譯林版)及答案
- 一例脂肪液化切口的護(hù)理
- 定額〔2025〕1號(hào)文-關(guān)于發(fā)布2018版電力建設(shè)工程概預(yù)算定額2024年度價(jià)格水平調(diào)整的通知
- 【MOOC】機(jī)械原理-西北工業(yè)大學(xué) 中國(guó)大學(xué)慕課MOOC答案
- 一種基于STM32的智能門(mén)鎖系統(tǒng)的設(shè)計(jì)-畢業(yè)論文
- 煤礦安全監(jiān)控系統(tǒng)設(shè)備管理報(bào)廢制度
- 機(jī)關(guān)事業(yè)單位退休人員養(yǎng)老金領(lǐng)取資格確認(rèn)表
- 第五屆“國(guó)藥工程杯”全國(guó)大學(xué)生制藥工程設(shè)計(jì)競(jìng)賽
- 柔性主動(dòng)防護(hù)網(wǎng)分項(xiàng)工程質(zhì)量檢驗(yàn)評(píng)定表
- 中機(jī)2015~2016年消防系統(tǒng)維保養(yǎng)護(hù)年度總結(jié)報(bào)告
評(píng)論
0/150
提交評(píng)論