diff options
| author | Dirk Fauth | 2023-02-22 13:23:42 +0000 |
|---|---|---|
| committer | Dirk Fauth | 2023-02-22 13:23:42 +0000 |
| commit | 27feb062e331c01513fe15c32738827ba075bf54 (patch) | |
| tree | 83f969d63b511159f678457eca70def591d87996 | |
| parent | e8a4a549ca4192d07ea599a47a27182b2289b865 (diff) | |
| download | org.eclipse.nebula.widgets.nattable-27feb062e331c01513fe15c32738827ba075bf54.tar.gz org.eclipse.nebula.widgets.nattable-27feb062e331c01513fe15c32738827ba075bf54.tar.xz org.eclipse.nebula.widgets.nattable-27feb062e331c01513fe15c32738827ba075bf54.zip | |
Bug 581562 - Numbers are not exported to Excel with the correct format
Added ExportConfigAttributes.NUMBER_FORMAT and modified the default
handling for Number values to avoid regressions.
Signed-off-by: Dirk Fauth <dirk.fauth@googlemail.com>
Change-Id: Ieee96d4ecea8e8cfe98dcd26a8f2ac6b2d57dde7
2 files changed, 11 insertions, 8 deletions
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/export/ExportConfigAttributes.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/export/ExportConfigAttributes.java index ee3d524d..dbb8edbd 100644 --- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/export/ExportConfigAttributes.java +++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/export/ExportConfigAttributes.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2020 Dirk Fauth and others. + * Copyright (c) 2013, 2023 Dirk Fauth and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -40,6 +40,13 @@ public final class ExportConfigAttributes { */ public static final ConfigAttribute<String> DATE_FORMAT = new ConfigAttribute<>(); /** + * The configuration attribute for specifying the format that should be used + * for exporting Number objects appropriately. + * + * @since 2.1 + */ + public static final ConfigAttribute<String> NUMBER_FORMAT = new ConfigAttribute<>(); + /** * The configuration attribute for specifying the concrete implementation * instance of ITableExporter that should be used for exporting the * NatTable. diff --git a/org.eclipse.nebula.widgets.nattable.extension.poi/src/org/eclipse/nebula/widgets/nattable/extension/poi/PoiExcelExporter.java b/org.eclipse.nebula.widgets.nattable.extension.poi/src/org/eclipse/nebula/widgets/nattable/extension/poi/PoiExcelExporter.java index a8fa7291..6dd4afe8 100644 --- a/org.eclipse.nebula.widgets.nattable.extension.poi/src/org/eclipse/nebula/widgets/nattable/extension/poi/PoiExcelExporter.java +++ b/org.eclipse.nebula.widgets.nattable.extension.poi/src/org/eclipse/nebula/widgets/nattable/extension/poi/PoiExcelExporter.java @@ -413,18 +413,14 @@ public abstract class PoiExcelExporter implements ILayerExporter { if (exportDisplayValue instanceof Calendar || exportDisplayValue instanceof Date) { dataFormat = getDataFormatString(cell, configRegistry); - } else { + } else if (exportDisplayValue instanceof Number) { dataFormat = configRegistry.getConfigAttribute( - ExportConfigAttributes.DATE_FORMAT, + ExportConfigAttributes.NUMBER_FORMAT, DisplayMode.NORMAL, cell.getConfigLabels()); if (dataFormat == null) { - if (exportDisplayValue instanceof Integer) { - return "0"; //$NON-NLS-1$ - } else if (exportDisplayValue instanceof Double) { - return "0.00"; //$NON-NLS-1$ - } + return (exportDisplayValue instanceof Double || exportDisplayValue instanceof Float) ? "0.00" : "0"; //$NON-NLS-1$//$NON-NLS-2$ } } |
