從數據庫中取出數據表,導入并生成excel

@RequestMapping("/numericalStatement1")public void createExcel(HttpServletResponse resp) throws Exception{try {String path = "G:/test.xlsx";// 創建新的Excel 工作簿XSSFWorkbook workbook = new XSSFWorkbook();// 在Excel工作簿中建一工作表,其名為缺省值// 如要新建一名為"用戶表"的工作表,其語句為:XSSFSheet sheet = workbook.createSheet("成績表");// 在索引0的位置創建行(最頂端的行)XSSFRow row = sheet.createRow((short) 0);//在索引0的位置創建單元格(左上端)XSSFCell cell = row.createCell((short) 0);//創建單元格樣式CellStyle cellStyle = workbook.createCellStyle();// 設置這些樣式
          cellStyle.setFillForegroundColor(HSSFColor.SKY_BLUE.index);cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 定義單元格為字符串類型
          cell.setCellType(HSSFCell.CELL_TYPE_STRING);// 在單元格中輸入一些內容cell = row.createCell((short) 0);cell.setCellValue("成績編號");cell.setCellStyle(cellStyle);cell = row.createCell((short) 1);cell.setCellValue("組織架構參數表編號");cell.setCellStyle(cellStyle);cell = row.createCell((short) 2);cell.setCellValue("試卷編號");cell.setCellStyle(cellStyle);cell = row.createCell((short) 3);cell.setCellValue("客觀題成績");cell.setCellStyle(cellStyle);cell = row.createCell((short) 4);cell.setCellValue("主觀題成績");cell.setCellStyle(cellStyle);cell = row.createCell((short) 5);cell.setCellValue("總成績");cell.setCellStyle(cellStyle);//查詢數據庫中所有的數據
//          ResultMapper mapper = getMapper(ResultMapper.class);
//          VtUserCriteria cri = new VtUserCriteria();
//          cri.createCriteria().andUserEnabledEqualTo(1);
        List<Result> list = resultService.selectAllResult();/*//第一個sheet第一行為標題XSSFRow rowFirst = sheet.createRow(0);rowFirst.setHeightInPoints(21.75f);*/for (int i = 0; i < list.size(); i++) {row = sheet.createRow((int) i + 1);Result stu = (Result) list.get(i);// 第四步,創建單元格,并設置值row.createCell((short) 0).setCellValue(stu.getId());row.createCell((short) 1).setCellValue(stu.getParaorgleadershipsId());row.createCell((short) 2).setCellValue(stu.getPaperId());row.createCell((short) 3).setCellValue(stu.getObjResult());row.createCell((short) 4).setCellValue(stu.getSubResult());row.createCell((short) 5).setCellValue(stu.getTotalResult());sheet.autoSizeColumn((short) 0); //調整第一列寬度(自適應),只識別數字、字母sheet.autoSizeColumn((short) 1); //調整第二列寬度//調整第三列寬度,有中文,先判斷這一列的最長字符串//  int length = stu.getPaperId().getBytes().length;//   sheet.setColumnWidth((short)2,(short)(length*2*256));sheet.autoSizeColumn((short) 2); //調整第三列寬度sheet.autoSizeColumn((short) 3); //調整第四列寬度sheet.autoSizeColumn((short) 4); //調整第五列寬度sheet.autoSizeColumn((short) 5); //調整第六列寬度/*Font font = workbook.createFont();font.setFontHeightInPoints((short)18); //字體大小sheet.setDefaultRowHeightInPoints(21.75f);font.setFontName("楷體");font.setBoldweight(Font.BOLDWEIGHT_BOLD); //粗體font.setColor(HSSFColor.GREEN.index);    //綠字- 字體顏色*/}// 新建一輸出文件流FileOutputStream fOut = new FileOutputStream(path);// 把相應的Excel 工作簿存盤
          workbook.write(fOut);//清空緩沖區數據
          fOut.flush();// 操作結束,關閉文件
          fOut.close();System.out.println("文件生成...");} catch (Exception e) {System.out.println("已運行 xlCreate() : " + e);}}

代碼引自https://www.cnblogs.com/zhxn/p/7016380.html

轉載于:https://www.cnblogs.com/minxiaofei/p/10081073.html

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

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

相關文章

【vue-router①】router-link跳轉頁面傳遞參數 - 進擊的前端之路(偶爾爬坑java小路) - SegmentFault 思否

在vue項目中&#xff0c;往往會遇到這樣的情況&#xff0c;就是要實現在一個循環列表中&#xff0c;點擊其中一條跳轉到下個頁面&#xff0c;然后將這一條的相關數據帶到下個頁面中顯示&#xff0c;這是個循環列表&#xff0c;無論點哪一條都是跳到相同的頁面&#xff0c;只是填…

RHEL7 USB installation problem and solving

版權聲明&#xff1a;本文為博主原創文章。未經博主同意不得轉載。 https://blog.csdn.net/scruffybear/article/details/37063701 Encountered quite a few problems while install the RHEL7, with the Windows system already installed. Problem 1:/dev/root does not exis…

Vue表單類的父子組件數據傳遞示例_vue.js_腳本之家

使用Vue.js進行項目開發&#xff0c;那必然會使用基于組件的開發方式&#xff0c;這種方式的確給開發和維護帶來的一定的便利性&#xff0c;但如果涉及到組件之間的數據與狀態傳遞交互&#xff0c;就是一件麻煩事了&#xff0c;特別是面對有一大堆表單的頁面。 在這里記錄一下…

Jmeter-【JSON Extractor】-響應結果中三級key取值

一、請求返回樣式 二、取第三個option 三、查看結果 轉載于:https://www.cnblogs.com/Nancy-Lee/p/10938758.html

Day5:python之函數(3)

一、函數默認值參數 內置函數&#xff1a; input&#xff08;&#xff09;、print&#xff08;&#xff09;、int&#xff08;&#xff09; 常用模塊&#xff1a; 1、列表生成式 s [1,2,3,4,5,6,7,8] for i in s:print(i1) res [ i1 for i in s] res [str(i) for i in s]prin…

vue路由傳參的三種基本方式 - 流年的櫻花逝 - SegmentFault 思否

現有如下場景&#xff0c;點擊父組件的li元素跳轉到子組件中&#xff0c;并攜帶參數&#xff0c;便于子組件獲取數據。 父組件中&#xff1a; <li v-for"article in articles" click"getDescribe(article.id)"> methods&#xff1a; 方案一&#…

Rust從入門到放棄(1)—— hello,world

安裝及環境配置 特點&#xff1a;安全&#xff0c;性能&#xff0c;并發rust源配置RLS安裝cargo rust管理工具&#xff0c;該工具可以愉快方便的管理rust工程 #!/bin/bash mkdir learn cd learn cargo init ## 該命令會在當前目錄下初始化一個## 目錄下會出現一個Cargo.toml文…

牛客33-tokitsukaze and Number Game(數論)

題目描述 tokitsukaze又在玩3ds上的小游戲了&#xff0c;現在她遇到了難關。 tokitsukaze得到了一個整數x&#xff0c;并被要求使用x的每一位上的數字重新排列&#xff0c;組成一個能被8整除的數&#xff0c;并且這個數盡可能大。 聰明的你們請幫幫可愛的tokitsukaze&#xff0…

手摸手,帶你用vue擼后臺 系列一(基礎篇) - 掘金

完整項目地址&#xff1a;vue-element-admin 系列文章&#xff1a; 手摸手&#xff0c;帶你用 vue 擼后臺 系列一&#xff08;基礎篇&#xff09;手摸手&#xff0c;帶你用 vue 擼后臺 系列二(登錄權限篇)手摸手&#xff0c;帶你用 vue 擼后臺 系列三 (實戰篇)手摸手&#xf…

21、python基礎學習-new_three_menu

1 #!/usr/bin/env python2 #__author: hlc3 #date: 2019/5/294 5 menu {6 北京: {7 海淀: {8 五道口: {9 soho: {}, 10 網易: {}, 11 google: {} 12 }, 13 中關村: { 14 …

文獻筆記(十六)

一、基本信息 標題&#xff1a;一種基于 C 語言訪問 MySQL 數據庫的研究 時間&#xff1a;2016 出版源&#xff1a;貴州輕工職業技術學院 領域分類&#xff1a;數據庫與信息管理 作者&#xff1a;唐林 副教授&#xff0c; 研究方向&#xff1a; 計算機應用 二、研究背景 相關工…

webpack+vue+mui學習心得

引入mui 1.不需要npm安裝; 直接從官方下載丟進來 2.那就是全局引用了; 沒錯,就是index.html里直接引入,當然也可以main.js引入,隨意啦! so easy 3.找到webpack.base.conf.js,在module與plugins之間插入以下代碼: 4.這樣就可以在項目里面直接用了.然就是mui與vue-router及點…

[java設計模式簡記] 觀察者模式(Observer-Pattern)

觀察者模式(Observer-Pattern) 數據主體擁有需要數據的對象的數據&#xff0c;并且數據改變時需要數據的對象要及時知道 意圖&#xff1a; 定義對象間的一種一對多的依賴關系&#xff0c;當一個對象的狀態發生改變時&#xff0c;所有依賴于它的對象都得到通知并被自動更新。主要…

【ARTS】01_04_左耳聽風-20181203~1209

ARTS&#xff1a; Algrothm: leetcode算法題目Review: 閱讀并且點評一篇英文技術文章Tip/Techni: 學習一個技術技巧Share: 分享一篇有觀點和思考的技術文章Algorithm Single Number https://leetcode.com/problems/single-number/ 1&#xff09;problem Given a non-empty arra…

vue項目(webpack+mintui),使用hbuilder打包app - 小小人兒大大夢想 - 博客園

一、配置config/index.js 本人沒有配置index.js文件&#xff0c;就開始進行了打包&#xff0c;結果最終效果是頁面空白&#xff0c;解決了空白&#xff0c;接著底部圖標&#xff08;我是用的阿里巴巴圖片&#xff09;資源找不到。所以配置這步比較重要。 &#xff08;1&#…

caffe介紹

轉載于:https://www.cnblogs.com/Artimis-fightting/p/10945099.html

python-mysql 基礎知識記錄

cursor.fetchone() 與 cursor.fetchall() 如果查詢結果為空&#xff0c;前者返回 None&#xff0c;后者返回[] 此時如用 len() 函數計算長度&#xff0c;前者報錯&#xff0c;后者返回0 轉載于:https://www.cnblogs.com/ZuoAn-xieyang/p/10097230.html

微服務之consul(一) - 詩碼者 - 博客園

一、概述 consul是google開源的一個使用go語言開發的服務發現、配置管理中心服務。內置了服務注冊與發現框 架、分布一致性協議實現、健康檢查、Key/Value存儲、多數據中心方案&#xff0c;不再需要依賴其他工具&#xff08;比如ZooKeeper等&#xff09;。服務部署簡單&#x…

C#動態加載dll,dll目錄指定

<?xml version"1.0"?><configuration><startup> <supportedRuntime version"v4.0" sku".NETFramework,Versionv4.0"/></startup> <runtime> <assemblyBinding xmlns"urn:schemas-microsoft-com:a…

RestFramework之認證組件

一、認證組件的介紹 對于認證&#xff0c;我們一般有三種方式&#xff0c;即cookie, session,token, cookie,是將信息存放在客戶端(瀏覽器上)&#xff0c;信息不安全&#xff1b;session,把信息放在服務器數據庫中&#xff0c;但是要是信息量較大&#xff0c;對服務器的壓力就會…