導出數據生成excel

前臺:

<asp:Button ID="btnMoney" runat="server" Text="經費使用總結表" CssClass="admin_cx marginleft" Height="25" OnClick="btnMoney_Click"  />

后臺:

        protected void btnMoney_Click(object sender, EventArgs e){if (this.ArticleId.Value == ""){this.Alert("請點擊下拉選擇您想操作的文章");return;}int id = Convert.ToInt32(this.ArticleId.Value);string sqlwhere = " ArticleId = " + id + " and State=" + (int)CedureEnum.CapitalDeclareState.Complete;DataSet ds = IBLL.Factory.infoCapitalDeclareCreate().GetPageList(sqlwhere, ref oPageInfo, "a.CreateDate desc");DataTable dt = ds.Tables[0];LeadExcel(dt, "匯總表", "three", id);}#region  生成xls文件//按采購人統計protected void LeadExcel(DataTable dt, string opetes, string state, int ArticleId=0){string filename = opetes + DateTime.Now.ToString("yyyyMMdd") + ".xls";MemoryStream ms = null;try{ms = new MemoryStream();//
                IWorkbook xssfworkbook = null;if (filename.IndexOf(".xlsx") > -1){xssfworkbook = new XSSFWorkbook();}elsexssfworkbook = new HSSFWorkbook();ISheet sheet = xssfworkbook.CreateSheet("Sheet1");ICellStyle cellstyle = xssfworkbook.CreateCellStyle();//設置垂直居中格式cellstyle.Alignment = HorizontalAlignment.CENTER;SetCellRangeAddress(sheet, 0, 0, 0, 7);sheet.DefaultColumnWidth = 28;//string title = "車輛信息";//startdate.ToString("yyyy-MM-dd") + "至" + enddate.ToString("yyyy-MM-dd") + "";//sheet.CreateRow(0).CreateCell(0).SetCellValue("車輛信息");//sheet.GetRow(0).GetCell(0).CellStyle = cellstyle;//SetCellRangeAddress(sheet, 0, 0, 8, 11);//sheet.CreateRow(0).CreateCell(8).SetCellValue("審核結果");//sheet.GetRow(0).GetCell(8).CellStyle = cellstyle;sheet.CreateRow(1).CreateCell(0).SetCellValue("公司名稱");sheet.GetRow(1).CreateCell(1).SetCellValue("項目名稱");sheet.GetRow(1).CreateCell(2).SetCellValue("申請人");sheet.GetRow(1).CreateCell(3).SetCellValue("聯系人");sheet.GetRow(1).CreateCell(4).SetCellValue("聯系電話");sheet.GetRow(1).CreateCell(5).SetCellValue("填報日期"); ;if (dt != null && dt.Rows.Count > 0){int row = 2;//int endrow = 0;//結束行for (int i = 0; i < dt.Rows.Count; i++){sheet.CreateRow(row).CreateCell(0).SetCellValue(dt.Rows[i]["Company"] + "");sheet.GetRow(row).CreateCell(1).SetCellValue(dt.Rows[i]["ProjectName"] + "");sheet.GetRow(row).CreateCell(2).SetCellValue(dt.Rows[i]["Proposer"] + "");sheet.GetRow(row).CreateCell(3).SetCellValue(dt.Rows[i]["Contacts"] + "");sheet.GetRow(row).CreateCell(4).SetCellValue(dt.Rows[i]["Mobile"] + "");sheet.GetRow(row).CreateCell(5).SetCellValue(dt.Rows[i]["CreateDate"] + "");row++;}}xssfworkbook.Write(ms);Response.Clear();Response.Charset = "utf-8";Response.ContentEncoding = System.Text.Encoding.UTF8;Response.AddHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(filename));Response.ContentType = "application/octet-stream";Response.BinaryWrite(ms.ToArray());Response.End();//
            }catch (Exception ex){throw ex;}finally{ms.Dispose();}}/// <summary>/// 合并單元格/// </summary>/// <param name="sheet">要合并單元格所在的sheet</param>/// <param name="rowstart">開始行的索引</param>/// <param name="rowend">結束行的索引</param>/// <param name="colstart">開始列的索引</param>/// <param name="colend">結束列的索引</param>public static void SetCellRangeAddress(ISheet sheet, int rowstart, int rowend, int colstart, int colend){CellRangeAddress cellRangeAddress = new CellRangeAddress(rowstart, rowend, colstart, colend);sheet.AddMergedRegion(cellRangeAddress);}#endregion

?

轉載于:https://www.cnblogs.com/shanshuiYiCheng/p/9629291.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/253550.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/253550.shtml
英文地址,請注明出處:http://en.pswp.cn/news/253550.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

U盤基本處理,U盤與移動固態硬盤

一、辨別 USB2.0 和 USB3.0 1、從USB外觀上來看&#xff0c;USB2.0通常是白色或黑色&#xff0c;而USB3.0則改觀為“高大上”的藍色接口。 目前&#xff0c;部分筆記本電腦USB接口&#xff0c;已同時提供對USB2.0及USB3.0的支持&#xff0c;我們可以通過接口顏色來區別。 2、從…

UWP_小說在線閱讀器:功能要求與技術要求

注&#xff1a;2017年2月23日正式提上日程 學了WP開發也有一年了&#xff0c;也沒做過什么軟件的。17年進發UWP&#xff0c;鍛煉自己一下。做一個開源的小說閱讀器吧。 既然開發一個軟件。所以要設計一下吧。 功能要求&#xff1a; 可能要用到的技術&#xff0c;這個嗎&#xf…

chisel快速入門(二)

上一篇見此&#xff1a; chisel快速入門&#xff08;一&#xff09;_滄海一升的博客-CSDN博客簡單介紹了chisel&#xff0c;使硬件開發者能快速上手chisel。https://blog.csdn.net/qq_21842097/article/details/121415341 十、運行和測試 現在我們已經定義了模塊&#xff0c;…

【WPF】設置TextBox內容為空時的提示文字

原文:【WPF】設置TextBox內容為空時的提示文字<TextBox Width"150" Margin"5"><TextBox.Resources><VisualBrush x:Key"HintText" TileMode"None" Opacity"0.5" Stretch"None" AlignmentX"Le…

視頻矩陣

視頻矩陣&#xff0c;就將視頻圖像從任意一個輸入通道切換到任意一個輸出通道顯示。一般來講,一個MN矩陣&#xff1a;表示它可以同時支持M路圖像輸入和N路圖像輸出。即任意的一個輸入和任意的一個輸出。 視頻矩陣 - 基本功能和要求 一個矩陣系統通常還應該包括以下基本功能&…

Spring 教程03

spring-3 1. Xml<!-- \src\applicationContext-xml.xml --> <?xml version"1.0" encoding"UTF-8"?> <beans xmlns"http://www.springframework.org/schema/beans"xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance…

讀書筆記之《The Art of Readable Code》Part 2

如何寫好流程控制語句(if-else/switch/while/for)使得代碼更可讀些&#xff1f;(chap 7)* 提高條件語句的可讀性(if語句, 或者bool型summary變量) if (length > 10) // Good if (10 < length) // Badwhile (bytes_received < bytes_expected) // Good while (b…

chisel快速入門(三)

前一篇見此&#xff1a; chisel快速入門&#xff08;二&#xff09;_滄海一升的博客-CSDN博客簡單介紹了chisel&#xff0c;使硬件開發者能快速上手chisel。https://blog.csdn.net/qq_21842097/article/details/121418806 十四、模塊的功能創建 制造用于模塊構造的功能接口也…

Redis作者攤上事了:多人要求修改Redis主從復制術語master/slave

作者 | ANTIREZ、小智近日&#xff0c;Redis 作者在 GitHub 上發起了一個“用其他詞匯代替 Redis 的主從復制術語”的 issue。有人認為 Redis 中的術語 master/slave &#xff08;主人 / 奴隸&#xff09;冒犯到了別人&#xff0c;要求 Redis 作者 ANTIREZ 修改這個術語&#x…

????C字符串數組賦值

C字符數組賦值 舉例如下&#xff1a; char a[10]; 1、定義的時候直接用字符串賦值 char a[10]"hello"; 注意&#xff1a;不能先定義再給它賦值&#xff0c;如 char a[10]; a[10]"hello"; 這樣是錯誤的&#xff01; 2、對數組中字符逐個賦值 char a[10]{h…

WP8.1使用HttpClient類

Uri uri new Uri("http://www.cnsos.net/weburl/index.htm", UriKind.Absolute); HttpClient myClient new HttpClient(); string result await myClient.GetStringAsync(uri); await new MessageDialog(result).ShowAsync(); 轉載于:https://www.cnblogs.com/wzw…

HttpClinet學習筆記

本文為學習httpClient學習過程中轉載的文章&#xff0c;若涉及版權請留言。 ----------------------------- 前言 超文本傳輸協議&#xff08;HTTP&#xff09;也許是當今互聯網上使用的最重要的協議了。Web服務&#xff0c;有網絡功能的設備和網絡計算的發展&#xff0c;都持續…

CMOS圖像傳感器——2021產品選談

據Yole統計,2020年全球CMOS圖像傳感器(CIS)市場規模為207億美元,出貨量為70.08億顆。跟其它半導體器件一樣,CIS也因為疫情和生產周期長,以及各種市場因素,而導致采購和供應鏈緊張。Yole預計2021年將趨于平穩,銷售額相比2020年略有增長(3.2%),將達到214億美元,出貨量…

LINUX 下tcp 和 udp 套接字收發緩沖區的大小決定規則 .

const int udp_recvbufsize 384 * 1024 ; int result ::setsockopt(m_hSocket, SOL_SOCKET, SO_RCVBUF, (char*)&udp_recvbufsize, sizeof(int)); // 如果是由于你發送的速率較高而引起的,如500kbit/s, 那么設置大點的UDP緩沖區是比較有效的. LINUX 下tcp 和 udp 套接…

C++匿名對象

匿名對象&#xff1a; string("hello")就是匿名對象&#xff1b; 匿名對象當做參數引用時必須加const; 轉載于:https://www.cnblogs.com/achao123456/p/9634810.html

MVC源碼分析 - Action查找和過濾器的執行時機

接著上一篇, 在創建好Controller之后, 有一個 this.ExecuteCore()方法, 這部分是執行的. 那么里面具體做了些什么呢? //ControllerBaseprotected virtual void Execute(RequestContext requestContext) {if (requestContext null){throw new ArgumentNullException("req…

CCIE-MPLS基礎篇-實驗手冊

又一部前期JUSTECH&#xff08;南京捷式泰&#xff09;工程師職業發展系列叢書完整拷貝。 MPLS&#xff08;Multi-Protocol Label Switching&#xff09; 目錄 1&#xff1a;MPLS 基礎實驗.... 3 1.1實驗拓撲... 3 1.2實驗需求&#xff1a;... 3 1.3實驗步驟... 3 1.4校驗…

數學形態學濾波學習

一、概述 數學形態學是建立在集合論基礎上了一門學科。具體在圖像處理領域,它把形態學和數學中的集合論結合起來,描述二值或灰度圖像中的形態特征,來達到圖形處理的目的。形態學主要是通過結構元素和圖像的相互作用對圖像進行拓補變換從而獲得圖像結構信息,通過對結構信息的…

RCA/BNC接口

RCA接口&#xff08;消費類市場&#xff09; RCA 是Radio Corporation of American的縮寫詞&#xff0c;因為RCA接頭由這家公司發明的。RCA俗稱蓮花插座&#xff0c;又叫AV端子&#xff0c;也稱AV 接口&#xff0c;幾乎所有的電視機、影碟機類產品都有這個接口。它并不是專門為…

Retrofit2源碼解析——網絡調用流程(下)

Retrofit2源碼解析系列 Retrofit2源碼解析(一)Retrofit2源碼解析——網絡調用流程(上)本文基于Retrofit2的2.4.0版本 implementation com.squareup.retrofit2:retrofit:2.4.0 復制代碼上次我們分析到網絡請求是通過OkHttpCall類來完成的&#xff0c;下面我們就來分析下OkHttpCa…