婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > 使用Aspose.Cells組件生成Excel文件實例

使用Aspose.Cells組件生成Excel文件實例

熱門標簽:怎樣給陜西地圖標注顏色 ai電銷機器人對貸款有幫助嗎 400電話辦理信任翰諾科技 地圖標注多少錢一張 廣州銷售外呼系統定制 福州人工智能電銷機器人加盟 云狐人工智能電話機器人 電銷機器人 數據 宿遷智能外呼系統排名

生成帶表頭的Excel文件,格式如下顯示。

當然更復雜的一些也可以通過 合并單元格的方法 public void Merge(int firstRow, int firstColumn, int totalRows, int totalColumns)來實現。

實現方式:

1. 首先,需要添加對"Aspose.Cells.dll"的引用。

2. 實現代碼如下:

復制代碼 代碼如下:

//新建工作簿
            Workbook workbook = new Workbook(); //工作簿
            Worksheet sheet = workbook.Worksheets[0]; //工作表
            Cells cells = sheet.Cells;//單元格


            Style style = workbook.Styles[workbook.Styles.Add()];//新增樣式

            #region 表頭
            //標題
            style.HorizontalAlignment = TextAlignmentType.Center;//文字居中 
            style.Font.Name = "宋體";//文字字體
            style.Font.Size = 18;//文字大小 
            style.Font.IsBold = true;//粗體

            cells.Merge(0, 0, 1, 12);               //合并單元格
            cells[0, 0].PutValue("標準化工作意見建議匯總表");   //填寫內容
            cells[0, 0].SetStyle(style);            //給單元格關聯樣式 
            cells.SetRowHeight(0, 28);              //設置行高 


            //發布時間
            style.HorizontalAlignment = TextAlignmentType.Left;
            style.Font.Size = 11;
            style.Font.IsBold = false;
            cells.Merge(1, 0, 1, 7);
            cells[1, 0].PutValue(String.Format("發布起止時間:{0}至{1}",DateTime.Now.AddDays(-1).ToString("yyyy年MM月dd日"),DateTime.Now.ToString("yyyy年MM月dd日")));
            cells[1, 0].SetStyle(style);
            cells.SetRowHeight(1, 20);

            //統計時間
            style.HorizontalAlignment = TextAlignmentType.Right;
            style.Font.Size = 11;
            style.Font.IsBold = false;
            cells.Merge(1, 7, 1, 5);
            cells[1, 7].PutValue(String.Format("統計時間:{0}", DateTime.Now.ToString("yyyy年MM月dd日")));
            cells[1, 7].SetStyle(style);
            cells.SetRowHeight(1, 20);
            #endregion

            #region 表格

            #region 表格標題行
            //序號
            style.HorizontalAlignment = TextAlignmentType.Center;
            cells[2, 0].PutValue("序號");
            cells[2, 0].SetStyle(style);
            cells.SetRowHeight(2, 20);
            cells.SetColumnWidthPixel(0, 38);

            //建議時間
            cells[2, 1].PutValue("建議時間");
            cells[2, 1].SetStyle(style);
            cells.SetColumnWidthPixel(1, 77);

            //建議部門
            cells[2, 2].PutValue("建議部門");
            cells[2, 2].SetStyle(style);
            cells.SetColumnWidthPixel(2, 107);

            //建 議 人
            cells[2, 3].PutValue("建 議 人");
            cells[2, 3].SetStyle(style);
            cells.SetColumnWidthPixel(3, 69);

            //類   別
            cells[2, 4].PutValue("類   別");
            cells[2, 4].SetStyle(style);
            cells.SetColumnWidthPixel(4, 71);

            //業務種類
            cells[2, 5].PutValue("業務種類");
            cells[2, 5].SetStyle(style);
            cells.SetColumnWidthPixel(5, 71);

            //標準名稱
            cells[2, 6].PutValue("標準名稱");
            cells[2, 6].SetStyle(style);
            cells.SetColumnWidthPixel(6, 114);

            //標準章、條編號
            cells[2, 7].PutValue("標準章、條編號");
            cells[2, 7].SetStyle(style);
            cells.SetColumnWidthPixel(7, 104);

            //意見建議
            cells[2, 8].PutValue("意見建議");
            cells[2, 8].SetStyle(style);
            cells.SetColumnWidthPixel(8, 255);

            //處理部門
            cells[2, 9].PutValue("處理部門");
            cells[2, 9].SetStyle(style);
            cells.SetColumnWidthPixel(9, 72);

            //處理進度
            cells[2, 10].PutValue("處理進度");
            cells[2, 10].SetStyle(style);
            cells.SetColumnWidthPixel(10, 72);

            //備注
            cells[2, 11].PutValue("備注");
            cells[2, 11].SetStyle(style);
            cells.SetColumnWidthPixel(11, 255);

            #endregion

            #endregion


            System.IO.MemoryStream ms = workbook.SaveToStream();//生成數據流
            byte[] bt = ms.ToArray();

            workbook.Save(@"E:\test.xls");//保存到硬盤
        }

3. 生成好的Excel可以保存到磁盤,也可以在web頁面上通過流的方式來下載。

復制代碼 代碼如下:

//下載
            System.IO.MemoryStream ms = workbook.SaveToStream();//生成數據流
            byte[] bt = ms.ToArray();

            string fileName = "標準化工作意見建議匯總表" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";//客戶端保存的文件名
            //以字符流的形式下載文件  

            Response.ContentType = "application/vnd.ms-excel";

            //通知瀏覽器下載文件而不是打開
            Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
            Response.BinaryWrite(bt);

            Response.Flush();
            Response.End();

您可能感興趣的文章:
  • 利用Aspose.Cells和Excel模板導出統計數據
  • Aspose.Cells組件導出excel文件
  • C#使用Aspose.Cells導出excel
  • C#使用Aspose.Cells創建和讀取Excel文件
  • Aspose.Cells 讀取受保護有密碼的Excel文件
  • C#使用Aspose.Cells控件讀取Excel
  • C#語言MVC框架Aspose.Cells控件導出Excel表數據

標簽:延安 焦作 大興安嶺 黃南 新疆 曲靖 宜春 綿陽

巨人網絡通訊聲明:本文標題《使用Aspose.Cells組件生成Excel文件實例》,本文關鍵詞  使用,Aspose.Cells,組件,生成,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《使用Aspose.Cells組件生成Excel文件實例》相關的同類信息!
  • 本頁收集關于使用Aspose.Cells組件生成Excel文件實例的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 明星| 专栏| 余姚市| 曲麻莱县| 宜宾市| 虎林市| 五家渠市| 海口市| 衡南县| 都兰县| 巴楚县| 双辽市| 德惠市| 伽师县| 北流市| 班玛县| 垣曲县| 绥滨县| 青岛市| 资溪县| 嫩江县| 屏山县| 孟津县| 垫江县| 崇义县| 南京市| 宽城| 定日县| 曲松县| 南澳县| 岱山县| 和静县| 辉南县| 盘锦市| 遵义市| 嘉鱼县| 德令哈市| 普洱| 时尚| 扶余县| 浑源县|