Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to merge or unmerge Excel cells with Java

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to merge or cancel merging Excel cells with Java". In daily operation, I believe many people have doubts about how to merge or cancel merging Excel cells with Java. The editor consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to merge or cancel merging Excel cells with Java". Next, please follow the editor to study!

Merging cells is the operation of merging two or more cells in the same row or column in a table into one cell.

Basic steps:

1. Download the Free Spire.XLS for Java package and extract it, then import the Spire.Xls.jar package under the lib folder into the Java application as a dependency. (you can also install the JAR package directly through the Maven repository (see below for the code to configure the pom.xml file))

two。 Create a new Java Class in the Java application (here I name it MergeCells and UnmergeCells), then enter the appropriate Java code and run it.

Configure the pom.xml file:

Com.e-iceblue http://repo.e-iceblue.cn/repository/maven-public/ e-iceblue spire.xls.free 2.2.0

Merge cells:

Import com.spire.xls.FileFormat;import com.spire.xls.Workbook;import com.spire.xls.Worksheet;//java project: www.1b23.compublic class MergeCells {public static void main (String [] args) {/ / create Workbook instance Workbook workbook = new Workbook (); / / load Excel document workbook.loadFromFile ("test1.xlsx"); / / get the first worksheet Worksheet sheet = workbook.getWorksheets () .get (0) / / merge the cell range A1 to C1sheet.getRange () .get ("A1:C1") .merge (); / / Save the resulting document workbook.saveToFile ("MergeCells.xlsx", FileFormat.Version2013);}}

Unmerge cells:

Import com.spire.xls.FileFormat;import com.spire.xls.Workbook;import com.spire.xls.Worksheet;//java project: www.1b23.compublic class UnmergeCells {public static void main (String [] args) {/ / create Workbook instance Workbook workbook = new Workbook (); / / load Excel document workbook.loadFromFile ("MergeCells.xlsx"); / / get the first worksheet Worksheet sheet = workbook.getWorksheets () .get (0) / / cancel merging the cell range A1 to C1sheet.getRange (). Get ("A1:C1"). UnMerge (); / / Save the result document workbook.saveToFile ("UnMergeCells.xlsx", FileFormat.Version2013);}} at this point, the study on "how to merge or cancel merging Excel cells with Java" is over. I hope you can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report