Write Data from Oracle database to Excel and oracleexcel

Source: Internet
Author: User

Write Data from Oracle database to Excel and oracleexcel

Write Data from Oracle database to Excel

1. Preparations

Data in the "TBYZB_FIELD_PRESSURE" table of the Oracle database

 

Exceltemplate (201512.xls ):

 

2. Task Description

The task we want to complete is to import the data in the table named tbyzb_field_pressure.pdf to a new Excel file according to the Excel template (5512.xls. That is: The exceltemplate (201512.xls) is not changed, generate an Excel file and import data.

 

3. key code

// Use each entity in FieldPressEntity. One entity contains all attributes public void insertintoExcel (String yyyy, String mm) throws Exception {List <FieldPressEntity> result = tyFieldPressDao. search (yyyy, mm); // read the Excel template HSSFWorkbook workbook = new HSSFWorkbook (new FileInputStream (new File ("D:/201512.xls"); HSSFSheet sheet = null; // read the sheet template sheet = workbook. getSheetAt (0); // defines the row HSSFRow row; // defines the cell HSSFCell cell; // for loop, which is a row loop for (int I = 0; I <result. size (); I ++) {System. out. println (result. size (); // assign FieldPressEntity e = result to e loop. get (I); // loop row = sheet. getRow (3 + I); // assign cell = row to cells in the row. getCell (1); cell. setCellValue (e. getH17 (); System. out. println (I + "I +" + e. getH17 (); cell = row. getCell (2); cell. setCellValue (e. getH18 (); System. out. println (I + "I +" + e. getH18 (); cell = row. getCell (3); cell. setCellValue (e. getH19 (); System. out. println (I + "I +" + e. getH19 (); cell = row. getCell (4); cell. setCellValue (e. getH20 (); System. out. println (I + "I +" + e. getH20 (); cell = row. getCell (5); cell. setCellValue (e. getH21 (); System. out. println (I + "I +" + e. getH21 (); cell = row. getCell (6); cell. setCellValue (e. geth2 (); System. out. println (I + "I +" + e. geth2 (); cell = row. getCell (7); cell. setCellValue (e. getH23 (); System. out. println (I + "I +" + e. getH23 (); cell = row. getCell (8); cell. setCellValue (e. getH00 (); System. out. println (I + "I +" + e. getH00 (); cell = row. getCell (9); cell. setCellValue (e. getH01 (); System. out. println (I + "I +" + e. getH01 (); cell = row. getCell (10); cell. setCellValue (e. getH02 (); System. out. println (I + "I +" + e. getH02 (); cell = row. getCell (11); cell. setCellValue (e. getH03 (); System. out. println (I + "I +" + e. getH03 (); cell = row. getCell (12); cell. setCellValue (e. getH04 (); System. out. println (I + "I +" + e. getH04 (); cell = row. getCell (13); cell. setCellValue (e. getH05 (); System. out. println (I + "I +" + e. getH05 (); cell = row. getCell (14); cell. setCellValue (e. getH06 (); System. out. println (I + "I +" + e. getH06 (); cell = row. getCell (15); cell. setCellValue (e. getH07 (); System. out. println (I + "I +" + e. getH07 (); cell = row. getCell (16); cell. setCellValue (e. getH08 (); System. out. println (I + "I +" + e. getH08 (); cell = row. getCell (17); cell. setCellValue (e. getH09 (); System. out. println (I + "I +" + e. getH09 (); cell = row. getCell (18); cell. setCellValue (e. getH10 (); System. out. println (I + "I +" + e. getH10 (); cell = row. getCell (19); cell. setCellValue (e. getH11 (); System. out. println (I + "I +" + e. getH11 (); cell = row. getCell (20); cell. setCellValue (e. getH12 (); System. out. println (I + "I +" + e. getH12 (); cell = row. getCell (21); cell. setCellValue (e. getH13 (); System. out. println (I + "I +" + e. getH13 (); cell = row. getCell (22); cell. setCellValue (e. getH14 (); System. out. println (I + "I +" + e. getH14 (); cell = row. getCell (23); cell. setCellValue (e. getH15 (); System. out. println (I + "I +" + e. getH15 (); cell = row. getCell (24); cell. setCellValue (e. getH16 (); System. out. println (I + "I +" + e. getH16 (); cell = row. getCell (25); cell. setCellValue (e. getDaily_sum (); System. out. println (I + "I +" + e. getDaily_sum (); cell = row. getCell (26); cell. setCellValue (e. getDaily_avg (); System. out. println (I + "I +" + e. getDaily_avg (); cell = row. getCell (27); cell. setCellValue (e. getDaily_max (); System. out. println (I + "I +" + e. getDaily_max (); cell = row. getCell (28); cell. setCellValue (e. getDaily_min (); System. out. println (I + "I +" + e. getDaily_min ();} // write FileOutputStream out = new FileOutputStream (new File ("E:/" + yyyy + mm + ". (xls "); // write to the Excel table to complete the workbook. write (out); // exit from the Excel table. close ();}

 

Summary:1. our project uses the ssh architecture. To use the above Code, we need to define four packages of dao action service entity according to ssh specifications. js is also required for page operations.

2. For Excel operations, go to the http://www.yiibai.com/apache_poi/apache_poi_java_excel.html for details

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.