Set Row Height and Column Width in Excel using a free Java API

In most cases, we need to adjust the row height and column width to better display the contents of certain Excel cells. This article will introduce how to set the row height and column width programmatically by using a free Java API (Free Spire.XLS for Java).

Installation (2 Method)
1# Download the free API and unzip it, then add the Spire.Xls.jar file to your project as dependency.
2# You can also add the jar dependency to maven project by adding the following configurations to the pom.xml.

<repositories>
        <repository>
            <id>com.e-iceblue</id>
            <name>e-iceblue</name>
            <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
        </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.xls.free</artifactId>
        <version>3.9.1</version>
    </dependency>
</dependencies>

Enter fullscreen mode Exit fullscreen mode

Relevant code snippet

import com.spire.xls.*;

public class SetWidthAndHeight {
    public static void main(String[] args) {

        //Load the sample document
        Workbook workbook = new Workbook();
        workbook.loadFromFile("sample.xlsx");

        //Get the first worksheet.
        Worksheet worksheet = workbook.getWorksheets().get(0);

        //Set the height of the third row to 25
        worksheet.setRowHeight(3,25);

        //Set the width of the second column to 20
        worksheet.setColumnWidth(2, 20);

        //Save to file
        workbook.saveToFile("output/SetWidthAndHeight.xlsx", ExcelVersion.Version2016);
    }
}

Enter fullscreen mode Exit fullscreen mode

原文链接:Set Row Height and Column Width in Excel using a free Java API

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容