POI Excel 11 workbook enlargement, set the header and footer

Source: Internet
Author: User
Tags italic font blank page

@ Author YHC

Set the workbook zoom in ratio:

Set the workbook to zoom in with scores. In the following example, the ratio is adjusted to 75%, 3 is the numerator, and 4 is the denominator;


[Java]
// Create an Excel file
Workbook wb = new HSSFWorkbook ();
// Create a workbook
Sheet sheet1 = wb. createSheet ("new sheet ");
// Set the workbook to zoom in
Sheet1.setZoom (3, 4); // 75 percent magnification
//
// Write a file
FileOutputStream fileOut = new FileOutputStream ("workbook.xls ");
Wb. write (fileOut );
FileOut. close ();

// Create an Excel file
Workbook wb = new HSSFWorkbook ();
// Create a workbook
Sheet sheet1 = wb. createSheet ("new sheet ");
// Set the workbook to zoom in
Sheet1.setZoom (3, 4); // 75 percent magnification
//
// Write a file
FileOutputStream fileOut = new FileOutputStream ("workbook.xls ");
Wb. write (fileOut );
FileOut. close ();
:

 


Set the header and footer:

The following example sets the header, but can also be used to set the footer directly.


[Java]
// Create an Excel file
Workbook wb = new HSSFWorkbook ();
// Create a workbook
Sheet sheet = wb. createSheet ("new sheet ");
// Create a header
Header header = sheet. getHeader ();
// Customize the header and set the information displayed in the left-right corner of the header
Header. setCenter ("Center Header ");
Header. setLeft ("Left Header ");
Header. setRight (HSSFHeader. font ("stenpencil-Normal", "Italic") +
HSSFHeader. fontSize (short) 16) + "Right w/stencel-Normal Italic font and size 16 ");

// Write a file
FileOutputStream fileOut = new FileOutputStream ("workbook.xls ");
Wb. write (fileOut );
FileOut. close ();

// Create an Excel file
Workbook wb = new HSSFWorkbook ();
// Create a workbook
Sheet sheet = wb. createSheet ("new sheet ");
// Create a header
Header header = sheet. getHeader ();
// Customize the header and set the information displayed in the left-right corner of the header
Header. setCenter ("Center Header ");
Header. setLeft ("Left Header ");
Header. setRight (HSSFHeader. font ("stenpencil-Normal", "Italic") +
HSSFHeader. fontSize (short) 16) + "Right w/stencel-Normal Italic font and size 16 ");

// Write a file
FileOutputStream fileOut = new FileOutputStream ("workbook.xls ");
Wb. write (fileOut );
FileOut. close (); Note: After the code is run, it is a blank page. How can I check whether the setting is effective:

Open your Excel file-> page settings-> Tab to select the header and footer-> click custom header:

 

Author: yhc13429826359
 

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.