-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhanced to read and write formatted dates and formulas. #48
base: develop
Are you sure you want to change the base?
Conversation
boolean isFormatted() default false; | ||
String format() default "dd/MM/yyyy"; | ||
|
||
boolean isFromula() default false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct formula spelling
if (DateUtil.isCellDateFormatted(cell)) { | ||
|
||
Map<String, String> formats = SpreadsheetWriter.getFormats(beanClz); | ||
String cellFormat = formats.get(cellColName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final ?
} else { | ||
formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
store default format as const..
Also, Can be written as
final String format = cellFormat != null ? cellFormat : defaultFormat; DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
@@ -0,0 +1,263 @@ | |||
package io.github.millij.poi.ss.reader; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for filename change ??
@Override | ||
public <T> void read(Class<T> beanClz, InputStream is, int sheetNo, RowListener<T> listener) | ||
throws SpreadsheetReadException { | ||
// Sanity checks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Format code
import org.apache.poi.ss.usermodel.DateUtil; | ||
import org.apache.poi.ss.usermodel.Row; | ||
import org.apache.poi.ss.usermodel.Workbook; | ||
// import org.apache.poi.util.SAXHelper; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the comment
// import io.github.millij.bean.Schedules; | ||
import io.github.millij.poi.ss.writer.SpreadsheetWriter; | ||
|
||
// import io.github.millij.bean.Schedules; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove Commented imports
mapping.put(fieldName, ec.value()); | ||
|
||
if (ec != null) { | ||
String value = StringUtils.isNotEmpty(ec.value()) ? ec.value() : fieldName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final ?
@@ -119,12 +126,45 @@ public <EB> void addSheet(Class<EB> beanType, List<EB> rowObjects, List<String> | |||
for (int i = 0, rowNum = 1; i < rowObjects.size(); i++, rowNum++) { | |||
final XSSFRow row = sheet.createRow(rowNum); | |||
|
|||
final Map<String, String> dateFormatsMap = this.getFormats(beanType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move outside of for loop
cellNo++; | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use LOGGER to display exceptions
… prev. sheets--issue 24" This reverts commit 78995e4. reverting updates
@@ -56,28 +58,28 @@ public static Map<String, String> getPropertyToColumnNameMap(Class<?> beanType) | |||
final Map<String, String> mapping = new HashMap<String, String>(); | |||
|
|||
// Fields | |||
Field[] fields = beanType.getDeclaredFields(); | |||
final Field[] fields = beanType.getDeclaredFields(); | |||
for (Field f : fields) { | |||
String fieldName = f.getName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[PP] make the string final
.
@Test | ||
public void writeDatesTest() throws IOException { | ||
|
||
List<Schedule> schedules = new ArrayList<Schedule>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final
?
Modified entire XlsxReader.java file:
Replaced HSSF in XlsReader.java with XSSF everywhere and did the same logics.
Created two new methods "getFormats()" and "getFormulaCols" to store data about the columns that have to be date formatted and containing formulas.
Modified @SheetColumn
Added files and some modified data for Test cases.