91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 1.79MB
    文件類型: .zip
    金幣: 2
    下載: 1 次
    發布日期: 2023-10-02
  • 語言: C#
  • 標簽: excel,C#??

資源簡介

C#操作excel,導入excel,導出excel,對excel進行操作

資源截圖

代碼片段和文件信息

using?System.Collections.Generic;
using?System.Data;
using?System.IO;
using?System.Linq;
using?NPOI.HSSF.UserModel;
using?NPOI.SS.UserModel;
using?NPOI.XSSF.UserModel;

public?class?ExcelHelper
{
????public?class?x2003
????{
????????#region?Excel2003
????????///?
????????///?將Excel文件中的數據讀出到DataTable中(xls)
????????///?

????????///?
????????///?
????????public?static?DataTable?ExcelToTableForXLS(string?file)
????????{
????????????DataTable?dt?=?new?DataTable();
????????????using?(FileStream?fs?=?new?FileStream(file?FileMode.Open?FileAccess.Read))
????????????{
????????????????HSSFWorkbook?hssfworkbook?=?new?HSSFWorkbook(fs);
????????????????ISheet?sheet?=?hssfworkbook.GetSheetAt(0);

????????????????//表頭
????????????????IRow?header?=?sheet.GetRow(sheet.FirstRowNum);
????????????????List?columns?=?new?List();
????????????????for?(int?i?=?0;?i?????????????????{
????????????????????object?obj?=?GetValueTypeForXLS(header.GetCell(i)?as?HSSFCell);
????????????????????if?(obj?==?null?||?obj.ToString()?==?string.Empty)
????????????????????{
????????????????????????dt.Columns.Add(new?DataColumn(“Columns“?+?i.ToString()));
????????????????????????//continue;
????????????????????}
????????????????????else
????????????????????????dt.Columns.Add(new?DataColumn(obj.ToString()));
????????????????????columns.Add(i);
????????????????}
????????????????//數據
????????????????for?(int?i?=?sheet.FirstRowNum?+?1;?i?<=?sheet.LastRowNum;?i++)
????????????????{
????????????????????DataRow?dr?=?dt.NewRow();
????????????????????bool?hasValue?=?false;
????????????????????foreach?(int?j?in?columns)
????????????????????{
????????????????????????dr[j]?=?GetValueTypeForXLS(sheet.GetRow(i).GetCell(j)?as?HSSFCell);
????????????????????????if?(dr[j]?!=?null?&&?dr[j].ToString()?!=?string.Empty)
????????????????????????{
????????????????????????????hasValue?=?true;
????????????????????????}
????????????????????}
????????????????????if?(hasValue)
????????????????????{
????????????????????????dt.Rows.Add(dr);
????????????????????}
????????????????}
????????????}
????????????return?dt;
????????}

????????///?
????????///?將DataTable數據導出到Excel文件中(xls)
????????///?

????????///?
????????///?
????????public?static?void?TableToExcelForXLS(DataTable?dt?string?file)
????????{
????????????HSSFWorkbook?hssfworkbook?=?new?HSSFWorkbook();
????????????ISheet?sheet?=?hssfworkbook.CreateSheet(“Test“);

????????????//表頭
????????????IRow?row?=?sheet.CreateRow(0);
????????????for?(int?i?=?0;?i?????????????{
????????????????ICell?cell?=?row.CreateCell(i);
????????????????cell.SetCellValue(dt.Columns[i].ColumnName);
????????????}

????????????//數據
????????????for?(int?i?=?0;?i?????????????{
????????????????I

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-10-17?11:35??導出excel\
?????文件?????????632??2017-10-13?17:07??導出excel\ImportHelper.aspx
?????文件????????8675??2017-10-13?17:08??導出excel\ImportHelper.aspx.cs
?????文件????????1143??2017-10-13?17:07??導出excel\ImportHelper.aspx.designer.cs
?????目錄???????????0??2017-10-19?09:45??導入excel\
?????文件????????9663??2017-07-28?10:08??導入excel\ExcelHelper.cs
?????目錄???????????0??2017-10-18?15:53??導入excel\導入excelBll\
?????文件??????200704??2017-03-14?11:38??導入excel\導入excelBll\ICSharpCode.SharpZipLib.dll
?????文件?????1599488??2017-03-14?11:38??導入excel\導入excelBll\NPOI.dll
?????文件??????395776??2017-03-14?11:38??導入excel\導入excelBll\NPOI.OOxml.dll
?????文件??????431466??2017-03-14?11:38??導入excel\導入excelBll\NPOI.OOxml.xml
?????文件???????84480??2017-03-14?11:38??導入excel\導入excelBll\NPOI.Openxml4Net.dll
?????文件??????153211??2017-03-14?11:38??導入excel\導入excelBll\NPOI.Openxml4Net.xml
?????文件?????1866240??2017-03-14?11:38??導入excel\導入excelBll\NPOI.OpenxmlFormats.dll
?????文件?????2133648??2017-03-14?11:38??導入excel\導入excelBll\NPOI.xml

評論

共有 條評論

相關資源