ApachePOIHSSF和XSSF读写EXCEL总结文档格式.docx

上传人:b****6 文档编号:8658264 上传时间:2023-05-12 格式:DOCX 页数:10 大小:27.41KB
下载 相关 举报
ApachePOIHSSF和XSSF读写EXCEL总结文档格式.docx_第1页
第1页 / 共10页
ApachePOIHSSF和XSSF读写EXCEL总结文档格式.docx_第2页
第2页 / 共10页
ApachePOIHSSF和XSSF读写EXCEL总结文档格式.docx_第3页
第3页 / 共10页
ApachePOIHSSF和XSSF读写EXCEL总结文档格式.docx_第4页
第4页 / 共10页
ApachePOIHSSF和XSSF读写EXCEL总结文档格式.docx_第5页
第5页 / 共10页
ApachePOIHSSF和XSSF读写EXCEL总结文档格式.docx_第6页
第6页 / 共10页
ApachePOIHSSF和XSSF读写EXCEL总结文档格式.docx_第7页
第7页 / 共10页
ApachePOIHSSF和XSSF读写EXCEL总结文档格式.docx_第8页
第8页 / 共10页
ApachePOIHSSF和XSSF读写EXCEL总结文档格式.docx_第9页
第9页 / 共10页
ApachePOIHSSF和XSSF读写EXCEL总结文档格式.docx_第10页
第10页 / 共10页
亲,该文档总共10页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

ApachePOIHSSF和XSSF读写EXCEL总结文档格式.docx

《ApachePOIHSSF和XSSF读写EXCEL总结文档格式.docx》由会员分享,可在线阅读,更多相关《ApachePOIHSSF和XSSF读写EXCEL总结文档格式.docx(10页珍藏版)》请在冰点文库上搜索。

ApachePOIHSSF和XSSF读写EXCEL总结文档格式.docx

Sheetsheet1=wb.createSheet("

HSSF_Sheet_1"

);

Sheetsheet2=wb.createSheet("

HSSF_Sheet_2"

//Row表示一行Cell表示一列

Rowrow=null;

Cellcell=null;

for(inti=0;

i<

60;

i=i+2){

//获得这个sheet的第i行

row=sheet1.createRow(i);

//设置行长度自动

//row.setHeight((short)500);

row.setHeightInPoints(20);

//row.setZeroHeight(true);

for(intj=0;

j<

25;

j++){

//设置每个sheet每一行的宽度,自动,根据需求自行确定

sheet1.autoSizeColumn(j+1,true);

//创建一个基本的样式

CellStylecellStyle=SummaryHSSF.createStyleCell(wb);

//获得这一行的每j列

cell=row.createCell(j);

if(j==0){

//设置文字在单元格里面的位置

cellStyle=SummaryHSSF.setCellStyleAlignment(cellStyle,CellStyle.ALIGN_CENTER,CellStyle.VERTICAL_CENTER);

//先创建字体样式,并把这个样式加到单元格的字体里面

cellStyle.setFont(createFonts(wb));

//把这个样式加到单元格里面

cell.setCellStyle(cellStyle);

//给单元格设值

cell.setCellValue(true);

}elseif(j==1){

//设置这个样式的格式(Format)

cellStyle=SummaryHSSF.setCellFormat(helper,cellStyle,"

#,##0.0000"

cell.setCellValue(newDouble(2008.2008));

}elseif(j==2){

cell.setCellValue(helper.createRichTextString("

RichString"

+i+j));

}elseif(j==3){

MM-yyyy-dd"

cell.setCellValue(newDate());

}elseif(j==24){

//设置公式

cell.setCellFormula("

SUM(E"

+(i+1)+"

:

X"

)"

}else{

cellStyle=SummaryHSSF.setFillBackgroundColors(cellStyle,IndexedColors.ORANGE.getIndex(),IndexedColors.ORANGE.getIndex(),CellStyle.SOLID_FOREGROUND);

cell.setCellValue

(1);

}

//输出

OutputStreamos=newFileOutputStream(newFile("

c:

//SummaryHSSF.xls"

));

wb.write(os);

os.close();

/**

*边框

*@paramwb

*@return

*/

publicstaticCellStylecreateStyleCell(Workbookwb){

CellStylecellStyle=wb.createCellStyle();

//设置一个单元格边框颜色

cellStyle.setBorderBottom(CellStyle.BORDER_THIN);

cellStyle.setBorderTop(CellStyle.BORDER_THIN);

cellStyle.setBorderLeft(CellStyle.BORDER_THIN);

cellStyle.setBorderRight(CellStyle.BORDER_THIN);

cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());

cellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());

cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());

cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());

returncellStyle;

*设置文字在单元格里面的位置

*CellStyle.ALIGN_CENTER

*CellStyle.VERTICAL_CENTER

*@paramcellStyle

*@paramhalign

*@paramvalign

publicstaticCellStylesetCellStyleAlignment(CellStylecellStyle,shorthalign,shortvalign){

//设置上下

cellStyle.setAlignment(CellStyle.ALIGN_CENTER);

//设置左右

cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);

*格式化单元格

*如#,##0.00,m/d/yy去HSSFDataFormat或XSSFDataFormat里面找

*@paramfmt

publicstaticCellStylesetCellFormat(CreationHelperhelper,CellStylecellStyle,Stringfmt){

//还可以用其它方法创建format

cellStyle.setDataFormat(helper.createDataFormat().getFormat(fmt));

*前景和背景填充的着色

*@parambgIndexedColors.ORANGE.getIndex();

*@paramfgIndexedColors.ORANGE.getIndex();

*@paramfpCellStyle.SOLID_FOREGROUND

publicstaticCellStylesetFillBackgroundColors(CellStylecellStyle,shortbg,shortfg,shortfp){

//cellStyle.setFillBackgroundColor(bg);

cellStyle.setFillForegroundColor(fg);

cellStyle.setFillPattern(fp);

*设置字体

publicstaticFontcreateFonts(Workbookwb){

//创建Font对象

Fontfont=wb.createFont();

//设置字体

font.setFontName("

黑体"

//着色

font.setColor(HSSFColor.BLUE.index);

//斜体

font.setItalic(true);

//字体大小

font.setFontHeight((short)300);

returnfont;

publicclassSummaryHSSF{

publicstaticvoidmain(String[]args)throwsIOException{

//创建Sheet并给名字(表示Excel的一个Sheet)

i=i+2){

if(j==0){

}elseif(j==1){

//设置这个样式的格式(Format)

}elseif(j==2){

}elseif(j==3){

}elseif(j==24){

}

/**

*@paramwb

*@return

*/

publicstaticCellStylecreateStyleCell(Workbookwb){

*CellStyle.ALIGN_CENTER

*CellStyle.VERTICAL_CENTER

*@paramcellStyle

*@paramhalign

*@paramvalign

publicstaticCellStylesetCellStyleAlignment(CellStylecellStyle,shorthalign,shortvalign){

*@paramfmt

publicstaticCellStylesetCellFormat(CreationHelperhelper,CellStylecellStyle,Stringfmt){

//还可以用其它方法创建format

*@paramfpCellStyle.SOLID_FOREGROUND

publicstaticCellStylesetFillBackgroundColors(CellStylecellStyle,shortbg,shortfg,shortfp){

publicstaticFontcreateFonts(Workbookwb){

读取Excel文件

publicclassReadExcel{

publicstaticvoidmain(String[]args)throwsExce

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 求职职场 > 简历

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2