"Web development" ☆★ Using POI Operations Excel Table Series tutorial "10" Cell fill color and color operations
Package Csg.xiaoye.poidemo;import Java.io.fileoutputstream;import Org.apache.poi.hssf.usermodel.HSSFWorkbook; Import Org.apache.poi.ss.usermodel.cell;import Org.apache.poi.ss.usermodel.cellstyle;import Org.apache.poi.ss.usermodel.indexedcolors;import Org.apache.poi.ss.usermodel.row;import Org.apache.poi.ss.usermodel.sheet;import org.apache.poi.ss.usermodel.workbook;/** * Cell fill color and color operation * @author Administrator * */public class Poispacecolor {public static void main (string[] args) throws exception{Workbook Wb=new Hssfworkbook (); Define a new workbook Sheet sheet=wb.createsheet ("First Sheet page"); Create the first sheet page of Row row=sheet.createrow (1); Create a row of Cell Cell=row.createcell (1); Cell.setcellvalue ("XX"); CellStyle Cellstyle=wb.createcellstyle (); Cellstyle.setfillbackgroundcolor (IndexedColors.AQUA.getIndex ()); Background color cellstyle.setfillpattern (cellstyle.big_spots); Cell.setcellstyle (CellStyle); Cell Cell2=row.createcell (2); Cell2.setcellvalue ("YYY"); CellStyle Cellstyle2=wb.createcellstyle (); Cellstyle2.setfillforegroundcolor (IndexedColors.RED.getIndex ()); Foreground Cellstyle2.setfillpattern (Cellstyle.solid_foreground); Cell2.setcellstyle (CellStyle2); FileOutputStream fileout=new fileoutputstream ("d:\\ saya. xls"); Wb.write (fileout); Fileout.close (); }}
The effect is as follows:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/26/90/wKiom1Nrgn3yf9bYAABJsLYfM04375.jpg "title=" 1.png " alt= "Wkiom1nrgn3yf9byaabjslyfm04375.jpg"/>
This article from "Promise always attached to the small wood 、、、" blog, please be sure to keep this source http://1936625305.blog.51cto.com/6410597/1408595