请教各位高手用poi操作excel如何设置单元格大小?

hongqiaowei 2008-04-23 10:52:06
如题!
...全文
5250 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
yaozqwise 2009-03-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ROBINAPOLLO 的回复:]
5、设置列宽、行高
sheet.setColumnWidth((short)column,(short)width);
row.setHeight((short)height);
render_code();
[/Quote]

render_code(); 请问该功能是做什么用的?
dlcboy 2008-11-20
  • 打赏
  • 举报
回复
this.sheet.setColumnWidth(column, width * 256);
dlcboy 2008-11-20
  • 打赏
  • 举报
回复
this.sheet.setColumnWidth(column, width);

shenjie1989 2008-11-20
  • 打赏
  • 举报
回复
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();

}

}

简单点了
ROBINAPOLLO 2008-04-23
  • 打赏
  • 举报
回复
LZ,提供这些,应该够你解决的咯
ROBINAPOLLO 2008-04-23
  • 打赏
  • 举报
回复
常用单元格边框格式
虚线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);
ROBINAPOLLO 2008-04-23
  • 打赏
  • 举报
回复
添加区域,合并单元格
Region region = new Region((short)rowFrom,(short)columnFrom,(short)rowTo,(short)columnTo);
sheet.addMergedRegion(region);
//得到所有区域
sheet.getNumMergedRegions()
render_code();
ROBINAPOLLO 2008-04-23
  • 打赏
  • 举报
回复
5、设置列宽、行高
sheet.setColumnWidth((short)column,(short)width);
row.setHeight((short)height);
render_code();
kokobox 2008-04-23
  • 打赏
  • 举报
回复
ls 给的已经够用了

lz 可以去下个api,仔细查阅一下,你会对这个框架有更好的理解。

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧