本文整理了Java中org.apache.poi.ss.usermodel.Sheet.shiftRows()
方法的一些代码示例,展示了Sheet.shiftRows()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Sheet.shiftRows()
方法的具体详情如下:
包路径:org.apache.poi.ss.usermodel.Sheet
类名称:Sheet
方法名:shiftRows
[英]Shifts rows between startRow and endRow n number of rows. If you use a negative number, it will shift rows up. Code ensures that rows don't wrap around. Calls shiftRows(startRow, endRow, n, false, false);
Additionally shifts merged regions that are completely defined in these rows (ie. merged 2 cells on a row to be shifted).
[中]在startRow和endRow之间移动行数n行数。如果使用负数,它会将行上移。代码确保行不会环绕。调用shiftRows(startRow、endRow、n、false、false);
另外,移动在这些行中完全定义的合并区域(即,要移动的行上合并了两个单元格)。
代码示例来源:origin: pentaho/pentaho-kettle
private void openLine() {
if ( data.shiftExistingCells ) {
data.sheet.shiftRows( data.posY, Math.max( data.posY, data.sheet.getLastRowNum() ), 1 );
}
}
代码示例来源:origin: stackoverflow.com
Workbook wb = WorkbookFactory.create(file);
Sheet sheet = wb.getSheetAt(0);
sheet.shiftRows(3, 3, -1);
代码示例来源:origin: cpesch/RouteConverter
private void shiftRowFromEndTo(int index) {
int lastRowNum = sheet.getLastRowNum();
sheet.shiftRows(lastRowNum, lastRowNum, index - lastRowNum);
}
代码示例来源:origin: metatron-app/metatron-discovery
private void createHeaderRow(Sheet sheet) {
sheet.shiftRows(0, sheet.getLastRowNum(), 1);
Row row = sheet.createRow(0);
for (int i = 0; i < sheet.getRow(1).getPhysicalNumberOfCells(); i++) {
Cell cell = row.createCell(i);
cell.setCellValue("field_" + (i + 1));
}
}
代码示例来源:origin: zsl131/spring-boot-test
/**
* 创建新行,在使用时只要添加完一行,需要调用该方法创建
*/
public void createNewRow() {
if(lastRowIndex>curRowIndex&&curRowIndex!=initRowIndex) {
sheet.shiftRows(curRowIndex, lastRowIndex, 1,true,true);
lastRowIndex++;
}
curRow = sheet.createRow(curRowIndex);
curRow.setHeightInPoints(rowHeight);
curRowIndex++;
curColIndex = initColIndex;
}
代码示例来源:origin: SheetJS/jxls
public static void shiftRows(Sheet sheet, int startRow, int endRow,
int shiftNum) {
if (startRow <= endRow) {
short[] rowHeights = getRowHeights(sheet, startRow, endRow);
sheet.shiftRows(startRow, endRow, shiftNum, false, false);
copyPositiveRowHeight(sheet, startRow, endRow, shiftNum, rowHeights);
}
}
代码示例来源:origin: net.sf.jxls/jxls-core
public static void shiftRows(Sheet sheet, int startRow, int endRow,
int shiftNum) {
if (startRow <= endRow) {
short[] rowHeights = getRowHeights(sheet, startRow, endRow);
sheet.shiftRows(startRow, endRow, shiftNum, false, false);
copyPositiveRowHeight(sheet, startRow, endRow, shiftNum, rowHeights);
}
}
代码示例来源:origin: stackoverflow.com
public static void deleteRowSavedFromSheet(Sheet sheet, List<Row> rowsToRemoved){
for(Row row : rowsToRemoved){
sheet.shiftRows(row.getRowNum()+1, sheet.getLastRowNum(), -1);
}
}
代码示例来源:origin: cpesch/RouteConverter
public void top(int index, int topOffset) {
// shift index row to the end
int rowForIndex = shiftRowToTheEnd(index);
// move all rows between topOffset and rowForIndex one down
sheet.shiftRows(topOffset + 1, rowForIndex - 1, 1);
// move index row from the end to topOffset row
shiftRowFromEndTo(topOffset + 1);
super.top(index, topOffset);
}
代码示例来源:origin: org.eclipse.epsilon/epsilon-spreadsheets
@Override
public void removeRow(final SpreadsheetRow row)
{
LOGGER.debug("Inside removeRow() method");
LOGGER.debug("Row: " + row);
if (row != null)
{
final ExcelRow excelRow = (ExcelRow) row;
final int rowIndex = excelRow.row.getRowNum();
final int lastRowNum = this.sheet.getLastRowNum();
this.sheet.removeRow(excelRow.row);
if (rowIndex >= this.getFirstRowIndex() && rowIndex < lastRowNum)
{
sheet.shiftRows(rowIndex + 1, lastRowNum, -1);
}
}
}
代码示例来源:origin: stackoverflow.com
private void sortSheet(Sheet sheet, int column, int rowStart) {
boolean sorting = true;
int lastRow = sheet.getLastRowNum();
while (sorting == true) {
sorting = false;
for (Row row : sheet) {
if (row.getRowNum()<rowStart) continue;
if (lastRow==row.getRowNum()) break;
Row nextRow= sheet.getRow(row.getRowNum()+1);
if (nextRow== null) continue;
Date firstValue = row.getCell(column).getDateCellValue() ;
Date secondValue = nextRow.getCell(column).getDateCellValue() ;
if (secondValue.before(firstValue)) {
sheet.shiftRows(nextRow.getRowNum(), nextRow.getRowNum(), -1);
sheet.shiftRows(row.getRowNum(), row.getRowNum(), 1);
sorting = true;
}
}
}
}
代码示例来源:origin: cpesch/RouteConverter
public void add(int index, ExcelPosition position) {
// shift all rows from index one position down
int rowForIndex = index < getPositionCount() ? getPosition(index).getRow().getRowNum() : position.getRow().getRowNum();
sheet.shiftRows(rowForIndex, sheet.getLastRowNum(), 1);
// shift row to add to the desired position (+1 for header)
int sourceRowIndex = position.getRow().getRowNum() + 1;
sheet.shiftRows(sourceRowIndex, sourceRowIndex, rowForIndex - sourceRowIndex);
positions.add(index, position);
}
代码示例来源:origin: cn.afterturn/easypoi-base
private Workbook removeSuperfluousRows(Workbook book, List<Row> rowList, ImportParams params) {
for (int i = params.getStartSheetIndex(); i < params.getStartSheetIndex()
+ params.getSheetNum(); i++) {
for (int j = rowList.size() - 1; j >= 0; j--) {
if (rowList.get(j).getRowNum() < rowList.get(j).getSheet().getLastRowNum()) {
book.getSheetAt(i).shiftRows(rowList.get(j).getRowNum() + 1, rowList.get(j).getSheet().getLastRowNum(), -1);
} else if (rowList.get(j).getRowNum() == rowList.get(j).getSheet().getLastRowNum()) {
book.getSheetAt(i).createRow(rowList.get(j).getRowNum() + 1);
book.getSheetAt(i).shiftRows(rowList.get(j).getRowNum() + 1, rowList.get(j).getSheet().getLastRowNum() + 1, -1);
}
}
}
return book;
}
代码示例来源:origin: cpesch/RouteConverter
private int shiftRowToTheEnd(int index) {
ExcelPosition row = getPosition(index);
int rowForIndex = row.getRow().getRowNum();
sheet.shiftRows(rowForIndex, rowForIndex, sheet.getLastRowNum() - rowForIndex + 1);
return rowForIndex;
}
代码示例来源:origin: cpesch/RouteConverter
public ExcelPosition remove(int index) {
// shift all rows one forward to index
int rowForIndex = getPosition(index).getRow().getRowNum() + 1;
int lastRowNum = sheet.getLastRowNum();
sheet.shiftRows(rowForIndex, lastRowNum, -1);
// remove last row
Row row = sheet.getRow(lastRowNum);
if (row != null)
sheet.removeRow(row);
return super.remove(index);
}
代码示例来源:origin: cpesch/RouteConverter
public void bottom(int index, int bottomOffset) {
// shift index row to the end
int lastRowNum = sheet.getLastRowNum();
int rowForIndex = shiftRowToTheEnd(index);
// move all rows between rowForIndex and lastRowNum-bottomOffset one up
sheet.shiftRows(rowForIndex + 1, lastRowNum - bottomOffset, -1);
// move index row from the end to lastRowNum-bottomOffset row
shiftRowFromEndTo(sheet.getLastRowNum() - (bottomOffset + 1));
super.bottom(index, bottomOffset);
}
代码示例来源:origin: cpesch/RouteConverter
public void move(int firstIndex, int secondIndex) {
// shift secondIndex row to the end
shiftRowToTheEnd(secondIndex);
// move first row to secondIndex
ExcelPosition first = getPosition(firstIndex);
int rowForFirstIndex = first.getRow().getRowNum();
sheet.shiftRows(rowForFirstIndex, rowForFirstIndex, secondIndex - firstIndex);
// move secondIndex row from the end to firstIndex row
shiftRowFromEndTo(rowForFirstIndex);
super.move(firstIndex, secondIndex);
}
代码示例来源:origin: tobyweston/simple-excel
public void insertAt(Workbook workbook, SheetIndex sheetIndex, RowIndex rowIndex) {
Sheet sheet = workbook.getSheetAt(sheetIndex.value());
sheet.shiftRows(rowIndex.value(), sheet.getLastRowNum(), shiftDownAmount);
org.apache.poi.ss.usermodel.Row row = sheet.createRow(rowIndex.value());
copyCellsTo(row, workbook);
}
代码示例来源:origin: org.hswebframework/hsweb-expands-office
@Override
public void nextRow(Cell cell) {
if (nowRow == null) {
//首次渲染行,则将表达式所在行替换为数据行
nowRow = cell.getRow();
} else {
//创建下一行
int rowNum = nowRow.getRowNum() + 1;
//将最后一行移动到当前行,以实现插入行效果
sheet.shiftRows(rowNum,sheet.getLastRowNum(),1,true,false);
Row tmp = sheet.createRow(rowNum);
tmp.setHeight(nowRow.getHeight());
tmp.setHeightInPoints(nowRow.getHeightInPoints());
nowRow = tmp;
}
}
代码示例来源:origin: hs-web/hsweb-expands
@Override
public void nextRow(Cell cell) {
if (nowRow == null) {
//首次渲染行,则将表达式所在行替换为数据行
nowRow = cell.getRow();
} else {
//创建下一行
int rowNum = nowRow.getRowNum() + 1;
//将最后一行移动到当前行,以实现插入行效果
sheet.shiftRows(rowNum,sheet.getLastRowNum(),1,true,false);
Row tmp = sheet.createRow(rowNum);
tmp.setHeight(nowRow.getHeight());
tmp.setHeightInPoints(nowRow.getHeightInPoints());
nowRow = tmp;
}
}
内容来源于网络,如有侵权,请联系作者删除!