POI set Custom RGB background color

Source: Internet
Author: User
Tags mongodb postgresql redis firewall
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
    HSSFWorkbook excel = new HSSFWorkbook ();
    // Create the first sheet
    HSSFSheet sheet = excel.createSheet ("My POI Journey");
    // Create the first line
    HSSFRow row = sheet.createRow ((short) 0);
    // Create the first cell
    HSSFCell cell = row.createCell ((short) 0);
    // Set the value of the cell
    cell.setCellValue ("Ay");
    // Generate cell style
    HSSFCellStyle style = excel.createCellStyle ();
    // Set the background color
    style.setFillForegroundColor (HSSFColor.LIME.index);
    // solid fill foreground foreground color
    style.setFillPattern (HSSFCellStyle.SOLID_FOREGROUND);
    cell.setCellStyle (style);
    // Write to hard disk by streaming
    FileOutputStream out = new FileOutputStream ("D: /old_color.xls");
    excel.write (out);
    out.close ();

    // ====== Here is the point, you will customize the style of the cell soon =============
    cell.setCellValue ("Al");
    // Get the palette color board
    HSSFPalette palette = excel.getCustomPalette ();
    // This is the key point, the specific is to put the previous color HSSFColor.LIME.index
    // Replace with RGB (51,204,204) sapphire blue
    // You can change to RGB (0,255,127)
    palette.setColorAtIndex (HSSFColor.LIME.index, (byte) 0, (byte) 255, (byte) 127);
    // ====== Here is the point, you will customize the style of the cell soon =============
    out = new FileOutputStream ("D: /new_color.xls");
    excel.write (out);
    out.close ();
}




Alibaba Cloud Hot Products

Elastic Compute Service (ECS) Dedicated Host (DDH) ApsaraDB RDS for MySQL (RDS) ApsaraDB for PolarDB(PolarDB) AnalyticDB for PostgreSQL (ADB for PG)
AnalyticDB for MySQL(ADB for MySQL) Data Transmission Service (DTS) Server Load Balancer (SLB) Global Accelerator (GA) Cloud Enterprise Network (CEN)
Object Storage Service (OSS) Content Delivery Network (CDN) Short Message Service (SMS) Container Service for Kubernetes (ACK) Data Lake Analytics (DLA)

ApsaraDB for Redis (Redis)

ApsaraDB for MongoDB (MongoDB) NAT Gateway VPN Gateway Cloud Firewall
Anti-DDoS Web Application Firewall (WAF) Log Service DataWorks MaxCompute
Elastic MapReduce (EMR) Elasticsearch

Alibaba Cloud Free Trail

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.