始终无法使用默认的实际值设置渐变单元填充
apache poi
版本。
XSSF
(
*.xlsx
ooxml-schemas-*.jar
poi-ooxml-full-*.jar
faq-N10025
.
.
CellStyle
只有一些填充才能从中获得填充索引。然后是低电平
CTFill
用于此
蜂窝式
. 然后它取消模式填充,然后设置渐变填充。
获取有关如何使用的信息
CT填充
ooxml-schemas
然后做
javadoc
. 没有API文档
ooxml模式
import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTGradientFill;
public class CreateExcelCellGradientFillColor {
public static void main(String[] args) throws Exception {
XSSFWorkbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet();
Row row = sheet.createRow(0);
XSSFCellStyle cellstyle = workbook.createCellStyle();
cellstyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
int fillidx = (int)cellstyle.getCoreXf().getFillId();
CTFill ctfill = workbook.getStylesSource().getFillAt(fillidx).getCTFill();
System.out.println(ctfill);
ctfill.unsetPatternFill();
byte[] rgb1 = new byte[3];
rgb1[0] = (byte) 0;
rgb1[1] = (byte) 0;
rgb1[2] = (byte) 255;
byte[] rgb2 = new byte[3];
rgb2[0] = (byte) 255;
rgb2[1] = (byte) 255;
rgb2[2] = (byte) 255;
CTGradientFill ctgradientfill = ctfill.addNewGradientFill();
ctgradientfill.setDegree(90.0);
ctgradientfill.addNewStop().setPosition(0.0);
ctgradientfill.getStopArray(0).addNewColor().setRgb(rgb1);
ctgradientfill.addNewStop().setPosition(0.5);
ctgradientfill.getStopArray(1).addNewColor().setRgb(rgb2);
ctgradientfill.addNewStop().setPosition(1.0);
ctgradientfill.getStopArray(2).addNewColor().setRgb(rgb1);
System.out.println(ctfill);
Cell cell = row.createCell(0);
cell.setCellValue("");
cell.setCellStyle(cellstyle);
FileOutputStream out = new FileOutputStream("CreateExcelCellGradientFillColor.xlsx");
workbook.write(out);
out.close();
workbook.close();
}
}