usingnpoi.hssf.usermodel;
using
npoi.ss.usermodel;
using
npoi.xssf.usermodel;
using
system;
using
system.collections.generic;
using
system.data;
using
system.io;
using
system.linq;
using
system.text;
using
system.threading.tasks;
namespace
//////
excel轉換為dataset
/// ///
//////
public dataset exceltodataset(bool isfirstrowcolumn, string
filename)
else
if (filename.indexof("
.xls
") > 0
)
else
#endregion
for (int sheetindex = 0; sheetindex < workbook.numberofsheets; sheetindex++)
str = workbook.numberofsheets +str;
throw
new exception($"
sheet不能為空!引數: 工作簿資訊:");
}#endregion
#region excel最大列數
int maxcolumnnum = 0
;
for (int i = 0; i < sheet.lastrownum; i++)
if (row.lastcellnum >maxcolumnnum)
}#endregion
//excel行數
int maxrownum =sheet.lastrownum;
#region table新增列
for (int i = 0; i < maxcolumnnum; ++i)
else
if (!string
.isnullorwhitespace(cellvalue))
,工作表:");
}mytable.columns.add(
newdatacolumn(cellvalue));}}
if(addemptycell)
}else
}#endregion
//起始行
int startrow = 0
;
if(isfirstrowcolumn)
#region datatable賦值
for (int i = startrow; i <= maxrownum; ++i)
}
else
if (cell.celltype ==celltype.formula)
else
if (filename.indexof("
.xls
") > 0
)
#endregion
}
catch
else}}
else
sheetindex: rowindex: colindex:\r\n");}}
else
}newrow[j] =value;
}mytable.rows.add(newrow);
}#endregion
ds.tables.add(mytable);
}return
ds; }
//////
數字格式的時間 轉換為 字串格式的時間
///數字格式的時間 如: 42095.7069444444/0.650694444444444
/// ///
數字,如:42095.7069444444/0.650694444444444
///日期/時間格式
public
string todatetimevalue(string
strnumber)
::",
(hour
< 10 ? ("
0" +hour) : hour.tostring()),
(minute
< 10 ? ("
0" +minute) : minute.tostring()),
(second
< 10 ? ("
0" +second) : second.tostring()));
if (day > 0
)
return
string.format("
", dt.tostring("
yyyy-mm-dd
"), resulttimes);
else
return
resulttimes;}}
return
string
.empty;
}//////
獲取excel的列名
///這個還是有很多bug 先將就用吧
/// ///
///public
string getexcelcolumnname(int
index)
;string name = ""
;
if (index <=arr.count)}}
else
num = index %arr.count;
name += arr[num - 1
]; }
if ((name.length >= 3
))
return
name;
}//////
datatable 轉換為 html,點選單元格 輸出 單元格所在的 行和列
/// ///
///public
string
gethtmlstring(datatable dt)
"");
int icolscount =dt.columns.count;
int rowscount = dt.rows.count - 1
;
for (int j = 0; j <= rowscount; j++)
if (obj.tostring() == ""
)
string strcellcontent =obj.tostring().trim();
"" + strcellcontent + "");
""); }""
); }""
);
//點選單元格 輸出 行和列");
"");"
");return
sb.tostring();}}
}
基於NPOI開源框架寫的ExcelHelper
namespace exceltest datatable匯出到excel的memorystream 源datatable 表頭文字 public static memorystream export datatable dtsource,string strheadertext endregion...
基於NPOI開源框架寫的ExcelHelper
namespace exceltest datatable匯出到excel的memorystream 源datatable 表頭文字 public static memorystream export datatable dtsource,string strheadertext endregion...
C 開源專案
1.emule 2.todolist 3.ftpserver 4.wxwidgets 5.tightvnc 6.codejock.xtreme.suite.pro.activex 7.jrtplib 8.boost 9.nopepad 10.opencv 11.qt,gtk 12.openoffic...