Skip to content

Conversation

HarshaM0211
Copy link

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.

boolean isFormatted() default false;
String format() default "dd/MM/yyyy";

boolean isFromula() default false;

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);

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");
}

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;

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

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;

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;

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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final ?

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);

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();
Copy link

@VyshnaviRG VyshnaviRG Oct 4, 2023

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

Field[] fields = beanType.getDeclaredFields();
final Field[] fields = beanType.getDeclaredFields();
for (Field f : fields) {
String fieldName = f.getName();

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>();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final ?

@HarshaM0211 HarshaM0211 reopened this Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants