In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces Java in Excel cells how to apply one/more font styles, the text is very detailed, has a certain reference value, interested friends must read!
In Excel, when setting cell font style, you can apply the same style to all characters in the cell, that is, obtain the specified cell and apply the style; in addition, you can apply different font styles to different character contents in the cell, that is, obtain the character position in the cell and apply the style;
Tools: Free Spire.XLS for Java (Free Edition)
Note: You can download the package through the official website, extract it, and import the Spire.Xls.jar file in the lib folder into Java programs; or import it through the maven repository. The import effect is as follows:
Java code examples
import com.spire.xls.*; import java.awt.*; public class SetMultipleStylesInOneCell { public static void main(String[] args) { //load Excel document Workbook wb = new Workbook(); wb.loadFromFile("test.xlsx"); //Get the specified worksheet Worksheet sheet = wb.getWorksheets().get(0); //Get cell C3, apply style to all characters in cell CellRange cell1 = sheet.getCellRange("C3"); cell1.getCellStyle().getFont().setFontName("line script"); cell1.getCellStyle().getFont().setColor(new Color(0,128,0)); cell1.getCellStyle().getFont().setUnderline(FontUnderlineType.Double); cell1.getCellStyle().getFont().setSize(13); //Get cell C5 CellRange cell2 = sheet.getCellRange("C5"); //Create font styles font1 and font2 ExcelFont font1 = wb.createFont(); font1.setColor(new Color(30,144,255)); font1.setFontName("bold"); font1.setSize(14); font1.isItalic(true); ExcelFont font2 = wb.createFont(); font2.setColor(new Color(220,20,60)); font2.setFontName("italics"); font2.setSize(17); font2.isBold(true); //call the method to set font style to the specified character in the cell RichText richText = cell2.getRichText(); richText.setFont(0,7,font1); richText.setFont(9,17,font2); //Save document wb.saveToFile("Result.xlsx"); wb.dispose(); } }
Font style application results:
The above is "Java in Excel cells how to apply one/more font style" all the content of this article, thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.