資源簡介
用npoi進行excel的讀寫操作,用C#實現,運行環境VS2013及以上,附帶winform界面

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Threading.Tasks;
using?System.Windows.Forms;
using?NPOI.HSSF.UserModel;
using?NPOI.HPSF;
using?NPOI.XSSF;
using?NPOI.XSSF.UserModel;
using?NPOI.POIFS.FileSystem;
using?NPOI.Util;
using?NPOI.SS.UserModel;
using?System.IO;
using?System.Collections;
namespace?npoi
{
????public?partial?class?FrmMain?:?Form
????{
????????public?FrmMain()
????????{
????????????InitializeComponent();
????????????List?stuList?=?new?List();
????????}
????????private?void?btnShow_Click(object?sender?EventArgs?e)
????????{
????????????//IWorkbook?workbook?=?null;
????????????//IWorkbook?myHSSFworkbook?=?new?HSSFWorkbook();??//用于創建?.xls
????????????//IWorkbook?myXSSFworkbook?=?new?XSSFWorkbook();??//用于創建?.xlsx
????????????this.tmRefreshInterface.Start();
????????}
????????private?void?btnSave_Click(object?sender?EventArgs?e)
????????{
????????}
????????int?count?=?1;
????????private?void?btnModify_Click(object?sender?EventArgs?e)
????????{
????????????this.tmRefreshInterface.Stop();
????????????FileStream?fs?=?new?FileStream(“detailedList.xls“?FileMode.Open?FileAccess.Read);?
????????????IWorkbook?wb?=?new?HSSFWorkbook(fs);
????????????fs.Close();
????????????HSSFSheet?sheet?=?(HSSFSheet)wb.GetSheetAt(0);
????????????if?(sheet.GetRow(0).GetCell(9).ToString()?==?“設備編號“)
????????????????sheet.GetRow(count).GetCell(9).SetCellValue(“已完成“);
????????????count?+=?1;
????????????FileStream?fsWrite?=?new?FileStream(“detailedList.xls“?FileMode.Create);
????????????wb.Write(fsWrite);
????????????fsWrite.Close();
????????????this.tmRefreshInterface.Start();
????????????
????????}
????????private?void?tmRefreshInterface_Tick(object?sender?EventArgs?e)
????????{
????????????List?stuList?=?new?List();
????????????FileStream?fs?=?new?FileStream(“detailedList.xls“?FileMode.Open?FileAccess.Read);
????????????HSSFWorkbook?wb?=?new?HSSFWorkbook(fs);
????????????fs.Close();
????????????HSSFSheet?sheet?=?(HSSFSheet)wb.GetSheetAt(0);
????????????this.tmRefreshInterface.Start();
????????????#region?顯示行
????????????for?(int?i?=?0;?i?????????????{
????????????????try
????????????????{
????????????????????if?(sheet.GetRow(i).GetCell(0).ToString()?==?null)?{?}
????????????????????//執行的代碼,其中可能有異常。一旦發現異常,則立即跳到catch執行。否則不會執行catch里面的內容
????????????????}
????????????????catch
????????????????{
????????????????????break;//除非try里面執行代碼發生了異常,否則這里的代碼不會執行
????????????????}
????????????????stuList.Add(new?Student()
????????????????{
????????????????????SerialNumber?=?sheet.GetRow(i).GetCell(0).ToString()
????????????????????StationName?=?sheet.GetRow(i).GetCell(1).ToString()
????????????????????LineType?=?sheet.GetRow(i).GetCell(2).ToString()
????????????????????TpKilometrePost?=?she
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-10-12?09:06??npoi\
?????目錄???????????0??2019-10-16?16:36??npoi\npoi\
?????文件?????????187??2019-10-12?09:06??npoi\npoi\App.config
?????文件????????8274??2019-10-15?16:27??npoi\npoi\FrmMain.Designer.cs
?????文件????????4715??2019-10-15?16:27??npoi\npoi\FrmMain.cs
?????文件????????8264??2019-10-15?16:27??npoi\npoi\FrmMain.resx
?????文件?????????518??2019-10-12?09:51??npoi\npoi\Program.cs
?????目錄???????????0??2019-10-12?09:06??npoi\npoi\Properties\
?????文件????????1332??2019-10-12?09:06??npoi\npoi\Properties\AssemblyInfo.cs
?????文件????????2860??2019-10-12?09:06??npoi\npoi\Properties\Resources.Designer.cs
?????文件????????5612??2019-10-12?09:06??npoi\npoi\Properties\Resources.resx
?????文件????????1091??2019-10-12?09:06??npoi\npoi\Properties\Settings.Designer.cs
?????文件?????????249??2019-10-12?09:06??npoi\npoi\Properties\Settings.settings
?????文件????????3065??2019-10-16?16:36??npoi\npoi\Student.cs
?????目錄???????????0??2019-10-12?09:51??npoi\npoi\bin\
?????目錄???????????0??2019-10-15?16:18??npoi\npoi\bin\Debug\
?????文件??????200704??2013-03-06?07:13??npoi\npoi\bin\Debug\ICSharpCode.SharpZipLib.dll
?????文件??????387072??2013-03-06?07:17??npoi\npoi\bin\Debug\NPOI.OOxm
?????文件???????79872??2013-03-06?07:17??npoi\npoi\bin\Debug\NPOI.Openxm
?????文件?????1316864??2013-03-06?07:17??npoi\npoi\bin\Debug\NPOI.Openxm
?????文件?????1624064??2013-03-06?07:17??npoi\npoi\bin\Debug\NPOI.dll
?????文件?????2144246??2013-03-06?07:17??npoi\npoi\bin\Debug\NPOI.xm
?????文件??????813056??2019-10-14?17:27??npoi\npoi\bin\Debug\detailedList?-?副本.xls
?????文件??????536576??2019-10-16?15:22??npoi\npoi\bin\Debug\detailedList.xls
?????文件???????16896??2019-10-15?16:27??npoi\npoi\bin\Debug\npoi.exe
?????文件?????????187??2019-10-12?09:06??npoi\npoi\bin\Debug\npoi.exe.config
?????文件???????34304??2019-10-15?16:27??npoi\npoi\bin\Debug\npoi.pdb
?????文件???????23168??2019-10-18?08:39??npoi\npoi\bin\Debug\npoi.vshost.exe
?????文件?????????187??2019-10-12?09:06??npoi\npoi\bin\Debug\npoi.vshost.exe.config
?????文件?????????490??2018-09-15?15:29??npoi\npoi\bin\Debug\npoi.vshost.exe.manifest
?????文件???????18944??2019-10-14?09:33??npoi\npoi\bin\Debug\student.xls
............此處省略19個文件信息
評論
共有 條評論