add method for #1342

This commit is contained in:
Looly 2021-01-02 11:36:14 +08:00
parent 6110a20f0a
commit 71177864be
4 changed files with 40 additions and 12 deletions

View File

@ -8,6 +8,7 @@
### 新特性
* 【core 】 DynaBean.create增加重载方法pr#245@Gitee
* 【core 】 IdcardUtil增加重载是否忽略大小写issue#1348@Github
* 【poi 】 SheetRidReader增加getRidByIndex方法issue#1342@Github
### Bug修复

View File

@ -145,7 +145,7 @@ public class ExcelBase<T extends ExcelBase<T>> implements Closeable {
}
/**
* 获取指定坐标单元格单元格不存在时返回<code>null</code>
* 获取指定坐标单元格单元格不存在时返回{@code null}
*
* @param locationRef 单元格地址标识符例如A11B5
* @return {@link Cell}
@ -157,7 +157,7 @@ public class ExcelBase<T extends ExcelBase<T>> implements Closeable {
}
/**
* 获取指定坐标单元格单元格不存在时返回<code>null</code>
* 获取指定坐标单元格单元格不存在时返回{@code null}
*
* @param x X坐标从0计数即列号
* @param y Y坐标从0计数即行号
@ -193,7 +193,7 @@ public class ExcelBase<T extends ExcelBase<T>> implements Closeable {
}
/**
* 获取指定坐标单元格如果isCreateIfNotExist为false则在单元格不存在时返回<code>null</code>
* 获取指定坐标单元格如果isCreateIfNotExist为false则在单元格不存在时返回{@code null}
*
* @param locationRef 单元格地址标识符例如A11B5
* @param isCreateIfNotExist 单元格不存在时是否创建
@ -206,7 +206,7 @@ public class ExcelBase<T extends ExcelBase<T>> implements Closeable {
}
/**
* 获取指定坐标单元格如果isCreateIfNotExist为false则在单元格不存在时返回<code>null</code>
* 获取指定坐标单元格如果isCreateIfNotExist为false则在单元格不存在时返回{@code null}
*
* @param x X坐标从0计数即列号
* @param y Y坐标从0计数即行号

View File

@ -233,7 +233,7 @@ public class ExcelWriter extends ExcelBase<ExcelWriter> {
/**
* 重命名sheet
*
* @param sheet sheet需要0表示第一个sheet
* @param sheet sheet序号0表示第一个sheet
* @param sheetName 新的sheet名
* @return this
* @since 4.1.8

View File

@ -1,5 +1,6 @@
package cn.hutool.poi.excel.sax;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil;
@ -11,7 +12,7 @@ import org.xml.sax.helpers.DefaultHandler;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
/**
@ -36,8 +37,8 @@ public class SheetRidReader extends DefaultHandler {
private final static String SHEET_ID_ATTR = "sheetId";
private final static String NAME_ATTR = "name";
private final Map<Integer, Integer> ID_RID_MAP = new HashMap<>();
private final Map<String, Integer> NAME_RID_MAP = new HashMap<>();
private final Map<Integer, Integer> ID_RID_MAP = new LinkedHashMap<>();
private final Map<String, Integer> NAME_RID_MAP = new LinkedHashMap<>();
/**
* 读取Wordkbook的XML中sheet标签中sheetId和rid的对应关系
@ -79,7 +80,7 @@ public class SheetRidReader extends DefaultHandler {
*/
public Integer getRidBySheetIdBase0(int sheetId) {
final Integer rid = getRidBySheetId(sheetId + 1);
if(null != rid){
if (null != rid) {
return rid - 1;
}
return null;
@ -104,7 +105,33 @@ public class SheetRidReader extends DefaultHandler {
*/
public Integer getRidByNameBase0(String sheetName) {
final Integer rid = getRidByName(sheetName);
if(null != rid){
if (null != rid) {
return rid - 1;
}
return null;
}
/**
* 通过sheet的序号获取rid
*
* @param index 序号从0开始
* @return rid
* @since 5.5.7
*/
public Integer getRidByIndex(int index) {
return CollUtil.get(this.NAME_RID_MAP.values(), index);
}
/**
* 通过sheet的序号获取rid
*
* @param index 序号从0开始
* @return rid从0开始
* @since 5.5.7
*/
public Integer getRidByIndexBase0(int index) {
final Integer rid = CollUtil.get(this.NAME_RID_MAP.values(), index);
if (null != rid) {
return rid - 1;
}
return null;
@ -114,7 +141,7 @@ public class SheetRidReader extends DefaultHandler {
public void startElement(String uri, String localName, String qName, Attributes attributes) {
if (TAG_NAME.equalsIgnoreCase(localName)) {
final String ridStr = attributes.getValue(RID_ATTR);
if(StrUtil.isEmpty(ridStr)){
if (StrUtil.isEmpty(ridStr)) {
return;
}
final int rid = Integer.parseInt(StrUtil.removePrefixIgnoreCase(ridStr, Excel07SaxReader.RID_PREFIX));
@ -127,7 +154,7 @@ public class SheetRidReader extends DefaultHandler {
// sheetId和rid映射
final String sheetIdStr = attributes.getValue(SHEET_ID_ATTR);
if(StrUtil.isNotEmpty(sheetIdStr)){
if (StrUtil.isNotEmpty(sheetIdStr)) {
ID_RID_MAP.put(Integer.parseInt(sheetIdStr), rid);
}
}