Skip to content

Commit

Permalink
flush out data target examples more
Browse files Browse the repository at this point in the history
  • Loading branch information
mdavis95 committed Sep 5, 2024
1 parent a79ebe8 commit b661d51
Showing 1 changed file with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package io.zulia.data.test;

import io.zulia.data.output.FileDataOutputStream;
import io.zulia.data.target.spreadsheet.SpreadsheetTarget;
import io.zulia.data.target.spreadsheet.SpreadsheetTargetFactory;
import io.zulia.data.target.spreadsheet.csv.CSVTarget;
import io.zulia.data.target.spreadsheet.excel.ExcelTarget;
import io.zulia.data.target.spreadsheet.excel.ExcelTargetConfig;
import io.zulia.data.target.spreadsheet.excel.cell.Link;

import java.io.IOException;
Expand All @@ -13,16 +15,49 @@

public class DataTargetExamples {

public static void main(String[] args) throws IOException {

public void csvTarget() throws IOException {
List<String> headers = List.of("string column", "number", "decimal number", "boolean column", "list column", "link column", "some date");
try (CSVTarget csvTarget = CSVTarget.withDefaultsFromFile("/data/test.csv", true, headers)) {
try (CSVTarget csvTarget = CSVTarget.withDefaultsFromFile("/data/test.xlsx", true, headers)) {
writeSampleRecords(csvTarget);
}
try (ExcelTarget excelTarget = ExcelTarget.withDefaultsFromFile("/data/test.xlsx", true, headers)) {
}

public void excelTarget() throws IOException {
List<String> headers = List.of("string column", "number", "decimal number", "boolean column", "list column", "link column", "some date");
try (ExcelTarget excelTarget = ExcelTarget.withDefaultsFromFile("/data/testA.xlsx", true, headers)) {
writeSampleRecords(excelTarget);
}

ExcelTargetConfig excelTargetConfig = ExcelTargetConfig.from(FileDataOutputStream.from("/data/testB.xlsx", true));

// optionally set a type handler on the config to handle Dates, Numbers, Strings, Links, ... differently

excelTargetConfig.withPrimarySheetName("Results");
excelTargetConfig.withHeaders(List.of("Title", "Description", "Added"));
try (ExcelTarget excelTarget = ExcelTarget.withConfig(excelTargetConfig)) {
excelTarget.writeRow("some title", "some description", new Date());
excelTarget.writeRow("some title 2", "some description 2", new Date());

excelTarget.newSheet("Other Stuff", List.of("Id", "Year", "Author"));
excelTarget.writeRow("1234", 2010, "John Doe");
excelTarget.writeRow("456", 2011, "Jane Doe");

excelTarget.newSheet("Even More Stuff");
excelTarget.appendValue(1);
excelTarget.appendValue("Lion");
excelTarget.finishRow();

excelTarget.appendValue(2);
excelTarget.appendValue("Tigers");
excelTarget.finishRow();

excelTarget.appendValue(3);
excelTarget.appendValue("Bears");
excelTarget.finishRow();
}
}

public void genericTarget() throws IOException {
try (SpreadsheetTarget<?, ?> spreadsheetTarget = SpreadsheetTargetFactory.fromFile("/data/test2.xlsx", true)) {
writeSampleRecords(spreadsheetTarget);
}
Expand All @@ -31,10 +66,9 @@ public static void main(String[] args) throws IOException {
List.of("header1", "header2"))) {
writeSampleRecords(spreadsheetTarget);
}

}

private static void writeSampleRecords(SpreadsheetTarget<?, ?> spreadsheetTarget) {
public void writeSampleRecords(SpreadsheetTarget<?, ?> spreadsheetTarget) {
spreadsheetTarget.appendValue("some string");
spreadsheetTarget.appendValue(132);
spreadsheetTarget.appendValue(10.332443f);
Expand Down

0 comments on commit b661d51

Please sign in to comment.