我现在使用的是poi-3.8 version,简单描述一下下载,以及该框架的API位置
@author YHC
poi下载地址 :POI下载页面
简单介绍一下POI操作Excel的快速指南的位置:
解压下载后的文件按照这个路径打开API:poi-bin-3.8-20120326poi-3.8docsindex.html
我当前的操作只需要一个jar包:poi-3.8-20120326.jar
以下就是文字竖着显示的设置的代码:
l.test;import java.io.FileOutputStream;
import java.util.Calendar;
import java.util.Date;import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;/*** Excel导出* @author Administrator**/
public class POIExcelExportTest {public static void main(String[] args) throws Exception {//创建一个ExcelWorkbook wb = new HSSFWorkbook();//创建一个输出流对象,以便将创建好的Excel写入文件FileOutputStream fileOut = new FileOutputStream("WORKBOOK.xls");//CreationHelper createHelper = wb.getCreationHelper();//创建一个sheetSheet sheet = wb.createSheet("附表");//合并一个单元格,这个地方会在下面用图介绍sheet.addMergedRegion(new CellRangeAddress(0, //first row (0-based)10, //last row (0-based)0, //first column (0-based)1 //last column (0-based)));//创建一个行对象,下标从0开始Row row1ateRow(0);//创建一个样式CellStyle cellStyle1 = wb.createCellStyle();//设置左右对齐居中cellStyle1.setAlignment(CellStyle.ALIGN_CENTER);//垂直对其居中cellStyle1.setVerticalAlignment(CellStyle.VERTICAL_CENTER);//设置true让Cell中的内容以多行显示cellStyle1.setWrapText(true);//创建一个单元格,单元格下标从0开始Cell c1ateCell(0);//创建富文本,如果你想每一行显示一个字体那么就按照我下面的写,如果想//多个显示在一行,那么去掉他们之间的rn就好了c1.ateRichTextString("合rn并rn后rn选rn择rn我rn" +",rn这rn只rn值rn!"));//设置样式c1.setCellStyle(cellStyle1);//写入文件wb.write(fileOut);//关闭输出流fileOut.close();}
}
当运行上面的代码之后的效果图:
现在解释一下以上代码中的合并单元格代码:
我还才刚刚接触这个框架,如有不足之处或者是错误的地方请大家提出,thanks!
本文发布于:2024-02-04 06:27:34,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170701032253107.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |