forked from fanruan/easyexcel
Jiaju Zhuang
5 years ago
35 changed files with 618 additions and 647 deletions
@ -0,0 +1,93 @@
|
||||
package com.alibaba.excel.metadata; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Locale; |
||||
|
||||
import com.alibaba.excel.converters.Converter; |
||||
|
||||
/** |
||||
* ExcelBuilder |
||||
* |
||||
* @author Jiaju Zhuang |
||||
*/ |
||||
public abstract class AbstractParameterBuilder<T extends AbstractParameterBuilder, C extends BasicParameter> { |
||||
/** |
||||
* You can only choose one of the {@link #head(List)} and {@link #head(Class)} |
||||
* |
||||
* @param head |
||||
* @return |
||||
*/ |
||||
public T head(List<List<String>> head) { |
||||
parameter().setHead(head); |
||||
return self(); |
||||
} |
||||
|
||||
/** |
||||
* You can only choose one of the {@link #head(List)} and {@link #head(Class)} |
||||
* |
||||
* @param clazz |
||||
* @return |
||||
*/ |
||||
public T head(Class clazz) { |
||||
parameter().setClazz(clazz); |
||||
return self(); |
||||
} |
||||
|
||||
/** |
||||
* Custom type conversions override the default. |
||||
* |
||||
* @param converter |
||||
* @return |
||||
*/ |
||||
public T registerConverter(Converter converter) { |
||||
if (parameter().getCustomConverterList() == null) { |
||||
parameter().setCustomConverterList(new ArrayList<Converter>()); |
||||
} |
||||
parameter().getCustomConverterList().add(converter); |
||||
return self(); |
||||
} |
||||
|
||||
/** |
||||
* true if date uses 1904 windowing, or false if using 1900 date windowing. |
||||
* |
||||
* default is false |
||||
* |
||||
* @param use1904windowing |
||||
* @return |
||||
*/ |
||||
public T use1904windowing(Boolean use1904windowing) { |
||||
parameter().setUse1904windowing(use1904windowing); |
||||
return self(); |
||||
} |
||||
|
||||
/** |
||||
* A <code>Locale</code> object represents a specific geographical, political, or cultural region. This parameter is |
||||
* used when formatting dates and numbers. |
||||
* |
||||
* @param locale |
||||
* @return |
||||
*/ |
||||
public T locale(Locale locale) { |
||||
parameter().setLocale(locale); |
||||
return self(); |
||||
} |
||||
|
||||
/** |
||||
* Automatic trim includes sheet name and content |
||||
* |
||||
* @param autoTrim |
||||
* @return |
||||
*/ |
||||
public T autoTrim(Boolean autoTrim) { |
||||
parameter().setAutoTrim(autoTrim); |
||||
return self(); |
||||
} |
||||
|
||||
@SuppressWarnings("unchecked") |
||||
protected T self() { |
||||
return (T)this; |
||||
} |
||||
|
||||
protected abstract C parameter(); |
||||
} |
@ -0,0 +1,47 @@
|
||||
package com.alibaba.excel.read.builder; |
||||
|
||||
import java.util.ArrayList; |
||||
|
||||
import com.alibaba.excel.metadata.AbstractParameterBuilder; |
||||
import com.alibaba.excel.read.listener.ReadListener; |
||||
import com.alibaba.excel.read.metadata.ReadBasicParameter; |
||||
|
||||
/** |
||||
* Build ExcelBuilder |
||||
* |
||||
* @author Jiaju Zhuang |
||||
*/ |
||||
public abstract class AbstractExcelReaderParameterBuilder<T extends AbstractExcelReaderParameterBuilder, |
||||
C extends ReadBasicParameter> extends AbstractParameterBuilder<T, C> { |
||||
/** |
||||
* Count the number of added heads when read sheet. |
||||
* |
||||
* <p> |
||||
* 0 - This Sheet has no head ,since the first row are the data |
||||
* <p> |
||||
* 1 - This Sheet has one row head , this is the default |
||||
* <p> |
||||
* 2 - This Sheet has two row head ,since the third row is the data |
||||
* |
||||
* @param headRowNumber |
||||
* @return |
||||
*/ |
||||
public T headRowNumber(Integer headRowNumber) { |
||||
parameter().setHeadRowNumber(headRowNumber); |
||||
return self(); |
||||
} |
||||
|
||||
/** |
||||
* Custom type listener run after default |
||||
* |
||||
* @param readListener |
||||
* @return |
||||
*/ |
||||
public T registerReadListener(ReadListener readListener) { |
||||
if (parameter().getCustomReadListenerList() == null) { |
||||
parameter().setCustomReadListenerList(new ArrayList<ReadListener>()); |
||||
} |
||||
parameter().getCustomReadListenerList().add(readListener); |
||||
return self(); |
||||
} |
||||
} |
@ -1,14 +0,0 @@
|
||||
package com.alibaba.excel.util; |
||||
|
||||
/** |
||||
* Thread local cache in the current tool class. |
||||
* |
||||
* @author Jiaju Zhuang |
||||
**/ |
||||
public interface ThreadLocalCachedUtils { |
||||
|
||||
/** |
||||
* Remove remove thread local cached. |
||||
*/ |
||||
void removeThreadLocalCache(); |
||||
} |
@ -0,0 +1,104 @@
|
||||
package com.alibaba.excel.write.builder; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Collection; |
||||
|
||||
import com.alibaba.excel.metadata.AbstractParameterBuilder; |
||||
import com.alibaba.excel.write.handler.WriteHandler; |
||||
import com.alibaba.excel.write.metadata.WriteBasicParameter; |
||||
|
||||
/** |
||||
* Build ExcelBuilder |
||||
* |
||||
* @author Jiaju Zhuang |
||||
*/ |
||||
public abstract class AbstractExcelWriterParameterBuilder<T extends AbstractExcelWriterParameterBuilder, |
||||
C extends WriteBasicParameter> extends AbstractParameterBuilder<T, C> { |
||||
/** |
||||
* Writes the head relative to the existing contents of the sheet. Indexes are zero-based. |
||||
* |
||||
* @param relativeHeadRowIndex |
||||
* @return |
||||
*/ |
||||
public T relativeHeadRowIndex(Integer relativeHeadRowIndex) { |
||||
parameter().setRelativeHeadRowIndex(relativeHeadRowIndex); |
||||
return self(); |
||||
} |
||||
|
||||
/** |
||||
* Need Head |
||||
*/ |
||||
public T needHead(Boolean needHead) { |
||||
parameter().setNeedHead(needHead); |
||||
return self(); |
||||
} |
||||
|
||||
/** |
||||
* Custom write handler |
||||
* |
||||
* @param writeHandler |
||||
* @return |
||||
*/ |
||||
public T registerWriteHandler(WriteHandler writeHandler) { |
||||
if (parameter().getCustomWriteHandlerList() == null) { |
||||
parameter().setCustomWriteHandlerList(new ArrayList<WriteHandler>()); |
||||
} |
||||
parameter().getCustomWriteHandlerList().add(writeHandler); |
||||
return self(); |
||||
} |
||||
|
||||
/** |
||||
* Use the default style.Default is true. |
||||
* |
||||
* @param useDefaultStyle |
||||
* @return |
||||
*/ |
||||
public T useDefaultStyle(Boolean useDefaultStyle) { |
||||
parameter().setUseDefaultStyle(useDefaultStyle); |
||||
return self(); |
||||
} |
||||
|
||||
/** |
||||
* Whether to automatically merge headers.Default is true. |
||||
* |
||||
* @param automaticMergeHead |
||||
* @return |
||||
*/ |
||||
public T automaticMergeHead(Boolean automaticMergeHead) { |
||||
parameter().setAutomaticMergeHead(automaticMergeHead); |
||||
return self(); |
||||
} |
||||
|
||||
/** |
||||
* Ignore the custom columns. |
||||
*/ |
||||
public T excludeColumnIndexes(Collection<Integer> excludeColumnIndexes) { |
||||
parameter().setExcludeColumnIndexes(excludeColumnIndexes); |
||||
return self(); |
||||
} |
||||
|
||||
/** |
||||
* Ignore the custom columns. |
||||
*/ |
||||
public T excludeColumnFiledNames(Collection<String> excludeColumnFiledNames) { |
||||
parameter().setExcludeColumnFiledNames(excludeColumnFiledNames); |
||||
return self(); |
||||
} |
||||
|
||||
/** |
||||
* Only output the custom columns. |
||||
*/ |
||||
public T includeColumnIndexes(Collection<Integer> includeColumnIndexes) { |
||||
parameter().setIncludeColumnIndexes(includeColumnIndexes); |
||||
return self(); |
||||
} |
||||
|
||||
/** |
||||
* Only output the custom columns. |
||||
*/ |
||||
public T includeColumnFiledNames(Collection<String> includeColumnFiledNames) { |
||||
parameter().setIncludeColumnFiledNames(includeColumnFiledNames); |
||||
return self(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,15 @@
|
||||
package com.alibaba.easyexcel.test.temp.simple; |
||||
|
||||
import lombok.Data; |
||||
|
||||
/** |
||||
* TODO |
||||
* |
||||
* @author Jiaju Zhuang |
||||
**/ |
||||
@Data |
||||
public class JsonData { |
||||
private String SS1; |
||||
private String sS2; |
||||
private String ss3; |
||||
} |
@ -0,0 +1,13 @@
|
||||
package com.alibaba.easyexcel.test.temp.simple; |
||||
|
||||
import lombok.Data; |
||||
|
||||
/** |
||||
* write data |
||||
* |
||||
* @author Jiaju Zhuang |
||||
**/ |
||||
@Data |
||||
public class WriteData { |
||||
private float f; |
||||
} |
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue