NPOI-Excel导出方案
version:2.2.1.0
static void Main(string[] args) { //Calculate("NORMDIST(A1,B1,C1,D1)"); HSSFWorkbook book = new HSSFWorkbook(); ISheet sheet = book.CreateSheet(); var row = sheet.CreateRow(0);//创建新的一行 var idCell_1 = row.CreateCell(0); var idCell_2 = row.CreateCell(1); var idCell_3 = row.CreateCell(2); var idCell_4 = row.CreateCell(3); var idCell_5 = row.CreateCell(4); idCell_1.SetCellValue(3.15); idCell_2.SetCellValue(3.53); idCell_3.SetCellValue(0.37); idCell_4.SetCellValue(true); idCell_5.SetCellFormula("A1 + B1 +C1 + D1"); //idCell_5.SetCellFormula("NORMDIST(A1,B1,C1,D1)"); HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(book); idCell_5 = eval.EvaluateInCell(idCell_5); System.Console.WriteLine(idCell_5.NumericCellValue); //string result = idCell_6.ToString(); // bin\Debug\output.xls 保存 //using (var fs = new FileStream("otuput.xls", FileMode.OpenOrCreate, FileAccess.Write)) //{ // book.Write(fs); //} //~ScorePercentage = (int)(excelApplication.WorksheetFunction.NormDist((double)Score, Average, StandardDeviation, true) * 100); //~ExcelApplication excelApplication = new ExcelApplication(); }
public static string Calculate(string formula) { HSSFWorkbook hssfworkbook = new HSSFWorkbook(); ISheet sheet1 = hssfworkbook.CreateSheet("Sheet1"); IRow row = sheet1.CreateRow(0); ICell cell = row.CreateCell(0); //try //{ cell.SetCellFormula(formula); HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(hssfworkbook); cell = eval.EvaluateInCell(cell); //} //TODO:(将来写活) 如果员工信息不全,暂时返回0; //catch //{ // return "0"; //} return cell.ToString(); }
其它:NickLee方案
参考 CIICSMS \SubModule\Bgs\Customer_List.aspx.cs
Excel导入方案: EPPlus.dll 可以实现Excel导入与导出操作

浙公网安备 33010602011771号