In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.