Generate EXCEL in Java

Source: Internet
Author: User

Public class simpleexcelwrite {
Public void createexcel (outputstream OS) throws writeexception, ioexception {
// Create a workbook
Writableworkbook workbook = Workbook. createworkbook (OS );
// Create a new page
Writablesheet sheet = Workbook. createsheet ("first sheet", 0 );
// Create the specific content to be displayed
Label xuexiao = new label (0, 0, "school ");
Sheet. addcell (xuexiao );
Label zhuanye = new label (1, 0, "professional ");
Sheet. addcell (zhuanye );
Label jingzhengli = new label (2, 0, "competitive ");
Sheet. addcell (jingzhengli );

Label Qinghua = new label (0, 1, "Tsinghua University ");
Sheet. addcell (QingHua );
Label jisuanji = new label (1, 1, "Computer Major ");
Sheet. addcell (jisuanji );
Label Gao = new label (2, 1, "high ");
Sheet. addcell (GAO );

Label Beida = new label (, "Peking University ");
Sheet. addcell (Beida );
Label falv = new label (1, 2, "Legal Major ");
Sheet. addcell (falv );
Label Zhong = new label (2, 2, "medium ");
Sheet. addcell (Zhong );

Label ligong = new label (, "Beijing Institute of Technology ");
Sheet. addcell (ligong );
Label hangkong = new label (1, 3, "Aviation Major ");
Sheet. addcell (hangkong );
Label di = new label (2, 3, "low ");
Sheet. addcell (DI );

// Write the created content to the output stream and close the output stream
Workbook. Write ();
Workbook. Close ();
OS. Close ();

}
}

<%
String fname = "professional competitiveness of Schools ";
Outputstream OS = response. getoutputstream ();
Response. Reset ();
 
// Process the Chinese file name
Response. setcharacterencoding ("UTF-8"); // sets the encoding format for the corresponding content
Fname = java.net. urlencoder. encode (fname, "UTF-8 ");
Response. setheader ("content-disposition", "attachment; filename =" + new string (fname. getbytes ("UTF-8"), "GBK") + ". xls ");
Response. setcontenttype ("application/msexel"); // defines the output type.
Simpleexcelwrite Sw = new simpleexcelwrite ();
Sw. createexcel (OS );
%>

Related Article

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.