一:npoi的使用
1)把excel中的資料輸出
2)將集合中的資料儲存到
excel文件中
3)把資料庫中的資料匯出到excel**中
3)把excel**中的資料匯入到資料庫中。
使用npoi對excel**進行操作:
npoi能夠分析excel檔案的格式,能夠進行常規excel操作,不依賴excel,節省資源,沒有安全性、效能問題,在asp.net中使用最合適,只能處理xls格式的檔案。
工作簿(workbook),工作表(sheet),行(row),單元格(cell),excel中每乙個單元格都是有資料型別的,常見的就這四個類
關鍵是實現的步驟
using _49_ado.net複習;
using npoi.hssf.usermodel;
using npoi.ss.usermodel;
using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.data.sqlclient;
using system.drawing;
using system.io;
using system.linq;
using system.text;
using system.threading.tasks;
using system.windows.forms;
namespace _50_通過npoi操作excel**
/// /// 練習1:把集合中的資料匯出excel檔案中
///
///
///
private void button1_click(object sender, eventargs e)
,new person() ,
new person() ,
};//1)建立工作簿,因為是寫入
workbook wkbook = new hssfworkbook();
//2)在此工作簿中建立工作表
sheet st = wkbook.createsheet("list for person");
//3)遍歷單元格,進行匯入
//向該工作表中插入行與單元格
for (int i = 0; i < list.count; i++)
//4)把記憶體中的workbook物件寫入到磁碟上
using (filestream fstream = file.openwrite("person.xls"))
messagebox.show("寫入成功!");
}/// /// 練習2:把excel檔案中的資料遍歷輸出
/// 除錯----->視窗----->輸出
///
///
///
private void button2_click(object sender, eventargs e)
| ", value);
}//進行換行輸出
console.writeline();}}
}}
/// /// 把資料庫庫表中的資料讀取到excel檔案中
/// 把teacher表中的內容匯入到excel檔案中
///
///
///
private void button3_click(object sender, eventargs e)
//寫入完畢後,把工作簿儲存到磁碟上。
using (filestream fstream = file.openwrite("teacher.xls"))
messagebox.show("匯入資料成功");
}else}}
/// /// 把excel檔案中的資料讀取到資料庫中
///
///
///
private void button4_click(object sender, eventargs e)
;//讀取每一行的資料
row row = sheet.getrow(i);
listlistcell = new list();
for (int j = 1; j < row.lastcellnum-1; j++)
for (int c= 0; c < listcell.count; c++)
//每次插入一行資料
sqlhelper.executenoquery(insert_sql,commandtype.text, pms);}}
}}
}
二:拼音檢索
1)如何把漢字轉化成拼音(如何獲取乙個漢字的拼音)?
2)如何簡體中文轉化成正體中文?
3)為什麼要使用拼音檢索?
4)更新資料庫中性名列的拼音
把實現封裝成乙個方法
看幫助文件重點是看類的型別和其中的方法。
運算元據庫時,先把sql語句執行一遍,看看能不能得到自己想要的結果。
using _49_ado.net複習;
using microsoft.international.converters.pinyinconverter;
using microsoft.international.converters.traditionalchinesetosimplifiedconverter;
using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.data.sqlclient;
using system.drawing;
using system.linq;
using system.text;
using system.threading.tasks;
using system.windows.forms;
namespace _51_拼音檢索
/// /// 漢字轉化成拼音
///
///
///
private void button1_click(object sender, eventargs e)
/// /// 簡體中文轉化成正體中文
///
///
///
private void button2_click(object sender, eventargs e)
/// /// 更新資料庫teacher中姓名列的拼音,便於檢索
///
///
///
private void button3_click(object sender, eventargs e)}}
}private void updatesqlby(int teaid, string pinyin)
,new sqlparameter("@teaid",sqldbtype.int) ,
};//使用sqlhelper執行更新操作
sqlhelper.executenoquery(insert_sql, commandtype.text, pms);
}private string getpinyinfromstring(string input)
}return sb.tostring();
}private string getintronationalfrom******(string input)
}}
支援拼音檢索的TextBox擴充套件控制項 使用
如 菜鳥aaa等當時想到肯定大家都會用,就沒上傳示例程式。原文為 既然有人問,那就上傳下是下程式。肯定很多人都知道如何用,請越過就是,不要發弁言。主要只有三個屬性暴露出來 1 maxitemcout 這是在多個下拉條時,顯示多少條可見 2 searchmode 檢索方式 只提供了 searchmod...
支援拼音檢索的TextBox擴充套件控制項 使用
如 菜鳥aaa等當時想到肯定大家都會用,就沒上傳示例程式。原文為 既然有人問,那就上傳下是下程式。肯定很多人都知道如何用,請越過就是,不要發弁言。主要只有三個屬性暴露出來 1 maxitemcout 這是在多個下拉條時,顯示多少條可見 2 searchmode 檢索方式 只提供了 searchmod...
NPOI 的使用姿勢
主要是需要注意公式和日期型別的單元格的讀取。開啟指定 excel 檔案 指定要開啟的檔名 excel 檔案對應的單元格 internal exceldatagrid open string filename var sourcefs new filestream filename,filemode....