我有一个整数值,我想在十六进制转换它.
我这样做:
private short getCouleur(Integer couleur, HSSFWorkbook classeur) {
if (null == couleur) {
return WHITE.index;
} else {
HSSFPalette palette = classeur.getCustomPalette();
String hexa = Integer.toHexString(couleur);
byte r = Integer.valueOf(hexa.substring(0, 2), 16).byteValue();
byte g = Integer.valueOf(hexa.substring(2, 4), 16).byteValue();
byte b = Integer.valueOf(hexa.substring(4, 6), 16).byteValue();
palette.setColorAtIndex((short) 65, r, g, b);
return (short) 65;
}
}
Run Code Online (Sandbox Code Playgroud)
在输出中我有这个:
couleur:65331
六:FF33
hexa.substring(0,2):FF
hexa.substring(2,4):33
hexa.substring(4,6):
r:-1
g:51
b:错误消息
错误消息:字符串索引超出范围:6
谢谢.