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.
Artigos semelhantes
- Why does Android button shape changes but not color after applying background drawable (Android, button, Android drawable, development)?
- Se o Android 16 fosse realmente capaz de explodir Cell, ele ainda voltaria como SP Cell e ainda lutaria contra Gohan?
- Can you forward a cell phone to another cell phone?
- How to make the background image of a button disappear when we click it, and make it appear on another button when we click it in Visual Studio