首先.aspx頁面引用
其次 npoi **
public class excelgameresult
}///
/// 輸出檔案到瀏覽器
///
/// excel文件流
/// http上下文
/// 檔名
/// datatable轉換成excel文件流
///
///
///
public static memorystream rendertoexcel(datatable table)
else if (table.columns.contains("下半場比分"))
else
sheet.setcolumnwidth(5, 18 * 256);
sheet.setcolumnwidth(6, 10 * 256);
sheet.setcolumnwidth(7, 12 * 256);
sheet.setcolumnwidth(8, 13 * 256);
sheet.setcolumnwidth(9, 13 * 256);
sheet.setcolumnwidth(10, 13 * 256);
icell cellsubtitle = headerrow.createcell(column.ordinal);
cellsubtitle.setcellvalue(column.caption);
icellstyle stylesubtitle = workbook.createcellstyle();
stylesubtitle.alignment = horizontalalignment.center;
stylesubtitle.fillpattern = fillpatterntype.solid_foreground;
stylesubtitle.fillforegroundcolor = hssfcolor.black.index;
ifont font = workbook.createfont();
font.color = hssfcolor.white.index;
font.boldweight = (short)fontboldweight.bold;//加粗
font.fontname = "宋體";
font.fontheightinpoints = 11;
stylesubtitle.setfont(font);
cellsubtitle.cellstyle = stylesubtitle;
}int rowindex = 1;
foreach (datarow row in table.rows)
else if (column.tostring() == "半場")
stylesubtitle.alignment = horizontalalignment.center;
//邊框
stylesubtitle.borderbottom = (cellbordertype)npoi.ss.usermodel.borderstyle.thin;
stylesubtitle.borderleft = (cellbordertype)npoi.ss.usermodel.borderstyle.thin;
stylesubtitle.borderright = (cellbordertype)npoi.ss.usermodel.borderstyle.thin;
stylesubtitle.bordertop = (cellbordertype)npoi.ss.usermodel.borderstyle.thin;
cellsubtitle.cellstyle = stylesubtitle;
}rowindex++;
}workbook.write(ms);
ms.flush();
ms.position = 0;}}
}return ms;
}///
/// datatable轉換成excel文件流,並儲存到檔案
///
///
/// 儲存的路徑
public static void rendertoexcel(datatable table, string filename)
}///
/// datatable轉換成excel文件流,並輸出到客戶端
///
///
///
/// 輸出的檔名
NPOI 1 2 4教程 日期函式
excel中有非常豐富的日期處理函式,在npoi中同樣得到了很好的支援。如下圖 建立乙個表 isheet sheet1 workbook.createsheet sheet1 建立乙個sheet irow row1 sheet1.createrow 0 建立一行 irow row2 sheet1.c...
NPOI高效匯出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...
NPOI匯出EXCEL樣式
public void export datarequestrequest,dataresponseresponse endregion region 單元格列值屬性樣式 for int jj 0 jj row1.cells.count jj style endregion cell.setcell...