java 實現excel 導出功能

實現功能:java導出excel表

1、jsp代碼

1 <form id="zhanwForm" action="<%=path%>/conferences.do?" target="_self"  method="get" >
2          <input type="hidden" name="method" value="outData"/>
3          <input type="hidden" name="compassId" value='1'/>
4          <input type="hidden" name="fromWhere" value="AAAA"/>
5 
6 </from>
View Code

2、js代碼

 1      $(".daochu1").click(function(){
 2              var bank = new Array();
 3               $.each($(".guangGaoLeiXing").find("input:checked"), function () {
 4                     bank.push($(this).val());
 5             });    
 6              if(bank == false){
 7                  alert("請選擇要統計類型");
 8              }else{
 9               $("#zhanwForm").submit();    
10             }     
11           })
12         
13          $(".lyBtn").click(function(){
14              $(".mask").show();
15             $(".tishiDiv").show();
16             $.ajax({
17                 url : '<%=path %>/conferences.do?method=getUserLy&fromWhere=csco',
18                 type : 'GET',  
19                 dataType : 'json',  
20                 success : function(data) {
21                      $(".mask").hide();
22                      $(".tishiDiv").hide();
23                       window.open(data.url);
24                 }  
25               })
26          });
View Code

3、action處理代碼

  1 //導出數據
  2     //SELECT SUBSTRING(create_time,1,10) s,COUNT(*)  FROM data_read WHERE data_id IN (SELECT data_id FROM DATA WHERE model_id=2 OR model_id=27)  GROUP BY s
  3     @RequestMapping(params = "method=outData",method = RequestMethod.GET)                  
  4     public void outCompassTongJiData(Integer compassId,String fromWhere,ModelMap model,HttpServletRequest request,HttpServletResponse response)
  5     {        
  6         String urlPath =  request.getScheme()+"://"+request.getServerName()+request.getContextPath();
  7         XSSFWorkbook rwb1 = new XSSFWorkbook();    
  8          
  9         while(true)
 10         {
 11             if(rwb1.getNumberOfSheets() != 0){
 12                 rwb1.removeSheetAt(0);
 13             }
 14             else{ 
 15                 break;
 16             }
 17         }
 18         try {
 19             int bankLong = 0;
 20             int bank1Long = 0;
 21             String []  bank = request.getParameterValues("bank");//廣告類型選擇
 22             String []  bank1 = request.getParameterValues("bank1");//身份選擇
 23             String startTime = request.getParameter("startTime");
 24             String endTime = request.getParameter("endTime");
 25             String[] shenfenList = {"醫生","醫學生","其他"};
 26             String[] zhichengArray = {"主任醫師","副主任醫師","主治醫師","住院醫師(有執業證)","住院醫師(未考執業證)","助理醫師(有執業證)","助理醫師(未考執業證)","其他"};
 27             String typeString1 ="";
 28             String typeString2 ="";
 29             if(bank!=null){
 30                 bankLong = bank.length;                
 31                 for(int i=0;i<bankLong;i++){
 32                     if(bank[i].equals("1")||bank[i].equals("3")||bank[i].equals("8")){                
 33                         typeString1 = typeString1+bank[i]+",";                        
 34                     }else {
 35                         typeString2 = typeString2+bank[i]+",";                        
 36                     }
 37                 }
 38             }
 39             if(typeString1 != null && typeString1.length() != 0){
 40                 typeString1 = typeString1.substring(0, typeString1.length()-1);
 41             }
 42             if(typeString2 != null && typeString2.length() != 0){
 43                 typeString2 = typeString2.substring(0, typeString2.length()-1);
 44             }
 45             if(bank1!=null){
 46                 bank1Long = bank1.length;
 47             }
 48                                     
 49             XSSFSheet ws1 = rwb1.createSheet("統計數據");
 50             ws1.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
 51             ws1.addMergedRegion(new CellRangeAddress(0, 1, 1, 1));
 52             ws1.addMergedRegion(new CellRangeAddress(0, 1, 2, 2));
 53             ws1.addMergedRegion(new CellRangeAddress(0, 1, 3, 3));
 54             ws1.addMergedRegion(new CellRangeAddress(0, 0, 4, 5));
 55             int count = 0;//
 56             int rolNUm = 0;//
 57             
 58             XSSFRow row1 = ws1.createRow(0);
 59             
 60             row1.createCell(rolNUm).setCellValue("類型");
 61             rolNUm++;
 62             row1.createCell(rolNUm).setCellValue("ID");
 63             rolNUm++;
 64             row1.createCell(rolNUm).setCellValue("標題");
 65             rolNUm++;
 66             row1.createCell(rolNUm).setCellValue("地址");
 67             rolNUm++;
 68             row1.createCell(rolNUm).setCellValue("點擊量");//1/2
 69         
 70             count++;
 71             XSSFRow row2 = ws1.createRow(count);            
 72             row2.createCell(rolNUm).setCellValue("總點擊次數");
 73             rolNUm++;
 74             row2.createCell(rolNUm).setCellValue("總點擊用戶數");
 75             //六種統計類型:首頁廣告、上方廣告、session相關性廣告、展商活動、動態(現場秀)、消息站
 76             
 77                     //得到需要統計的廣告類型的集合
 78                     List<CompassTongji> compassTongJis = conferencesService.getCompassTongJiByType(fromWhere,typeString1,typeString2,startTime,endTime);// i,group by dataId    查詢不重復的data
 79                     //如果不為空,遍歷
 80                     if(compassTongJis != null && compassTongJis.size() != 0){
 81                         for(CompassTongji compassTongJi :compassTongJis){ 
 82                             int dataId = compassTongJi.getDataId();//廣告ID
 83                             int type = compassTongJi.getType();
 84                             String title = compassTongJi.getDataTitle();//廣告標題
 85                             String url1 = compassTongJi.getDataUrl()==null?"":compassTongJi.getDataUrl();//廣告地址
 86                             String url = "";
 87                             if(type - 8 == 0){                                                
 88                                 if(url1.indexOf("method=")!= -1){
 89                                     String[] urlStrings = url1.split("&");
 90                                     url = urlStrings[0]+"&"+urlStrings[1];
 91                                 }else{
 92                                     int index = url1.indexOf("?");
 93                                     if(index != -1){
 94                                         url = url1.substring(0, index);
 95                                     }else{
 96                                         url = url1;
 97                                     }
 98                                 }    
 99                             }else{
100                                 int index = url1.indexOf("?");
101                                 if(index != -1){
102                                     url = url1.substring(0, index);
103                                 }else{
104                                     url = url1;
105                                 }
106                                 
107                             }
108                             
109                             //總點擊量
110                             int totalClickNumber = conferencesService.getTotalClickNumber(dataId,url,startTime,endTime,type,fromWhere);
111                             //總點擊人數
112                             int totalClickPeopleNumber = conferencesService.getTotalClickPeopleNumber(dataId,url,startTime,endTime,type,fromWhere);
113                             count++;
114                             XSSFRow row3 = ws1.createRow(count);
115                             rolNUm=0;
116                             row3.createCell(rolNUm).setCellValue(type == 1?"首頁廣告":type ==2?"上方廣告":type==3?"session相關性廣告":type==4?"展商活動":type==5?"動態(現場秀)":type==6?"消息站":type == 7?"彈窗":type == 8?"推送":"首頁模塊");
117                             rolNUm++;
118                             row3.createCell(rolNUm).setCellValue(dataId);
119                             rolNUm++;
120                             row3.createCell(rolNUm).setCellValue(title);
121                             rolNUm++;
122                             row3.createCell(rolNUm).setCellValue(url1);  
123                             rolNUm++;
124                             row3.createCell(rolNUm).setCellValue(totalClickNumber);
125                             rolNUm++;
126                             row3.createCell(rolNUm).setCellValue(totalClickPeopleNumber);
127                             for(int j=0;j<bank1Long;j++){
128                                 int tongJiZiDuan = Integer.valueOf(bank1[j]);
129                                 if (tongJiZiDuan == 1) {
130                                     //領域統計 userLy
131                                     //先查詢所有領域列表
132                                     //遍歷領域列表(compassfield)     根據 領域id 查詢 用戶表(field_id 領域ID  field  領域 )   得到  領域統計信息
133                                     List<CompassField> compassList = conferencesService.getCompassList();
134                                     int compassListLength = compassList.size();
135                                     
136                                     ws1.addMergedRegion(new CellRangeAddress(0, 0, rolNUm+1, compassListLength+rolNUm));    
137                                     row1.createCell(rolNUm+1).setCellValue("領域");
138                                     if(compassList != null && compassList.size()!=0){                                        
139                                         for (CompassField compassField : compassList) {
140                                             int compassFieldId = compassField.getCompassFieldId();
141                                             int countLy = conferencesService.getUserLyInfo(dataId,url,compassFieldId,startTime,endTime,type,fromWhere);
142                                             rolNUm++;
143                                             row2.createCell(rolNUm).setCellValue(compassField.getFieldName());                                                                    
144                                             row3.createCell(rolNUm).setCellValue(countLy);                                                                                            
145                                         }
146                                     }
147                                 }
148                                 if(tongJiZiDuan == 2){//科室統計 userKs    
149                                     List<CompassKs> compassKsListList = conferencesService.getCompassKsList();
150                                     int userKsListLength = compassKsListList.size();
151                                     ws1.addMergedRegion(new CellRangeAddress(0, 0, rolNUm+1, userKsListLength+rolNUm));
152                                     row1.createCell(rolNUm+1).setCellValue("科室");
153                                     if(compassKsListList != null && compassKsListList.size()!=0){
154                                         for (CompassKs compassKs : compassKsListList) {    
155                                             int compassKsId = compassKs.getCompassKsId();
156                                             int countKs  = conferencesService.getUserKsInfo(dataId,url,compassKsId,startTime,endTime,type,fromWhere);
157                                             rolNUm++;                                                
158                                             row2.createCell(rolNUm).setCellValue(compassKs.getKsName());
159                                             row3.createCell(rolNUm).setCellValue(countKs);                                                
160                                         }
161                                     }        
162                                 }
163                                 
164                                 if(tongJiZiDuan == 3){//職稱統計 zhicheng
165                                     int userZhichengListLeng = zhichengArray.length;
166                                     ws1.addMergedRegion(new CellRangeAddress(0, 0, rolNUm+1, userZhichengListLeng+rolNUm));
167                                     row1.createCell(rolNUm+1).setCellValue("職稱");
168                                     for (int k=0;k<userZhichengListLeng;k++) {
169                                         String zhicheng = zhichengArray[k];
170                                         int userZhichengList  = conferencesService.getUserZhichengInfo(dataId,url,startTime,endTime,zhicheng,type,fromWhere);
171                                         rolNUm++;
172                                         row2.createCell(rolNUm).setCellValue(zhicheng);
173                                         row3.createCell(rolNUm).setCellValue(userZhichengList);        
174                                     }
175                                     
176                                 }
177                                 
178                                 if(tongJiZiDuan == 4){//身份統計                                                                             
179                                     int userShenfenListLength = shenfenList.length;                                
180                                     ws1.addMergedRegion(new CellRangeAddress(0, 0, rolNUm+1, userShenfenListLength + rolNUm));
181                                     row1.createCell(rolNUm+1).setCellValue("身份");
182                                     
183                                     for (int k = 0;k<userShenfenListLength;k++) {
184                                         String shenfen = shenfenList[k];
185                                         int countShenFen  = conferencesService.getClickUserShenFenInfo( dataId,url,startTime,endTime,shenfen,type,fromWhere);
186                                         rolNUm++;                                        
187                                         row2.createCell(rolNUm).setCellValue(shenfen);                                        
188                                         row3.createCell(rolNUm).setCellValue(countShenFen);                                                                    
189                                     }                                    
190                                 }
191                                 if(tongJiZiDuan == 5){//省市(市)統計                                    
192                                     List<Hospital> provinceList  = conferencesService.getProvinceList();    
193                                     
194                                     if(provinceList != null && provinceList.size()!=0){
195                                         for (Hospital hospital : provinceList) {                        
196                                             Integer provinceId = hospital.getHospitalId();
197                                             String provinceName = hospital.getProvince();
198                                             
199                                             if(provinceName!=null && provinceName.length() != 0){
200                                                 List<Hospital> cityList = conferencesService.getCityInfoByProvinceId(provinceId);
201                                                 
202                                                 if(cityList != null && cityList.size() != 0){
203                                                     int cityListLength = cityList.size();
204                                                     ws1.addMergedRegion(new CellRangeAddress(0, 0, rolNUm+1, rolNUm+cityListLength));
205                                                     row1.createCell(rolNUm+1).setCellValue(provinceName);    
206                                                     for (Hospital hospital2 : cityList) {
207                                                         //得到市的名稱
208                                                         String cityName = hospital2.getCity();
209                                                         Integer cityId = hospital2.getHospitalId();
210                                                         if(cityName!=null && cityName.length() != 0){
211                                                             int cityNum = conferencesService.getCityInfoByProvinceNameAndCityName(dataId,url,startTime, endTime, cityId,type,fromWhere);
212                                                             rolNUm++;                                    
213                                                             row2.createCell(rolNUm).setCellValue(cityName);                                        
214                                                             row3.createCell(rolNUm).setCellValue(cityNum);    
215                                                         }    
216                                                     }                                                        
217                                                 }    
218                                             }//省不為空
219                                         }                                            
220                                     }    
221                                 }//省市統計結束                                
222                             }                            
223                         }
224                      }//最外if結束        
225                 
226             
227            
228             String filePath = request.getSession().getServletContext().getRealPath("files/execl");
229             File conFile = new File(filePath);                 //目錄結構
230             if(!conFile.exists())
231             {
232                 conFile.mkdir();
233             }    
234             String fileName = "compassTongJi.xlsx";
235             File file = new File(filePath+"/"+fileName);
236             if(file.exists())
237             {
238                 file.delete();
239             }
240             else{
241                 file.createNewFile();
242             }    
243             FileOutputStream fout = new FileOutputStream(file);
244             rwb1.write(fout);
245             fout.close();
246             //JSONObject jsonObject = new JSONObject();
247             //jsonObject.accumulate("url",request.getContextPath()+"/files/execl/"+fileName);
248             //writeToJson(response, jsonObject.toString());
249             String urlString ="<script type='text/javascript'>window.parent.open('"+urlPath+"/files/execl/"+fileName+"')</script>";
250             PrintWriter out = response.getWriter();
251             response.setCharacterEncoding("utf-8");
252             response.setContentType("text/html;charset=UTF-8");
253             out.write(urlString);
254             out.flush();
255             out.close();
256         } catch (Exception e) {
257             // TODO: handle exception
258             e.printStackTrace();
259         }
260     }
View Code

夢想是一個說出來就矯情的東西,它是生長在暗地里的一顆種子,只有破土而出,拔節而長,終有一日開出花來,才能正大光明的讓所有人都知道。在此之前,除了堅持,別無選擇。

轉載于:https://www.cnblogs.com/jichuang/p/8036144.html

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

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

相關文章

python 內置模塊 subprocess

1、介紹 subprocess模塊可以生成新的進程&#xff0c;連接到它們的input/output/error管道&#xff0c;同時獲取它們的返回碼。 2、基本操作方法 2.1、subprocess的run、call、check_call、check_output函數 subprocess.run(args[, stdout, stderr, shell ...]) 執行args命…

Windows下的FFmpeg 、MEncoder、MPlayer下載地址

視頻轉碼常用的是MEncoder&#xff0c;這個工具包含在MPlayer中&#xff0c;也可以使用FFmpeg&#xff0c;但據說有些格式轉換的時候效率不及MEcoder&#xff0c;所以能用MEncoder轉換的盡量用MEncoder轉換&#xff0c;由于MEncoder暫時還沒有研究&#xff0c;等研究過了再補充…

功率曲線k值_什么叫離心泵的流量——功率曲線?它們之間有什么關系?

流量和功率之間為正比例關系。流量增加時功率也增加&#xff0c;增加快、慢與比轉數有關。比轉數越小&#xff0c;流量增加后功率增加越快&#xff1b;比轉數越大&#xff0c;流量增加后功率增加越慢。 離心泵的性能參數與特性曲線泵的性能及相互之間的關系是選泵和進行流量調節…

什么是CI/CD

一、簡介 CI / CD的采用改變了開發人員和測試人員如何發布軟件。 最初是瀑布模型&#xff0c;后來是敏捷開發&#xff0c;現在是DevOps&#xff0c;這是現代開發人員構建出色的產品的技術路線。隨著DevOps的興起&#xff0c;出現了持續集成&#xff08;Continuous Integration…

FFmpeg在Windows系統下的編譯過程

由于FFMpeg是基于Linux開發的開源項目&#xff0c;源代碼和Windows下最常見的Visual Studio提供的C/C編譯器不兼容&#xff0c;因此它不能使用MSVC編譯。要想使用FFMpeg&#xff0c;最先要解決的問題就是在Windows下配置一個類似Linux的編譯環境&#xff0c;將FFMpeg編譯為二進…

centos 文件夾網絡連接_centos8 安裝后網絡不通及網絡配置

一 修改配置文件設置網絡時首先打開配置文件&#xff0c;配置文件默認如下所示&#xff0c;如果使用dhcp自動獲取ip&#xff0c;只需將ONBOOTno修改為ONBOOTno即可。#網卡配置文件按默認配置TYPEEthernetPROXY_METHODnoneBROWSER_ONLYnoBOOTPROTOdhcpDEFROUTEyesIPV4_FAILURE_F…

STM32 HAL庫詳解 及 手動移植

源&#xff1a; STM32 HAL庫詳解 及 手動移植轉載于:https://www.cnblogs.com/LittleTiger/p/8044047.html

Python 內置函數之 open (文件操作)

正常的文件操作都分三步走&#xff1a;打開文件&#xff0c;操作文件&#xff0c;關閉文件。 python open() 函數用于打開一個文件&#xff0c;創建一個 file 對象&#xff0c;相關的方法才可以調用它進行讀寫 語法 文件句柄 open(文件名,模式) 例如&#xff1a;f open(a…

windows系統下_ffmpeg編譯_2011年

ffmpeg開源庫在linux系統下弄的&#xff0c;是一個很全的音頻和視頻的編解碼庫要在windows下編譯出用于開發的lib庫確實比linux下要麻煩&#xff0c;百度了很久&#xff0c;參照別人的見解終于成功編譯出自己需要的可以用于開發的庫&#xff08;dll的形式&#xff0c;附帶dll的…

部署WEB項目到服務器(三)安裝mysql到linux服務器(Ubuntu)詳解

突發奇想&#xff0c;想在自己電腦上部署一個web網站。 1&#xff0c;首先是下載一個適合自己已安裝服務器版本的mysql數據庫。 這里使用網上的鏈接http://dev.mysql.com/downloads/mysql/5.6.html#downloads 或者使用代理網站上下載&#xff1a;https://mirrors.huaweicloud.c…

在Windows下編譯ffmpeg完全手冊

本文的內容幾乎全部來自于FFmpeg on Windows&#xff0c;但是由于國內的網絡封鎖&#xff0c;很難訪問這個域名下的內容&#xff0c;因此我一方面按照我自己的理解和實踐做了翻譯&#xff0c;另一方面也是為了能提供一個方便的參考方法。 注&#xff1a; 1. 對于compil…

padding和卷積的區別_TensorFlow筆記1——20.CNN卷積神經網絡padding兩種模式SAME和VALID...

第1種解說&#xff1a;(核心最后一張圖&#xff0c;兩種填充方式輸出的形狀尺寸計算公式)在用tensorflow寫CNN的時候&#xff0c;調用卷積核api的時候&#xff0c;會有填padding方式的參數&#xff0c;找到源碼中的函數定義如下&#xff08;max pooling也是一樣&#xff09;&am…

MORMOT數據庫連接池

MORMOT數據庫連接池 MORMOT封裝了一堆的PROPS控件&#xff0c;用于連接各種數據庫。 MORMOT的封裝是武裝到了牙齒的&#xff0c;這堆PROPS控件居然數據庫連接池也封裝好了。這就為我們省了不少事&#xff0c;筆者非常喜歡&#xff01; 下面拿TOleDBMSSQLConnectionProperties控…

循環神經網絡變形之 (Long Short Term Memory,LSTM)

1、長短期記憶網絡LSTM簡介 在RNN 計算中&#xff0c;講到對于傳統RNN水平方向進行長時刻序列依賴時可能會出現梯度消失或者梯度爆炸的問題。LSTM 特別適合解決這種需要長時間依賴的問題。 LSTM&#xff08;Long Short Term Memory&#xff0c;長短期記憶網絡&#xff09;是R…

Windows 系統下使用 MinGW + MSYS + GCC 編譯 FFMPEG

一定要按照順序操作&#xff0c;否則你很可能持續遇到很多奇怪的問題&#xff08;ffmpeg對編譯系統版本要求比較高&#xff09;。 1. www.mingw.org: 下載并安裝 MinGW 5.1.4 (http://jaist.dl.sourceforge.net/sourceforge/mingw/MinGW-5.1.4.exe)&#xff0c;安裝時選中 g, m…

eclipse怎樣改編碼格式_Eclipse中各種編碼格式及設置

操作系統&#xff1a;Windows 10(家庭中文版)Eclipse版本&#xff1a;Version: Oxygen.1a Release (4.7.1a)剛看到一篇文章&#xff0c;里面介紹說Ascii、Unicode是編碼&#xff0c;而GBK、UTD-8等是編碼格式。Java中的編碼問題(by 迷失之路)&#xff1a;https://www.cnblogs.c…

UE4 ShooterGame Demo的開火的代碼

之前一直沒搞懂按下鼠標左鍵開火之后&#xff0c;代碼的邏輯是怎么走的&#xff0c;今天看懂了之前沒看懂的部分&#xff0c;進了一步 ShooterCharacter.cpp void AShooterCharacter::OnStartFire() {AShooterPlayerController* MyPC Cast<AShooterPlayerController>(Co…

kafka 異常:return ‘<SimpleProducer batch=%s>‘ % self.async ^ SyntaxError: invalid syntax

Python3.X 執行Python編寫的生產者和消費者報錯&#xff0c;報錯信息如下&#xff1a; Traceback (most recent call last): File "mykit_kafka_producer.py", line 9, in <module> from kafka import KafkaProducer File "/usr/local/lib/python3.7/sit…

python 分布式計算框架_漫談分布式計算框架

如果問 mapreduce 和 spark 什么關系&#xff0c;或者說有什么共同屬性&#xff0c;你可能會回答他們都是大數據處理引擎。如果問 spark 與 tensorflow 呢&#xff0c;就可能有點迷糊&#xff0c;這倆關注的領域不太一樣啊。但是再問 spark 與 MPI 呢&#xff1f;這個就更遠了。…

Codeforces 899D Shovel Sale

題目大意 給定正整數 $n$&#xff08;$2\le n\le 10^9$&#xff09;。 考慮無序整數對 $(x, y)$&#xff08;$1\le x,y\le n, x\ne y$&#xff09;。 求滿足 「$xy$ 結尾連續的 9 最多」的數對 $(x,y)$ 的個數。 例子&#xff1a; $n50$&#xff0c;$(49,50)$ 是一個滿足條件的…