濮阳杆衣贸易有限公司

主頁 > 知識庫 > 將Oracle數(shù)據(jù)庫中的數(shù)據(jù)寫入Excel

將Oracle數(shù)據(jù)庫中的數(shù)據(jù)寫入Excel

熱門標簽:區(qū)域地圖標注怎么設置 地圖標注的坐標點 百度地圖標注注解 電話機器人那種好 南通電銷外呼系統(tǒng)哪家強 百度地圖標注飯店位置怎么 理財產(chǎn)品電銷機器人 上海網(wǎng)絡外呼系統(tǒng) 外呼系統(tǒng)好點子

1.準備工作

Oracle數(shù)據(jù)庫“TBYZB_FIELD_PRESSURE”表中數(shù)據(jù)如圖:

Excel模板(201512.xls):

2.任務說明

我們要完成的任務就是將表“TBYZB_FIELD_PRESSURE”中的數(shù)據(jù),按照Excel模板(201512.xls)的樣式導入到一個新的Excel中。即:Excel模板(201512.xls)不改變,生成一個和它一樣的Excel并且導入數(shù)據(jù)。

3.關鍵代碼

// 使用FieldPressEntity中的每一個entity,一個entity包含了所有屬性
 public void insertintoExcel(String yyyy, String mm) throws Exception {
  ListFieldPressEntity> result = tyFieldPressDao.search(yyyy, mm);
  // 讀取Excel的模板
  HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(new File(
    "D:/201512.xls")));
  HSSFSheet sheet = null;
  // 讀取sheet的模板
  sheet = workbook.getSheetAt(0);
  // 定義行
  HSSFRow row;
  // 定義單元格
  HSSFCell cell;
  // for循環(huán),循環(huán)目標為行循環(huán)
  for (int i = 0; i  result.size(); i++) {
   System.out.println(result.size());
   // 給e循環(huán)賦值
   FieldPressEntity e = result.get(i);
   // 循環(huán)行
   row = sheet.getRow(3 + i);
   // 給行內(nèi)的單元格賦值
   cell = row.getCell(1);
   cell.setCellValue(e.getH17());
   System.out.println(i + "i內(nèi)+" + e.getH17());
   cell = row.getCell(2);
   cell.setCellValue(e.getH18());
   System.out.println(i + "i內(nèi)+" + e.getH18());
   cell = row.getCell(3);
   cell.setCellValue(e.getH19());
   System.out.println(i + "i內(nèi)+" + e.getH19());
   cell = row.getCell(4);
   cell.setCellValue(e.getH20());
   System.out.println(i + "i內(nèi)+" + e.getH20());
   cell = row.getCell(5);
   cell.setCellValue(e.getH21());
   System.out.println(i + "i內(nèi)+" + e.getH21());
   cell = row.getCell(6);
   cell.setCellValue(e.getH22());
   System.out.println(i + "i內(nèi)+" + e.getH22());
   cell = row.getCell(7);
   cell.setCellValue(e.getH23());
   System.out.println(i + "i內(nèi)+" + e.getH23());
   cell = row.getCell(8);
   cell.setCellValue(e.getH00());
   System.out.println(i + "i內(nèi)+" + e.getH00());
   cell = row.getCell(9);
   cell.setCellValue(e.getH01());
   System.out.println(i + "i內(nèi)+" + e.getH01());
   cell = row.getCell(10);
   cell.setCellValue(e.getH02());
   System.out.println(i + "i內(nèi)+" + e.getH02());
   cell = row.getCell(11);
   cell.setCellValue(e.getH03());
   System.out.println(i + "i內(nèi)+" + e.getH03());
   cell = row.getCell(12);
   cell.setCellValue(e.getH04());
   System.out.println(i + "i內(nèi)+" + e.getH04());
   cell = row.getCell(13);
   cell.setCellValue(e.getH05());
   System.out.println(i + "i內(nèi)+" + e.getH05());
   cell = row.getCell(14);
   cell.setCellValue(e.getH06());
   System.out.println(i + "i內(nèi)+" + e.getH06());
   cell = row.getCell(15);
   cell.setCellValue(e.getH07());
   System.out.println(i + "i內(nèi)+" + e.getH07());
   cell = row.getCell(16);
   cell.setCellValue(e.getH08());
   System.out.println(i + "i內(nèi)+" + e.getH08());
   cell = row.getCell(17);
   cell.setCellValue(e.getH09());
   System.out.println(i + "i內(nèi)+" + e.getH09());
   cell = row.getCell(18);
   cell.setCellValue(e.getH10());
   System.out.println(i + "i內(nèi)+" + e.getH10());
   cell = row.getCell(19);
   cell.setCellValue(e.getH11());
   System.out.println(i + "i內(nèi)+" + e.getH11());
   cell = row.getCell(20);
   cell.setCellValue(e.getH12());
   System.out.println(i + "i內(nèi)+" + e.getH12());
   cell = row.getCell(21);
   cell.setCellValue(e.getH13());
   System.out.println(i + "i內(nèi)+" + e.getH13());
   cell = row.getCell(22);
   cell.setCellValue(e.getH14());
   System.out.println(i + "i內(nèi)+" + e.getH14());
   cell = row.getCell(23);
   cell.setCellValue(e.getH15());
   System.out.println(i + "i內(nèi)+" + e.getH15());
   cell = row.getCell(24);
   cell.setCellValue(e.getH16());
   System.out.println(i + "i內(nèi)+" + e.getH16());
   cell = row.getCell(25);
   cell.setCellValue(e.getDaily_sum());
   System.out.println(i + "i內(nèi)+" + e.getDaily_sum());
   cell = row.getCell(26);
   cell.setCellValue(e.getDaily_avg());
   System.out.println(i + "i內(nèi)+" + e.getDaily_avg());
   cell = row.getCell(27);
   cell.setCellValue(e.getDaily_max());
   System.out.println(i + "i內(nèi)+" + e.getDaily_max());
   cell = row.getCell(28);
   cell.setCellValue(e.getDaily_min());
   System.out.println(i + "i內(nèi)+" + e.getDaily_min());
  }
  // 寫入一個新的Excel表內(nèi)
  FileOutputStream out = new FileOutputStream(new File("E:/"+yyyy+mm+".xls"));
  // Excel表寫入完成
  workbook.write(out);
  // Excel表退出
  out.close();
 }

總結(jié):我們這個項目用的是ssh架構,如果想使用以上代碼,需要按照ssh的規(guī)范,定義dao action service entity四個包,如果需要頁面操作還需要js做頁面。

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!

您可能感興趣的文章:
  • Oracle 使用TOAD實現(xiàn)導入導出Excel數(shù)據(jù)
  • Oracle讀取excel數(shù)據(jù)
  • Oracle導出excel數(shù)據(jù)
  • 如何解決Oracle EBS R12 - 以Excel查看輸出格式為“文本”的請求時亂碼
  • 使用工具 plsqldev將Excel導入Oracle數(shù)據(jù)庫
  • Excel導入oracle的幾種方法
  • Excel VBA連接并操作Oracle

標簽:自貢 海東 寧波 昭通 百色 紹興 中衛(wèi) 遼源

巨人網(wǎng)絡通訊聲明:本文標題《將Oracle數(shù)據(jù)庫中的數(shù)據(jù)寫入Excel》,本文關鍵詞  將,Oracle,數(shù)據(jù)庫,中的,數(shù)據(jù),;如發(fā)現(xiàn)本文內(nèi)容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《將Oracle數(shù)據(jù)庫中的數(shù)據(jù)寫入Excel》相關的同類信息!
  • 本頁收集關于將Oracle數(shù)據(jù)庫中的數(shù)據(jù)寫入Excel的相關信息資訊供網(wǎng)民參考!
  • 推薦文章
    平潭县| 会同县| 郧西县| 汉阴县| 盐源县| 清远市| 鹤岗市| 海门市| 玛沁县| 理塘县| 教育| 万年县| 嘉峪关市| 长乐市| 瓮安县| 衢州市| 陆河县| 万载县| 永昌县| 多伦县| 兴宁市| 华阴市| 安塞县| 陈巴尔虎旗| 靖安县| 婺源县| 万州区| 武平县| 达拉特旗| 遵义市| 嵩明县| 紫金县| 淮南市| 锡林郭勒盟| 泽库县| 永春县| 清苑县| 汉阴县| 太保市| 九台市| 平乐县|