荣耀彩票代理

  • 热门专题

如何利用Aspose.Cells导出excel

作者:wy  发布日期:2019-01-12 08:32:00
  •    今天在又有新知识了,敲黑板划重点如何利用Aspose.Cells的组件而导出excel的文件呢,这是一个非常实用的代码,我相信在生活工作、学习技术时都一定会用上,非常的基础非常的实用。赶快拿出电脑试一试吧,唯有实践才能熟知哦。

      ///

    荣耀彩票代理  /// DAOCHUSHUJUDAOBENDI

      ///

    荣耀彩票代理  ///YAODAOCHUDESHUJU

      ///DAOCHUMINGCHENG

    荣耀彩票代理  ///BIAOGEXINGMINGGESHI“ZHANGHAO,MIMA”

      ///QINGQIU

      public static void OutFileToDisk(DataTable dt, string tableName, string tableTitle, HttpResponse response)

      {

      Workbook workbook = new Workbook(); //GONGZUOBU

    荣耀彩票代理  Worksheet sheet = workbook.Worksheets[0]; //GONGZUOBIAO

      Cells cells = sheet.Cells;//DANYUANGE

    荣耀彩票代理  //WEIBIAOTISHEZHIYANGSHI

      Style styleTitle = workbook.Styles[workbook.Styles.Add()];//XINZENGYANGSHI

      styleTitle.HorizontalAlignment = TextAlignmentType.Center;//WENZIJUZHONG

    荣耀彩票代理  styleTitle.Font.Name = "SONGTI";//WENZIZITI

      styleTitle.Font.Size = 18;//WENZIDAXIAO

      styleTitle.Font.IsBold = true;//CUTI

      //YANGSHI2

      Style style2 = workbook.Styles[workbook.Styles.Add()];//XINZENGYANGSHI

      style2.HorizontalAlignment = TextAlignmentType.Center;//WENZIJUZHONG

    荣耀彩票代理  style2.Font.Name = "SONGTI";//WENZIZITI

      style2.Font.Size = 14;//WENZIDAXIAO

      style2.Font.IsBold = true;//CUTI

      style2.IsTextWrapped = true;//DANYUANGENEIRONGZIDONGHUANXING

      style2.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;

    荣耀彩票代理  style2.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;

      style2.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;

    荣耀彩票代理  style2.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;

      

    excel

     

      //YANGSHI3

      Style style3 = workbook.Styles[workbook.Styles.Add()];//XINZENGYANGSHI

      style3.HorizontalAlignment = TextAlignmentType.Center;//WENZIJUZHONG

    荣耀彩票代理  style3.Font.Name = "SONGTI";//WENZIZITI

      style3.Font.Size = 12;//WENZIDAXIAO

      style3.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;

    荣耀彩票代理  style3.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;

    荣耀彩票代理  style3.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;

      style3.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;

      int Colnum = dt.Columns.Count;//BIAOGELIESHU

      int Rownum = dt.Rows.Count;//BIAOGEXINGSHU

    荣耀彩票代理  //SHENGCHENGXING1 BIAOTIXING

      cells.Merge(0, 0, 1, Colnum);//HEBINGDANYUANGE

      cells[0, 0].PutValue(tableName);//TIANXIENEIRONG

    荣耀彩票代理  cells[0, 0].SetStyle(styleTitle);

      cells.SetRowHeight(0, 38);

    荣耀彩票代理  //SHENGCHENGXING2 LIEMINGXING

    荣耀彩票代理  string[] Tile = tableTitle.Split(',');

      for (int i = 0; i < Colnum; i++)

      {

      cells[1, i].PutValue(Tile[i]);

      cells[1, i].SetStyle(style2);

    荣耀彩票代理  cells.SetRowHeight(1, 25);

      }

      //SHENGCHENGSHUJUXING

      for (int i = 0; i < Rownum; i++)

      {

      for (int k = 0; k < Colnum; k++)

      {

    荣耀彩票代理  cells[2 + i, k].PutValue(dt.Rows[i][k].ToString());

      cells[2 + i, k].SetStyle(style3);

      }

      cells.SetRowHeight(2 + i, 24);

      }

    荣耀彩票代理  workbook.Save(response, HttpUtility.UrlEncode(tableName, System.Text.Encoding.UTF8) + ".xls", ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));

      }

      WOMENDEWANGZHANYOUXUDUOLEISIDEZHANDIANFANGBIANDAJIAXUEXI,HAIKEYIHETONGDAOZHIRENZAISIXIANGSHANGDEPENGZHUANGAIHAOSHANGDEJIAOLIU,XIWANGNINENGDUODUOZHICHIWOMENWANGZHAN,WOMENJIUHUITIGONGGENGDUOXUEXI、JIAOYUDEXINXI,XIEXIEDAJIADELIJIEYUZHICHI。

延伸阅读:

About IT165 - 广告服务 - 隐私声明 - 版权申明 - 免责条款 - 网站地图 - 网友投稿 - 联系方式
本站内容来自于互联网,仅供用于网络技术学习,学习中请遵循相关法律法规