namespace exceltest}}/// /// datatable匯出到excel的memorystream
///
/// 源datatable
/// 表頭文字
public static memorystream export(datatable dtsource, string strheadertext)
#endregion
hssfcellstyle datestyle = workbook.createcellstyle() as hssfcellstyle;
hssfdataformat format = workbook.createdataformat() as hssfdataformat;
datestyle.dataformat = format.getformat("yyyy-mm-dd");
//取得列寬
int arrcolwidth = new int[dtsource.columns.count];
foreach (datacolumn item in dtsource.columns)
for (int i = 0; i < dtsource.rows.count; i++)}}
int rowindex = 0;
foreach (datarow row in dtsource.rows)
#region 表頭及樣式
#endregion
#region 列頭及樣式
sheet.createfreezepane(0, 2, 0, dtsource.columns.count - 1);
}#endregion
rowindex = 2;
}#endregion
#region 填充內容
hssfrow datarow = sheet.createrow(rowindex) as hssfrow;
foreach (datacolumn column in dtsource.columns)
}#endregion
rowindex++;
}using (memorystream ms = new memorystream())
}/// /// 用於web匯出
///
/// 源datatable
/// 表頭文字
/// 檔名
public static void exportbyweb(datatable dtsource, string strheadertext, string strfilename)
/// 讀取excel
/// 預設第一行為標頭
///
/// excel文件路徑
///
public static datatable import(string strfilename)
hssfsheet sheet = hssfworkbook.getsheetat(0) as hssfsheet;
system.collections.ienumerator rows = sheet.getrowenumerator();
hssfrow headerrow = sheet.getrow(0) as hssfrow;
int cellcount = headerrow.lastcellnum;
for (int j = 0; j < cellcount; j++)
for (int i = (sheet.firstrownum + 1); i <= sheet.lastrownum; i++)
dt.rows.add(datarow);
}return dt;}}
}
基於NPOI開源框架寫的ExcelHelper
namespace exceltest datatable匯出到excel的memorystream 源datatable 表頭文字 public static memorystream export datatable dtsource,string strheadertext endregion...
基於wsgiref模組寫的web框架
基於wsgiref web框架 from wsgiref.server import make server from urls import urls from views import def run env,response param env 請求相關的所有資料型別 param respon...
基於NPOI的Excel資料匯入
從excel匯入資料最令人頭疼的是資料格式的相容性,特別是日期型別的相容性。為了能夠無腦匯入日期,折騰了一天的npoi。在經過測試確實可以匯入任意格式的合法日期後,寫下這篇小文,與大家共享。完整 請移步 2016 11 13 04 06 修正乙個bug。由try datecellvalue改為判斷列...