Versatile Grid Writer

The Versatile Grid Writer (VGW) is a Java Library that will export two-dimensional data into CSV or XML SpreedSheet files.

History

I struggled 6 month with Apache POI library to export my data into Excel. The problem was my data volume of approx. 1 million rows and 100 columns. It turns out that this library was not build for, even for smaller files it eats up to 120 GB ram for a 10 MB size Excel file. That wasn’t that good … wasted time.

So i decide to write my own library. I already take a look into existing libraries, but they aren’t fit to my requirements.

Function

The VGW split the data from the styles and header. They are combined in time by the export itself. This ensures that all exports are consistent by writing different formats and without rewriting the structure.

Example

There is an Exampleclass inside the Unit-Tests, and here the result of the example_01 as CSV file:

Example 01 - CSV - Text Example 01 - CSV - Excel

Same for Excel:

Example 01 - XML - Text

And here is the code:

package net.whurst.util.vgw;

import org.junit.jupiter.api.Test;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.nio.charset.StandardCharsets;

import static org.junit.jupiter.api.Assertions.*;

public class Examples {

	@Test
	void example_01 () {

		int groupIndex;
		Header header = new Header ();
		GridData gridData = new GridData ();
		Style columnStyle;

		// Header definieren mit allen Styles, Farben und Fonts und allem
		Style titleStyle = new Style ();
		titleStyle.setBackgroundColor (280.0/360.0, 0.05, 1.0);
		titleStyle.setBorderBottom (true);
		titleStyle.setFontName (Style.FONT_NAME.ARIAL);
		titleStyle.setFontSize (14);
		titleStyle.setFontBold (true);
		titleStyle.setIndent (3);
		titleStyle.setVerticalAlignment (Style.VERTICAL_ALIGNMENT.MIDDLE);
		header.setTitle ("Example 01 - Devices And Interfaces", titleStyle);

		// Wir setzen für alle Gruppen Header die Defaults
		Style groupHeaderStyle = new Style ();
		groupHeaderStyle.setHorizontalAlignment (Style.HORIZONTAL_ALIGNMENT.CENTER);
		groupHeaderStyle.setFontName (Style.FONT_NAME.CALIBRI);
		groupHeaderStyle.setFontSize (14);
		groupHeaderStyle.setFontBold (true);
		header.setGroupHeaderParentStyle (groupHeaderStyle);

		// Wir setzen für alle Spalten Header die Defaults
		Style columnHeaderStyle = new Style ();
		columnHeaderStyle.setHorizontalAlignment (Style.HORIZONTAL_ALIGNMENT.LEFT);
		columnHeaderStyle.setBorderBottom (true);
		columnHeaderStyle.setFontSize (11);
		columnHeaderStyle.setFontBold (true);
		header.setColumnHeaderParentStyle (columnHeaderStyle);

		// Wir setzen für alle Spalten die Defaults
		Style dataStyle = new Style ();
		dataStyle.setHorizontalAlignment (Style.HORIZONTAL_ALIGNMENT.LEFT);
		dataStyle.setFontName (Style.FONT_NAME.CALIBRI);
		dataStyle.setFontSize (11);
		dataStyle.setFontBold (false);
		header.setGroupDataParentStyle (dataStyle);

		groupHeaderStyle = new Style ();
		groupHeaderStyle.setBackgroundColor (0.1, 0.2, 1.0);

		columnStyle = new Style ();
		columnStyle.setBackgroundColor (0.1, 0.1, 1.0);

		groupIndex = header.addGroup ("DEVICE", "Device", groupHeaderStyle, columnStyle);
		header.addColumn (groupIndex, "NAME", "Name", null, null);
		header.addColumn (groupIndex, "TYPE", "Type", null, null);

		groupHeaderStyle = new Style ();
		groupHeaderStyle.setBackgroundColor (0.2, 0.2, 1.0);

		columnStyle = new Style ();
		columnStyle.setBackgroundColor (0.2, 0.1, 1.0);

		groupIndex = header.addGroup ("INTERFACE", "Interface Data", groupHeaderStyle, columnStyle);
		header.addColumn (groupIndex, "DESC", "Description", null, null);
		header.addColumn (groupIndex, "SPEED", "Speed", null, null);
		header.addColumn (groupIndex, "STATE", "Status", null, null);

		// Phantasie Daten erstellen
		gridData.addCell ("MERKUR"); gridData.addCell ("Linux"); gridData.addCell ("eno1");
		gridData.addCell ("10000"); gridData.addCell ("UP/UP"); gridData.nextLine ();

		gridData.addCell ("MERKUR"); gridData.addCell ("Linux"); gridData.addCell ("eno2");
		gridData.addCell ("10000"); gridData.addCell ("UP/down"); gridData.nextLine ();

		gridData.addCell ("MERKUR"); gridData.addCell ("Linux"); gridData.addCell ("eno3");
		gridData.addCell ("0"); gridData.addCell ("down/down"); gridData.nextLine ();

		gridData.addCell ("NEPTUN"); gridData.addCell ("FreeBSD"); gridData.addCell ("fpx0");
		gridData.addCell ("1000"); gridData.addCell ("down/UP"); gridData.nextLine ();

		gridData.addCell ("NEPTUN"); gridData.addCell ("FreeBSD"); gridData.addCell ("fpx1");
		gridData.addCell ("1000"); gridData.addCell ("UP/UP"); gridData.nextLine ();

		gridData.addCell ("PLUTO"); gridData.addCell ("FreeBSD"); gridData.addCell ("fpx0");
		gridData.addCell ("1000"); gridData.addCell ("UP/UP"); gridData.nextLine ();

		gridData.addCell ("GECKO"); gridData.addCell ("Windows 10"); gridData.addCell ("lan0");
		gridData.addCell ("10000"); gridData.addCell ("UP/UP"); gridData.nextLine ();

		gridData.addCell ("GECKO"); gridData.addCell ("Windows 10"); gridData.addCell ("wlan0");
		gridData.addCell ("155"); gridData.addCell ("UP/UP"); gridData.nextLine ();

		gridData.addCell ("FALCON"); gridData.addCell ("QNAP"); gridData.addCell ("eth0");
		gridData.addCell ("1000"); gridData.addCell ("UP/UP"); gridData.nextLine ();

		// XML konfigurieren
		ConfigurationXml configurationXml = new ConfigurationXml ();
		configurationXml.setSheetName ("InterfaceList");
		configurationXml.setGenerateGroupHeaderBorderOnly (true);

		// CSV konfigurieren
		ConfigurationCsv configurationCsv = new ConfigurationCsv ();

		// Jetzt die Dateien schreiben
		try {
			File tempDir = new File ("temp");
			tempDir.mkdir ();

			FileOutputStream fileOutputStreamXML = new FileOutputStream ("temp/example_01.xml");
			Writer.write (configurationXml, header, gridData, fileOutputStreamXML);

			FileOutputStream fileOutputStreamCSV = new FileOutputStream ("temp/example_01.csv");
			Writer.write (configurationCsv, header, gridData, fileOutputStreamCSV);

			assertTrue (true);

		} catch (Exception e) {
			fail (e.getLocalizedMessage ());
		}
	}
}

Downloads

The tar file contain JAR, JavaDocs, all Unit-Tests and examples, there is also a detail documentation, but I didn’t found the time now to make it full-featured-ultra-awesome.

Version main-20221029081207

First Release, Production Version

Download VGW Production Version - 20221029081207

Version main-20231003022321

Bugfixes, CellStyles, CellLinks

Download VGW Production Version - 20231003022321