1. Background of the problem
There is a student table that needs to be exported to Excel, with a number, name, gender, and age of four fields
2. Realize the source code
/** * * @Project: report * @Title: Excelexport.java * @Package: Com.you.excel * @Description: * @Author: Youhaidong * @Date: 2 015 November 4 pm 2:23:49 * @Version: */package com.you.excel;import Java.io.fileoutputstream;import Org.apache.poi.hssf.usermodel.hssfcell;import Org.apache.poi.hssf.usermodel.hssfrow;import Org.apache.poi.hssf.usermodel.hssfsheet;import org.apache.poi.hssf.usermodel.hssfworkbook;/** * <p> Please summarize the function in a sentence </p> * @ClassName: Excelexport * @Description: * @Author: Youhaidong * @Date: November 4, 2015 PM 2:23:49 * */public Class Excelexport {/** * * @Title: Excelexport * @Description: * @param args * @Date: November 4, 2015 PM 2:23:49 * @return: void * @throws Exception */@SuppressWarnings ("resource") public static void main (string[] args) throws Exception {//Create a WORKB Ookhssfworkbook workbook = new Hssfworkbook ();//Create a sheet page hssfsheet sheet = workbook.createsheet ("Student table");// Create the first row hssfrow row = sheet.createrow (0);//Create cell Hssfcell cell1 = Row.createcell (0); Hssfcell cell2 = Row.createcell (1); Hssfcell Cell3 = Row.createcell (2); Hssfcell CELL4 = Row.createcell (2);//Set Header Cell1.setcellvalue ("study number"); Cell2.setcellvalue ("name"); Cell3.setcellvalue ("Gender "); Cell4.setcellvalue (" Age "); FileOutputStream stream = new FileOutputStream ("D:/student.xls"); Workbook.write (stream); }}
3. Achieve Results
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Set Java Export Excel header