Reputation: 9447
Did style cell color && value right alignment like this:
XSSFColor color = new XSSFColor(new Color(43,150,150));
XSSFCellStyle cellStyle = myWorkBook.createCellStyle();
cellStyle.setFillForegroundColor(color);
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cellStyle.setAlignment(HorizontalAlignment.RIGHT);
//cellStyle.setAlignment(CellStyle.ALIGN_RIGHT);
Cell color working but cell value right alignment not working.
Upvotes: 0
Views: 12985
Reputation: 61915
Your issue is not reproducible. Exact your code snippet works as expected using the current apache poi 4.1.1
.
Let's have a Minimal, Reproducible Example to show that it really works.
Code:
import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.xssf.usermodel.*;
class CreateExcelCellStyleAlingmentAndColor {
public static void main(String[] args) throws Exception {
try (XSSFWorkbook workbook = new XSSFWorkbook();
FileOutputStream fileout = new FileOutputStream("./Excel.xlsx") ) {
XSSFColor color = new XSSFColor(new java.awt.Color(43,150,150), null);
XSSFCellStyle cellStyle = workbook.createCellStyle();
cellStyle.setFillForegroundColor(color);
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cellStyle.setAlignment(HorizontalAlignment.RIGHT);
XSSFSheet sheet = workbook.createSheet();
XSSFCell cell = sheet.createRow(0).createCell(0);
cell.setCellValue("A1");
cell.setCellStyle(cellStyle);
workbook.write(fileout);
}
}
}
Result:
You see, colored and right aligned.
Upvotes: 3