添加区域,合并单元格 Region region = new Region((short)rowFrom,(short)columnFrom,(short)rowTo,(short)columnTo); sheet.addMergedRegion(region); //得到所有区域 sheet.getNumMergedRegions() render_code();
package com.baidu.poitest;import java.io.FileOutputStream;import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook;/** * @author lixiaoqing * */ public class SimpleDemo {/** * @param args */ public static void main(String[] args) throws Exception{ // TODO Auto-generated method stub HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("new sheet"); // Create a row and put some cells in it. Rows are 0 based. HSSFRow row = sheet.createRow((short)0); // Create a cell and put a value in it. HSSFCell cell = row.createCell((short)0); cell.setCellValue(1); // Or do it on one line. row.createCell((short)1).setCellValue(1.2); row.createCell((short)2).setCellValue("This is a string"); row.createCell((short)3).setCellValue(true);
// Create a row and put some cells in it. Rows are 0 based. row = sheet.createRow((short)1); // Create a cell and put a value in it. cell = row.createCell((short)0); cell.setCellValue(1); // Or do it on one line. row.createCell((short)1).setCellValue(2.4); row.createCell((short)2).setCellValue("This is another string"); row.createCell((short)3).setCellValue(false); // Write the output to a file FileOutputStream fileOut = new FileOutputStream("workbook2.xls"); wb.write(fileOut); fileOut.close();}}简单点了
sheet.setColumnWidth((short)column,(short)width);
row.setHeight((short)height);
render_code();
Region region = new Region((short)rowFrom,(short)columnFrom,(short)rowTo,(short)columnTo);
sheet.addMergedRegion(region);
//得到所有区域
sheet.getNumMergedRegions()
render_code();
虚线HSSFCellStyle.BORDER_DOTTED
实线HSSFCellStyle.BORDER_THIN
代码public static HSSFCellStyle getCellStyle(short type)
{
HSSFWorkbook wb = new HSSFWorkbook();
HSSFCellStyle style = wb.createCellStyle();
style.setBorderBottom(type);//下边框
style.setBorderLeft(type);//左边框
style.setBorderRight(type);//右边框
style.setBorderTop(type);//上边框
return style;
}
render_code();
设置字体和内容位置
代码HSSFFont f = wb.createFont();
f.setFontHeightInPoints((short) 11);//字号
f.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);//加粗
style.setFont(f);
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//左右居中
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//上下居中
style.setRotation(short rotation);//单元格内容的旋转的角度
HSSFDataFormat df = wb.createDataFormat();
style1.setDataFormat(df.getFormat("0.00%"));//设置单元格数据格式
cell.setCellFormula(string);//给单元格设公式
style.setRotation(short rotation);//单元格内容的旋转的角度
cell.setCellStyle(style);
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;/**
* @author lixiaoqing
*
*/
public class SimpleDemo {/**
* @param args
*/
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet"); // Create a row and put some cells in it. Rows are 0 based.
HSSFRow row = sheet.createRow((short)0);
// Create a cell and put a value in it.
HSSFCell cell = row.createCell((short)0);
cell.setCellValue(1); // Or do it on one line.
row.createCell((short)1).setCellValue(1.2);
row.createCell((short)2).setCellValue("This is a string");
row.createCell((short)3).setCellValue(true);
// Create a row and put some cells in it. Rows are 0 based.
row = sheet.createRow((short)1);
// Create a cell and put a value in it.
cell = row.createCell((short)0);
cell.setCellValue(1); // Or do it on one line.
row.createCell((short)1).setCellValue(2.4);
row.createCell((short)2).setCellValue("This is another string");
row.createCell((short)3).setCellValue(false); // Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook2.xls");
wb.write(fileOut);
fileOut.close();}}简单点了
render_code(); 请问该功能是做什么用的?