mirror of https://github.com/alibaba/easyexcel
gongxuanzhang
2 years ago
3 changed files with 62 additions and 38 deletions
@ -0,0 +1,61 @@
|
||||
package com.alibaba.excel.util; |
||||
|
||||
import com.alibaba.excel.exception.ExcelRuntimeException; |
||||
import org.apache.poi.hssf.record.RowRecord; |
||||
import org.apache.poi.hssf.usermodel.HSSFRow; |
||||
import org.apache.poi.ss.usermodel.Row; |
||||
import org.apache.poi.util.BitField; |
||||
import org.apache.poi.util.BitFieldFactory; |
||||
import org.apache.poi.xssf.usermodel.XSSFRow; |
||||
|
||||
import java.lang.reflect.Field; |
||||
|
||||
/** |
||||
* utils |
||||
* |
||||
* @author Jiaju Zhuang |
||||
*/ |
||||
public class PoiUtils { |
||||
|
||||
/** |
||||
* Whether to customize the height |
||||
*/ |
||||
public static final BitField CUSTOM_HEIGHT = BitFieldFactory.getInstance(0x640); |
||||
|
||||
private static Field ROW_RECORD_FIELD; |
||||
|
||||
/** |
||||
* Whether to customize the height |
||||
* |
||||
* @param row row |
||||
* @return |
||||
*/ |
||||
public static boolean customHeight(Row row) { |
||||
if (row instanceof XSSFRow) { |
||||
XSSFRow xssfRow = (XSSFRow) row; |
||||
return xssfRow.getCTRow().getCustomHeight(); |
||||
} |
||||
if (row instanceof HSSFRow) { |
||||
HSSFRow hssfRow = (HSSFRow) row; |
||||
try { |
||||
if (ROW_RECORD_FIELD == null) { |
||||
initRowRecordField(); |
||||
} |
||||
RowRecord record = (RowRecord) ROW_RECORD_FIELD.get(hssfRow); |
||||
return CUSTOM_HEIGHT.getValue(record.getOptionFlags()) == 1; |
||||
} catch (IllegalAccessException ignore) { |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
|
||||
private static void initRowRecordField() { |
||||
try { |
||||
ROW_RECORD_FIELD = HSSFRow.class.getDeclaredField("row"); |
||||
ROW_RECORD_FIELD.setAccessible(true); |
||||
} catch (NoSuchFieldException e) { |
||||
throw new ExcelRuntimeException(e); |
||||
} |
||||
} |
||||
} |
@ -1,37 +0,0 @@
|
||||
package org.apache.poi.hssf.usermodel; |
||||
|
||||
import org.apache.poi.ss.usermodel.Row; |
||||
import org.apache.poi.util.BitField; |
||||
import org.apache.poi.util.BitFieldFactory; |
||||
import org.apache.poi.xssf.usermodel.XSSFRow; |
||||
|
||||
/** |
||||
* utils |
||||
* |
||||
* @author Jiaju Zhuang |
||||
*/ |
||||
public class PoiUtils { |
||||
|
||||
/** |
||||
* Whether to customize the height |
||||
*/ |
||||
public static final BitField CUSTOM_HEIGHT = BitFieldFactory.getInstance(0x640); |
||||
|
||||
/** |
||||
* Whether to customize the height |
||||
* |
||||
* @param row row |
||||
* @return |
||||
*/ |
||||
public static boolean customHeight(Row row) { |
||||
if (row instanceof XSSFRow) { |
||||
XSSFRow xssfRow = (XSSFRow)row; |
||||
return xssfRow.getCTRow().getCustomHeight(); |
||||
} |
||||
if (row instanceof HSSFRow) { |
||||
HSSFRow hssfRow = (HSSFRow)row; |
||||
return CUSTOM_HEIGHT.getValue(hssfRow.getRowRecord().getOptionFlags()) == 1; |
||||
} |
||||
return false; |
||||
} |
||||
} |
Loading…
Reference in new issue