1. http://poi.apache.org/download required jar get Poi-bin-3.9-20121203.zip decompression
2. Import the required Jar:poi-ooxml-3.9-20121203.jar,poi-scratchpad-3.9-20121203.jar, Xmlbeans-2.3.0.jar,
Dom4j-1.6.1.jar,poi-3.9-20121203.jar,poi-ooxml-schemas-3.9-20121203.jar
3.http://wenku.baidu.com/view/b357ccac6bec0975f46
POI Set Excel StyleSome summary of operations that need to format Excel cells may be used in POI:Get the Workbook object first:Hssfworkbook wb = new Hssfworkbook ();Hssfsheet sheet = Wb.createsheet ();Hssfcellstyle SetBorder = Wb.createcellstyle ();First, set the background color:Setborder.setfillforegroundcolor ((short) 13);//
Recently done in the project with the POI export Excel file template, some of the columns need to be set to text format, check the data found are to set the style of the cell, because it is not the content of the template cell, so can not set the format of the cell style operation, the Internet has the argument is not
I wrote a strange question about exporting Excel using poi a few days ago. Today I used poi, but this time it is not suitable for using templates.Program. So I encountered some unexpected problems. In fact, there are two problems: Setting the Row Height and setting the column width.First, I checked the poi3.0 API and found that the hssfrow object has the setheight (Short height) method. Then I wrote a verte
Reference: http://apps.hi.baidu.com/share/detail/17249059
Poi may use some Operation Summaries for setting the Excel cell format:
Obtain the thin objects first:
Hssfworkbook WB = new hssfworkbook ();
Hssfsheet sheet = WB. createsheet ();
Hssfcellstyle setborder = WB. createcellstyle ();
1. Set the background color:
Setborder. setfillforegroundcolor (short) 13); // you can specify the background color.Setbor
Pick up a POI to export word http://www.cnblogs.com/xiufengd/p/4708680.html. Public Static voidSetauto (xwpfdocument Doc)throwsSecurityException, Nosuchfieldexception, IllegalArgumentException, illegalaccessexception{Listdoc.getrelations (); //set compatibility properties for some Word documents for(Poixmldocumentpart p:list) {if(pinstanceofxwpfsettings) {xwpfsettings Settings=(xwpfsettings) p;
Set the foreground color background color in POI Excel
Set the background color in POI as follows:
HSSFCellStyle cellStyle = wb. createCellStyle (); cellStyle. setFillBackgroundColor (HSSFColor. TEAL. index); // set the background color cellStyle. setFillForegroundColor (HSS
Ask questions
Poi How to customize cell background color ... solve the problem
Example one: A concrete look at the note
Import org.apache.poi.hssf.usermodel.*;
Import Org.apache.poi.hssf.util.HSSFColor;
Import Java.io.FileOutputStream;
/** * Created by Ay on 2016/4/29. */public class Poibackgroundcolortest {public static void main (string[] args) throws exception{//Create a copy of Hssfwork
Book Excel = new Hssfworkbook ();
Create the firs
.setfontheightinpoints ((short) 12);Setborder.setfont (font);//Select the font format you want to useFive, set the column width:Sheet.setcolumnwidth (0, 3766); The first parameter represents the column ID (starting at 0), and the 2nd parameter represents the Width valueSix, set the automatic line wrapping:Setborder.setwraptext (TRUE);//Set line wrappingSeven, mer
Before reading this article, please read my previous article, the previous article has focused on POI set Excel cell format as text format, the rest of the set decimal, percent, currency, date, scientific notation and Chinese capitalization these will be written in one by one belowEach of the following will be used in these three rows of variablesHssfworkbook Dem
"Web development" ☆★ using POI to manipulate Excel Table series tutorial "8" to set how cells are to be usedPackage Csg.xiaoye.poidemo;import Java.io.fileoutputstream;import Org.apache.poi.hssf.usermodel.HSSFCellStyle; Import Org.apache.poi.hssf.usermodel.hssfrichtextstring;import Org.apache.poi.hssf.usermodel.hssfworkbook;import Org.apache.poi.ss.usermodel.cell;import Org.apache.poi.ss.usermodel.cellstyle;
This example shows you Excel cell fills and colors using Apache POI.
In our example I has used all the possible colors and set it as Fills background colors of cells.
Below is the example code.
Package com.java.connect.poi;
Import Java.io.FileOutputStream;
Import java.io.IOException;
Import Org.apache.poi.ss.usermodel.Cell;
Import Org.apache.poi.ss.usermodel.CellStyle;
Import org.apache.poi.ss.usermodel.In
if the cell assignment is not assigned a value, but it must be createcell,
Row. createcell (2 );Row. createcell (3 );Row. createcell (4 );Row. createcell (5); this is not meaningless, if removed
The error result is as follows:
The correct result after createcell 2-5 is added:
In addition, I found an interesting place. When operating to merge cells in Excel, if other cells except the first cell to be merged also have values, a prompt will be displayed.
.
After the cells are merged, remove th
@ Author YHC
Convenience functions:
These convenience functions provide practical program functions, such as setting the area for table border merging, and changing style attributes, rather than re-creating a new style:
[Java]// Create an Excel fileWorkbook wb = new HSSFWorkbook (); // or create a new XSSFWorkbook ()// Create a workbookSheet sheet1 = wb. createSheet ("new sheet ");// Create a merged Region// Create a rowRow row = sheet1.createRow (1 );// Create a rowRow row2 = sheet1.createRow (
@ 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 fileWorkbook wb = new HSSFWorkbook ();// Create a workbookSheet sheet1 = wb. createSheet ("new sheet ");// Set the workbook to zoom inSheet1.setZoom (3,
In my last article, (4) How to operate an Excel file with Apache POI-----found POI-3.12 a regression, by testing the version of POI-3.12, I found a bug, then what to do when the bug was found. We have 2 kinds of processing, first we go to the Apache POI Bug Library to search, to see if others have created a similar bug
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.