本文介绍了如何使用HSSFSheet Apache POI在excell中创建具有多种样式的单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为excel创建导出文档的脚本。
我发现一些困难,像:
我想要像名称:的单元格值标记 DOB: 11-11-2014通过合并几个细胞。
你能帮我解决一下吗?

I am creating a script for export document as excel.I have found some difficulties in that like:I want cell value like "Name: Mark DOB: 11-11-2014" by merging few cells.Can you please help me to get resolve this ?

提前感谢!

推荐答案

您需要做的是创建一个。这是将不同的格式/样式应用于在Excel中显示的同一单元格的不同部分

What you need to do is create a RichTextString for your cell. That's the way of applying different formatting / styles to different parts of the same cell for display in Excel

您将要查看了解更多关于如何使用它,但广泛地,它将像

You'll want to review the POI "Working With Rich Text" example for more on how to use it, but broadly it'll be something like

    Cell cell = row.createCell(1);
    RichTextString rt = new XSSFRichTextString("The quick brown fox");

    Font font1 = wb.createFont();
    font1.setBoldWeight(Font.BOLDWEIGHT_BOLD);
    rt.applyFont(0, 10, font1);

    Font font2 = wb.createFont();
    font2.setItalic(true);
    font2.setUnderline(XSSFFont.U_DOUBLE);
    rt.applyFont(10, 19, font2);

    Font font3 = wb.createFont();
    font3.setBoldWeight(Font.BOLDWEIGHT_NORMAL);
    rt.append(" Jumped over the lazy dog", font3);

    cell.setCellValue(rt);

这应该给你一个单元格,混合了粗体,斜体+下划线和普通

That should give you a cell with a mixture of bold, italic+underline and normal

这篇关于如何使用HSSFSheet Apache POI在excell中创建具有多种样式的单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 21:27