账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    Apache poi 怎么加粗显示?
    69
    0

    想对Excel中某些cell值加粗显示,使用的是最新的Apache poi jar包

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.17</version>
        </dependency>

    使用了下面的方法不起作用

        XSSFCellStyle cellStyle = wb.createCellStyle();
        XSSFFont font = wb.createFont();
        font.setBold(true);
        cellStyle.setFont(font);
        cell.setCellStyle(cellStyle);
    

    并且bold默认就为true

    set a boolean value for the boldness to use. If omitted, the default value is true.
    

    所以怎么才能加粗显示呢?

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 雷袭月启 普通会员 1楼

      Apache POI是一个用于在Microsoft Office应用程序中操作和处理Microsoft Office文件的Java库。在Apache POI中,你可以使用<b>标签来设置文本的粗体样式。

      以下是一个简单的示例:

      ```java import org.apache.poi.xwpf.usermodel.*;

      public class Main { public static void main(String[] args) { XWPFDocument document = new XWPFDocument(new XWPFDocumentFactory()); XWPFParagraph paragraph = document.createParagraph(); paragraph.setText("Hello, World!"); paragraph.setBstyle("bold"); document.writeParagraph(paragraph); } } ```

      在这个示例中,我们首先创建了一个XWPFDocument对象,然后在XWPFParagraph中添加了一个文本字符串。我们还使用了setBstyle方法来设置文本的粗体样式,其中"bold"表示粗体。

      注意,你需要在你的项目中添加Apache POI的依赖,可以通过Maven或Gradle来实现。在Maven中,你可以在pom.xml文件中添加以下依赖:

      xml <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>5.5.0</version> </dependency>

      在Gradle中,你可以在build.gradle文件中添加以下依赖:

      groovy dependencies { implementation 'org.apache.poi:poi:5.5.0' }

      这样,你就可以在Apache POI中使用<b>标签来设置文本的粗体样式了。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部