1 // <summary> 2 /// 创建一个的excel工作薄- 3 /// </summary> 4 /// <returns></returns> 5 public void InputExcel() 6 { 7 try 8 { 9 //Instantiate a new workbook 10 Workbook workbook = new Workbook(); 11 workbook.Worksheets[0].Name = "我的工作薄"; 12 //Set default font 13 Aspose.Cells.Style style = workbook.DefaultStyle; 14 style.Font.Name = "Tahoma"; 15 workbook.DefaultStyle = style; 16 17 Cells cells = workbook.Worksheets[0].Cells; 18 cells.InsertRow(0); 19 for (int j = 0; j < 2; j++) 20 { 21 Cell cell = cells[0, j];//i行j列 22 #region 生成表头 23 if (j == 0) 24 { 25 cell.PutValue("员工姓名"); 26 } 27 if (j == 1) 28 { 29 cell.PutValue("邮箱"); 30 } 31 #endregion 32 } 33 //return workbook; 34 String filename = string.Format("{0}{1}.xls", "saleranklist", Convert.ToDateTime(DateTime.Now).ToString("yyyyMMdd")); //文件默认命名方式,可以自定义 35 Response.ContentType = "application/ms-excel;charset=utf-8"; 36 Response.AddHeader("content-disposition", "attachment; filename=" + filename); 37 System.IO.MemoryStream memStream = workbook.SaveToStream(); 38 Response.BinaryWrite(memStream.ToArray()); 39 Response.End(); 40 41 } 42 catch (System.Exception ex) 43 { 44 45 } 46 }