java中 poi3.9 sheet.shiftRows()时如何做到上移时覆盖原本行的数据
时间: 2024-03-09 18:49:46 浏览: 30
在使用 `sheet.shiftRows()` 方法上移行时,如果希望新插入的行覆盖原本行的数据,可以将第五个参数 `resetOriginalRowHeight` 设置为 `true`。这样,被移动的行将被删除,而新插入的行将会覆盖原本行的数据。
以下是使用 `sheet.shiftRows()` 方法上移行并覆盖原本行的数据的示例代码:
```
// 将第 21 行到第 44 行上移 moveNUM 行,并覆盖原本行的数据
int startRow = 21;
int endRow = 44;
int moveNUM = -1; // 向上移动一行
sheet.shiftRows(startRow, endRow, moveNUM, true, true);
```
在上面的示例代码中,我们将第 21 行到第 44 行上移了一行,并将第 21 行覆盖了原本的数据。
希望这可以帮助您解决问题!
相关问题
sheet.shiftRows(21, 44, moveNUM,true); java中 poi3.9报错
根据您提供的信息,我可以猜测您在使用 Apache POI 3.9 来操作 Excel 文件,并且在使用 `sheet.shiftRows(21, 44, moveNUM,true)` 方法时遇到了报错。
在 Apache POI 3.9 中,`sheet.shiftRows()` 方法的参数列表如下:
```
void shiftRows(int startRow, int endRow, int n, boolean copyRowHeight, boolean resetOriginalRowHeight);
```
其中,第四个参数 `copyRowHeight` 指定是否将被移动的行的行高复制到新插入的行中,而第五个参数 `resetOriginalRowHeight` 指定是否重置原始行的高度。
因此,您可以尝试将您的代码修改为:
```
sheet.shiftRows(21, 44, moveNUM, true, true);
```
其中,第四个参数 `true` 表示将被移动的行的行高复制到新插入的行中,第五个参数 `true` 表示重置原始行的高度。
希望这可以帮助您解决问题!
sheet.shiftRows()插入一行,并且让上下行合并格式不变
对于使用Apache POI操作Excel的开发人员来说,sheet.shiftRows()方法可以插入一行,并且让上下行合并格式不变。该方法的语法如下:
```
public void shiftRows(int startRow, int endRow, int n)
```
其中,startRow表示要移动的起始行,endRow表示要移动的结束行,n表示要移动的行数。如果n为正数,则表示向下移动n行;如果n为负数,则表示向上移动n行。在移动行之后,上下行的合并格式不会发生变化。
例如,如果要在第2行插入一行,并且让上下行合并格式不变,可以使用以下代码:
```
sheet.shiftRows(2, sheet.getLastRowNum(), 1);
```
这将插入一行,并将原来在第2行及其以下的行都向下移动一行,从而腾出第2行的位置。在移动行之后,上下行的合并格式不会发生变化。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)