如何创建使用Apache的HSSFSheet EXCELL POI有多种样式的细​​胞? [英] How to create cell with multiple styles in excell using HSSFSheet Apache POI?

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

问题描述

我创造了出口文档作为Excel中的一个脚本。
我发现在像一些困难:
我要像名称:标记的出生日期: 2014年11月11日单元格的值通过合并几个细胞。
你可以帮我获得解决此问题?

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 ?

在此先感谢!

推荐答案

我已经创造了这个很短的完整的例子。

I have created a short complete example for this.

import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.*;

import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;


class RichTextTest {

 public static void main(String[] args) {
  Workbook wb = new XSSFWorkbook();
  Sheet sheet = wb.createSheet("Sheet1");

  Row row = sheet.createRow(0);

  Cell cell = row.createCell(0);

  RichTextString richString = new XSSFRichTextString( "Name: Mark DOB: 11-11-2014" );
                                                     //^0  ^4     ^11^14
  Font fontBold = wb.createFont();
  fontBold.setBoldweight(Font.BOLDWEIGHT_BOLD);

  richString.applyFont( 0, 4, fontBold );
  richString.applyFont( 11, 14, fontBold );
  cell.setCellValue(richString);


  try {
   FileOutputStream fileOut = new FileOutputStream("workbook.xlsx");
   wb.write(fileOut);
   fileOut.flush();
   fileOut.close();
  } catch (FileNotFoundException fnfex) {
  } catch (IOException ioex) {
  }

 }
}

进一步的阅读可见文档。

For further reading see documentation.

如何创建工作簿,表和单元格:的http:/ /poi.apache.org/s$p$padsheet/quick-guide.html#CreateCells

How to create workbook, sheet and cells: http://poi.apache.org/spreadsheet/quick-guide.html#CreateCells

如何使用富文本:的https://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFRichTextString.html

该字体界面: https://开头的POI。 apache.org/apidocs/org/apache/poi/ss/usermodel/Font.html

这篇关于如何创建使用Apache的HSSFSheet EXCELL POI有多种样式的细​​胞?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆