What is the code to change background color of Excel cell in Java?
Please see the following sample code that uses Aspose.Cells API to change the background color of the cell in Java.
The code creates an empty workbook, accesses the first worksheet, accesses the cell C4 and its style and using the style object, it then changes the background color of the cell to yellow.
Here is the sample code for your reference. Please read the comments inside the code for more understanding.
Java
- // Create empty workbook.
- com.aspose.cells.Workbook wb = new Workbook();
- // Access first worksheet
- Worksheet ws = wb.getWorksheets().get(0);
- // Access cell C4
- Cell c4 = ws.getCells().get("C4");
- // Get the style of the cell
- Style st = c4.getStyle();
- st.setPattern(BackgroundType.SOLID);
- st.setForegroundColor(Color.getYellow());
- c4.setStyle(st);
- // Save the workbook in XLSX format
- wb.save("D:/Download/Output.xlsx", SaveFormat.XLSX);
The following screenshot shows the output Excel file (as you see cell C4 is filled with Yellow color) generated by the code.
Thanks for reading. Hopefully, it will be helpful for you.
Articoli simili
- Se Android 16 fosse davvero in grado di far saltare in aria Cell, tornerebbe comunque come SP Cell e combatterebbe ancora contro Gohan?
- Can you forward a cell phone to another cell phone?
- Why does Android button shape changes but not color after applying background drawable (Android, button, Android drawable, development)?
- Che cos'è "abilitare l'aggiornamento in background" in Excel?