本文整理汇总了Java中org.apache.poi.hssf.usermodel.HSSFSheet.addMergedRegion方法的典型用法代码示例。如果您正苦于以下问题:Java HSSFSheet.addMergedRegion方法的具体用法?Java HSSFSheet.addMergedRegion怎么用?Java HSSFSheet.addMergedRegion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.hssf.usermodel.HSSFSheet
的用法示例。
在下文中一共展示了HSSFSheet.addMergedRegion方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setRegionBorder
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
/**
* 获取合并单元格式
*
* @param sheet
* @param row
* @param columnFrom
* @param columnTo
* @return
*/
private static void setRegionBorder(HSSFSheet sheet, int row, int columnFrom, int columnTo) {
CellRangeAddress region = new CellRangeAddress(row, row, columnFrom, columnTo);
sheet.addMergedRegion(region);
final short border = CellStyle.BORDER_THIN;
HSSFWorkbook wb = sheet.getWorkbook();
RegionUtil.setBorderBottom(border, region, sheet, wb);
RegionUtil.setBorderTop(border, region, sheet, wb);
RegionUtil.setBorderLeft(border, region, sheet, wb);
RegionUtil.setBorderRight(border, region, sheet, wb);
RegionUtil.setBottomBorderColor(HSSFColor.BLACK.index, region, sheet, wb);
RegionUtil.setTopBorderColor(HSSFColor.BLACK.index, region, sheet, wb);
RegionUtil.setLeftBorderColor(HSSFColor.BLACK.index, region, sheet, wb);
RegionUtil.setRightBorderColor(HSSFColor.BLACK.index, region, sheet, wb);
}
示例2: writeCondtions
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
/**
* 表头条件
* @param sheet
* @param t
* @param cellCount
* @return
*/
void writeCondtions(HSSFSheet sheet){
T t = getConditions();
if (t!=null) {
HSSFRow row = sheet.createRow(getRowNumber());
row.setHeight((short) 500);
CellRangeAddress cra = new CellRangeAddress(getRowNumber(), getRowNumber(), 0, getColumnJson().size());
sheet.addMergedRegion(cra);
HSSFCell cell = row.createCell(0);
HSSFCellStyle style = cell.getCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setWrapText(true);
cell.setCellStyle(style);
setCellValue(cell, formatCondition(t));
addRowNumber();
}
}
示例3: rowSpan
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
/**
* 合并单元格(行合并),合并规则:内容相同则合并
*
* @param sheet 合并的sheet
* @param colindex 合并列索引
* @return
*/
@SuppressWarnings("deprecation")
public static HSSFSheet rowSpan(HSSFSheet sheet, int colindex, int contentBeginIndex) {
// 总行数
int rowNum = sheet.getLastRowNum();
HSSFRow row = sheet.getRow(1);
// 正文内容应该从第二行开始,第一行为表头的标题
int startRow = contentBeginIndex;
String startValue = "";
for (int i = contentBeginIndex; i <= rowNum; i++) {
row = sheet.getRow(i);
String value = row.getCell(colindex).getRichStringCellValue().getString();
if (i == contentBeginIndex) {
startValue = value;
continue;
}
if (StrUtil.isNotBlank(startValue) && StrUtil.isNotBlank(value) && startValue.equals(value)) {
if (i == rowNum)
sheet.addMergedRegion(new CellRangeAddress(startRow, i , colindex, colindex));
else
continue;
} else {
if((i-1)>startRow)
sheet.addMergedRegion(new CellRangeAddress(startRow, i - 1, colindex, colindex));
startRow = i;
}
startValue=value;
}
return sheet;
}
示例4: copyRow
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
/**
* @param srcSheet the sheet to copy.
* @param destSheet the sheet to create.
* @param srcRow the row to copy.
* @param destRow the row to create.
* @param styleMap -
*/
public static void copyRow(HSSFSheet srcSheet, HSSFSheet destSheet, HSSFRow srcRow, HSSFRow destRow, Map<Integer, HSSFCellStyle> styleMap) {
// manage a list of merged zone in order to not insert two times a merged zone
Set<CellRangeAddressWrapper> mergedRegions = new TreeSet<CellRangeAddressWrapper>();
destRow.setHeight(srcRow.getHeight());
// pour chaque row
for (int j = srcRow.getFirstCellNum(); j <= srcRow.getLastCellNum(); j++) {
if(j<0){
}else{
HSSFCell oldCell = srcRow.getCell(j); // ancienne cell
HSSFCell newCell = destRow.getCell(j); // new cell
if (oldCell != null) {
if (newCell == null) {
newCell = destRow.createCell(j);
}
// copy chaque cell
copyCell(oldCell, newCell, styleMap);
// copy les informations de fusion entre les cellules
//System.out.println("row num: " + srcRow.getRowNum() + " , col: " + (short)oldCell.getColumnIndex());
CellRangeAddress mergedRegion = getMergedRegion(srcSheet, srcRow.getRowNum(), (short) oldCell.getColumnIndex());
if (mergedRegion != null) {
//System.out.println("Selected merged region: " + mergedRegion.toString());
CellRangeAddress newMergedRegion = new CellRangeAddress(mergedRegion.getFirstRow(), mergedRegion.getLastRow(), mergedRegion.getFirstColumn(), mergedRegion.getLastColumn());
//System.out.println("New merged region: " + newMergedRegion.toString());
CellRangeAddressWrapper wrapper = new CellRangeAddressWrapper(newMergedRegion);
if (isNewMergedRegion(wrapper, mergedRegions)) {
mergedRegions.add(wrapper);
destSheet.addMergedRegion(wrapper.range);
}
}
}
}
}
}
示例5: copyMergedRegion
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
public static void copyMergedRegion(HSSFSheet sheet,
List<CellRangeAddress> regionList, int rowNum) {
for (CellRangeAddress region : regionList) {
CellRangeAddress address = new CellRangeAddress(rowNum, rowNum,
region.getFirstColumn(), region.getLastColumn());
sheet.addMergedRegion(address);
}
}
示例6: copyMergedRegion
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
public static void copyMergedRegion(final HSSFSheet sheet, final List<CellRangeAddress> regionList, final int rowNum) {
for (final CellRangeAddress region : regionList) {
final CellRangeAddress address = new CellRangeAddress(rowNum, rowNum, region.getFirstColumn(), region.getLastColumn());
sheet.addMergedRegion(address);
}
}
示例7: downloadXLSFileBase
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
public FileTransfer downloadXLSFileBase(List<String[]> list,
String filename, String name) throws Exception {
if (list == null) {
list = new ArrayList<String[]>();
}
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
HSSFCellStyle cs = wb.createCellStyle();
cs.setBorderBottom(HSSFCellStyle.BORDER_THIN);
cs.setBorderLeft(HSSFCellStyle.BORDER_THIN);
cs.setBorderRight(HSSFCellStyle.BORDER_THIN);
cs.setBorderTop(HSSFCellStyle.BORDER_THIN);
cs.setAlignment(HSSFCellStyle.ALIGN_CENTER);
cs.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
int columnCount = list.get(0).length;
sheet.setColumnWidth((short) 0, (short) 100);
sheet.addMergedRegion(new Region((short) 0, (short) 0, (short) 0,
(short) columnCount));
for (int i = 1; i <= columnCount; i++) {
sheet.setColumnWidth((short) i, (short) 4000);
}
// 表名
HSSFRow row1 = sheet.createRow(0);
HSSFCell cell = row1.createCell((short) 0);
// cell.setEncoding((short) 0);
cell.setCellValue(name);
cell.setCellStyle(cs);
row1.setHeight((short) 800);
HSSFRow rows = null;
for (int i = 0; i < list.size(); i++) {
rows = sheet.createRow(i + 1);
String cellDate[] = list.get(i);
HSSFCell cells = null;
for (int j = 0; j < cellDate.length; j++) {
cells = rows.createCell((short) (j + 1));
// cells.setEncoding((short) j);
cells.setCellValue(cellDate[j]);
cells.setCellStyle(cs);
}
if (i == 0) {
rows.setHeight((short) 600);// 标题行宽
}
}
wb.write(buffer);
return new FileTransfer(filename, "application/x-xls", buffer
.toByteArray());
}
示例8: downloadXLSFileBase
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
private FileTransfer downloadXLSFileBase(List<String[]> list,
String filename, String name) throws Exception {
if (list == null) {
list = new ArrayList<String[]>();
}
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
HSSFCellStyle cs = wb.createCellStyle();
cs.setBorderBottom(HSSFCellStyle.BORDER_THIN);
cs.setBorderLeft(HSSFCellStyle.BORDER_THIN);
cs.setBorderRight(HSSFCellStyle.BORDER_THIN);
cs.setBorderTop(HSSFCellStyle.BORDER_THIN);
cs.setAlignment(HSSFCellStyle.ALIGN_CENTER);
cs.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
int columnCount = list.get(0).length;
sheet.setColumnWidth((short) 0, (short) 100);
sheet.addMergedRegion(new Region((short) 0, (short) 0, (short) 0,
(short) columnCount));
for (int i = 1; i <= columnCount; i++) {
sheet.setColumnWidth((short) i, (short) 4000);
}
// 表名
HSSFRow row1 = sheet.createRow(0);
HSSFCell cell = row1.createCell((short) 0);
// cell.setEncoding((short) 0);
cell.setCellValue(name);
cell.setCellStyle(cs);
row1.setHeight((short) 800);
HSSFRow rows = null;
for (int i = 0; i < list.size(); i++) {
rows = sheet.createRow(i + 1);
String cellDate[] = list.get(i);
HSSFCell cells = null;
for (int j = 0; j < cellDate.length; j++) {
cells = rows.createCell((short) (j + 1));
// cells.setEncoding((short) j);
cells.setCellValue(cellDate[j]);
cells.setCellStyle(cs);
}
if (i == 0) {
rows.setHeight((short) 600);// 标题行宽
}
}
wb.write(buffer);
return new FileTransfer(filename, "application/x-xls", buffer
.toByteArray());
}
示例9: exportMotionExcel
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
/**
* 为退款经办下载表
*
* @param outfile
* @param list
* @param name
* 表名
* @param s为每一格的宽度
* @throws IOException
*/
public FileTransfer exportMotionExcel(List<String[]> list, String filename,
String name, String[] s) throws Exception {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
HSSFCellStyle cs = wb.createCellStyle();
// 设置表头的格式
HSSFCellStyle cs1 = wb.createCellStyle();
HSSFFont f1 = wb.createFont();
f1.setFontHeightInPoints((short) 20);// 字体大小
cs1.setFont(f1);
cs1.setAlignment(HSSFCellStyle.ALIGN_CENTER);
// 设置表中的格�?
cs.setBorderBottom(HSSFCellStyle.BORDER_THIN);
cs.setBorderLeft(HSSFCellStyle.BORDER_THIN);
cs.setBorderRight(HSSFCellStyle.BORDER_THIN);
cs.setBorderTop(HSSFCellStyle.BORDER_THIN);
cs.setAlignment(HSSFCellStyle.ALIGN_CENTER);
cs.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
cs.setWrapText(true);// 自动换行
// 将页面设�为横向打印模�?
HSSFPrintSetup hps = sheet.getPrintSetup();
hps.setLandscape(true); // 将页面设置为横向打印模式
hps.setPaperSize(HSSFPrintSetup.A4_PAPERSIZE);// 为A4纸的大小
int columnCount = list.get(0).length;
// 表头那一列的的宽�?
sheet.setColumnWidth((short) 0, (short) 10000);
// 合并单元�?
// sheet.addMergedRegion(new Region((short) 0, (short) 0, (short) 0,
// (short) (columnCount-1)));
// 根据String[] s来设定每一格的宽度
for (int i = 0; i < columnCount; i++) {
sheet.setColumnWidth((short) i, (Short.parseShort(s[i])));
}
// 表名
HSSFRow row1 = sheet.createRow(0);
HSSFCell cell = row1.createCell(0);
cell.setCellValue(name);
cell.setCellStyle(cs1);
row1.setHeight((short) 800);
sheet.addMergedRegion(new Region((short) 0, (short) 0, (short) 0,
(short) (columnCount - 1)));
HSSFRow rows = null;
for (int i = 0; i < list.size(); i++) {
rows = sheet.createRow(i + 1);
String cellDate[] = list.get(i);
HSSFCell cells = null;
for (int j = 0; j < cellDate.length; j++) {
cells = rows.createCell((short) (j));
cells.setCellValue(cellDate[j]);
cells.setCellStyle(cs);
}
if (i == 0) {
rows.setHeight((short) 600);// 标题行宽�?
}
}
wb.write(buffer);
return new FileTransfer(filename, "application/x-xls", buffer
.toByteArray());
}