-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Impl #111 - [Export] Add support for exporting to XLSX
- Loading branch information
Showing
12 changed files
with
145 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file renamed
BIN
+364 KB
...g.apache.commons.commons-codec_1.17.0.jar → ...g.apache.commons.commons-codec_1.17.1.jar
Binary file not shown.
Binary file added
BIN
+1.03 MB
...lipse.nebula.widgets.nattable.examples/lib/org.apache.commons.commons-compress_1.26.2.jar
Binary file not shown.
Binary file removed
BIN
-643 KB
org.eclipse.nebula.widgets.nattable.examples/lib/org.apache.commons.lang3_3.14.0.jar
Binary file not shown.
Binary file added
BIN
+655 KB
org.eclipse.nebula.widgets.nattable.examples/lib/org.apache.commons.lang3_3.15.0.jar
Binary file not shown.
Binary file added
BIN
+6.16 MB
...ebula.widgets.nattable.examples/lib/org.apache.poi.ooxml.schemas_5.3.0.v20240703-1000.jar
Binary file not shown.
Binary file added
BIN
+2.04 MB
...clipse.nebula.widgets.nattable.examples/lib/org.apache.poi.ooxml_5.3.0.v20240703-1000.jar
Binary file not shown.
Binary file added
BIN
+2.27 MB
...eclipse.nebula.widgets.nattable.examples/lib/org.apache.xmlbeans_5.2.1.v20240527-0800.jar
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...xtension.poi/src/org/eclipse/nebula/widgets/nattable/extension/poi/XSSFExcelExporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Dirk Fauth. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Dirk Fauth <dirk.fauth@googlemail.com> - initial API and implementation | ||
******************************************************************************/ | ||
package org.eclipse.nebula.widgets.nattable.extension.poi; | ||
|
||
import java.util.HashMap; | ||
|
||
import org.apache.poi.ss.usermodel.CellStyle; | ||
import org.apache.poi.ss.usermodel.Font; | ||
import org.apache.poi.ss.usermodel.Workbook; | ||
import org.apache.poi.xssf.usermodel.XSSFColor; | ||
import org.apache.poi.xssf.usermodel.XSSFFont; | ||
import org.apache.poi.xssf.usermodel.XSSFWorkbook; | ||
import org.eclipse.nebula.widgets.nattable.export.FileOutputStreamProvider; | ||
import org.eclipse.nebula.widgets.nattable.export.IOutputStreamProvider; | ||
import org.eclipse.swt.graphics.Color; | ||
|
||
public class XSSFExcelExporter extends PoiExcelExporter { | ||
|
||
private HashMap<Color, XSSFColor> colorIndex = new HashMap<>(); | ||
|
||
public XSSFExcelExporter() { | ||
super(new FileOutputStreamProvider("table_export.xlsx", new String[] { "Excel Workbook (*.xlsx)" }, new String[] { "*.xlsx" })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | ||
} | ||
|
||
public XSSFExcelExporter(IOutputStreamProvider outputStreamProvider) { | ||
super(outputStreamProvider); | ||
} | ||
|
||
@Override | ||
protected Workbook createWorkbook() { | ||
this.colorIndex = new HashMap<>(); | ||
return new XSSFWorkbook(); | ||
} | ||
|
||
@Override | ||
protected void setFillForegroundColor(CellStyle xlCellStyle, Color swtColor) { | ||
xlCellStyle.setFillForegroundColor(getColor(swtColor)); | ||
} | ||
|
||
@Override | ||
protected void setFontColor(Font xlFont, Color swtColor) { | ||
((XSSFFont) xlFont).setColor(getColor(swtColor)); | ||
} | ||
|
||
private XSSFColor getColor(Color swtColor) { | ||
return this.colorIndex.computeIfAbsent(swtColor, c -> { | ||
byte[] rgb = { | ||
(byte) swtColor.getRed(), | ||
(byte) swtColor.getGreen(), | ||
(byte) swtColor.getBlue() | ||
}; | ||
XSSFColor xc = new XSSFColor(rgb, null); | ||
return xc; | ||
}); | ||
} | ||
|
||
} |