如何创建使用Apache的HSSFSheet EXCELL POI有多种样式的细胞? [英] How to create cell with multiple styles in excell using HSSFSheet Apache 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屋!