Browse Source

修改合并报错

developing
Jiaju Zhuang 3 years ago
parent
commit
16f7f53eb3
  1. 7
      src/main/java/com/alibaba/excel/metadata/csv/CsvSheet.java
  2. 7
      src/main/java/com/alibaba/excel/util/NumberDataFormatterUtils.java

7
src/main/java/com/alibaba/excel/metadata/csv/CsvSheet.java

@ -2,6 +2,7 @@ package com.alibaba.excel.metadata.csv;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -768,8 +769,8 @@ public class CsvSheet implements Sheet, Closeable {
if (dataFormatString == null) { if (dataFormatString == null) {
dataFormatString = csvWorkbook.createDataFormat().getFormat(dataFormat); dataFormatString = csvWorkbook.createDataFormat().getFormat(dataFormat);
} }
return NumberDataFormatterUtils.format( return NumberDataFormatterUtils.format(BigDecimal.valueOf(
DateUtil.getExcelDate(csvCell.getDateValue(), csvWorkbook.getUse1904windowing()), DateUtil.getExcelDate(csvCell.getDateValue(), csvWorkbook.getUse1904windowing())),
dataFormat, dataFormatString, csvWorkbook.getUse1904windowing(), csvWorkbook.getLocale(), dataFormat, dataFormatString, csvWorkbook.getUse1904windowing(), csvWorkbook.getLocale(),
csvWorkbook.getUseScientificFormat()); csvWorkbook.getUseScientificFormat());
} else { } else {
@ -784,7 +785,7 @@ public class CsvSheet implements Sheet, Closeable {
if (dataFormatString == null) { if (dataFormatString == null) {
dataFormatString = csvWorkbook.createDataFormat().getFormat(dataFormat); dataFormatString = csvWorkbook.createDataFormat().getFormat(dataFormat);
} }
return NumberDataFormatterUtils.format(csvCell.getNumericCellValue(), dataFormat, dataFormatString, return NumberDataFormatterUtils.format(csvCell.getNumberValue(), dataFormat, dataFormatString,
csvWorkbook.getUse1904windowing(), csvWorkbook.getLocale(), csvWorkbook.getUse1904windowing(), csvWorkbook.getLocale(),
csvWorkbook.getUseScientificFormat()); csvWorkbook.getUseScientificFormat());
} }

7
src/main/java/com/alibaba/excel/util/NumberDataFormatterUtils.java

@ -1,11 +1,10 @@
package com.alibaba.excel.util; package com.alibaba.excel.util;
import java.util.Locale;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Locale;
import com.alibaba.excel.metadata.format.DataFormatter;
import com.alibaba.excel.metadata.GlobalConfiguration; import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.format.DataFormatter;
/** /**
* Convert number data, including date. * Convert number data, including date.
@ -48,7 +47,7 @@ public class NumberDataFormatterUtils {
* @param useScientificFormat * @param useScientificFormat
* @return * @return
*/ */
public static String format(Double data, Short dataFormat, String dataFormatString, Boolean use1904windowing, public static String format(BigDecimal data, Short dataFormat, String dataFormatString, Boolean use1904windowing,
Locale locale, Boolean useScientificFormat) { Locale locale, Boolean useScientificFormat) {
DataFormatter dataFormatter = DATA_FORMATTER_THREAD_LOCAL.get(); DataFormatter dataFormatter = DATA_FORMATTER_THREAD_LOCAL.get();
if (dataFormatter == null) { if (dataFormatter == null) {

Loading…
Cancel
Save