Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions example/data/input/transactions_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
[
{
"transactionId": 1001,
"customerName": "Alice Johnson",
"category": "Refund",
"amount": -120.5,
"transactionDate": "2025-01-05"
},
{
"transactionId": 1002,
"customerName": "Bob Smith",
"category": "Purchase",
"amount": 250.0,
"transactionDate": "2025-01-06"
},
{
"transactionId": 1003,
"customerName": "Charlie Brown",
"category": "Refund",
"amount": -75.0,
"transactionDate": "2025-01-07"
},
{
"transactionId": 1004,
"customerName": "Diana Prince",
"category": "Purchase",
"amount": 430.25,
"transactionDate": "2025-01-08"
},
{
"transactionId": 1005,
"customerName": "Ethan Hunt",
"category": "Refund",
"amount": -60.0,
"transactionDate": "2025-01-09"
},
{
"transactionId": 1006,
"customerName": "Fiona Lee",
"category": "Purchase",
"amount": 180.75,
"transactionDate": "2025-01-10"
},
{
"transactionId": 1007,
"customerName": "George Miller",
"category": "Refund",
"amount": -200.0,
"transactionDate": "2025-01-11"
},
{
"transactionId": 1008,
"customerName": "Hannah Kim",
"category": "Purchase",
"amount": 95.0,
"transactionDate": "2025-01-12"
},
{
"transactionId": 1009,
"customerName": "Ian Wright",
"category": "Refund",
"amount": -45.99,
"transactionDate": "2025-01-13"
},
{
"transactionId": 1010,
"customerName": "Julia Roberts",
"category": "Purchase",
"amount": 320.4,
"transactionDate": "2025-01-14"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.northconcepts.datapipeline.examples.cookbook;

import java.io.File;

import com.northconcepts.datapipeline.core.DataReader;
import com.northconcepts.datapipeline.core.StreamWriter;
import com.northconcepts.datapipeline.excel.ExcelDocument;
import com.northconcepts.datapipeline.excel.ExcelDocument.ProviderType;
import com.northconcepts.datapipeline.excel.ExcelReader;
import com.northconcepts.datapipeline.job.Job;

public class ReadExcelFormattingAndStyles {

public static void main(String[] args) throws Throwable {
ExcelDocument document = new ExcelDocument(ProviderType.POI_XSSF_SAX)
.open(new File("example/data/input/transactions-with-formatting-and-styles.xlsx"));
DataReader reader = new ExcelReader(document)
.setAutoCloseDocument(true)
.setFieldNamesInFirstRow(true)
.setReadMetadata(true); // only read excel cell styles if this flag is true

// read from excel and write all excel records & cell styles on console.
Job.run(reader, new StreamWriter(System.out).setFormat(StreamWriter.Format.RECORD_WITH_SESSION_PROPERTIES));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.northconcepts.datapipeline.examples.cookbook;

import java.io.File;

import com.northconcepts.datapipeline.core.DataReader;
import com.northconcepts.datapipeline.core.FieldLocationPredicate;
import com.northconcepts.datapipeline.excel.ExcelCellStyleDecorator;
import com.northconcepts.datapipeline.excel.ExcelColorPalette;
import com.northconcepts.datapipeline.excel.ExcelDocument;
import com.northconcepts.datapipeline.excel.ExcelWriter;
import com.northconcepts.datapipeline.job.Job;
import com.northconcepts.datapipeline.json.JsonRecordReader;

public class WriteExcelFormattingAndStyles {

public static void main(String[] args) {
DataReader reader = new JsonRecordReader(new File("example/data/input/transactions_data.json"))
.addRecordBreak("/array/object");

ExcelDocument document = new ExcelDocument();
ExcelWriter writer = new ExcelWriter(document)
.setSheetName("transactions")
.setAutofitColumns(true);

// Add Formatting & Cell Style for Header
writer.addHeaderCellStyle(FieldLocationPredicate.all(), ExcelCellStyleDecorator.bold()
.and(ExcelCellStyleDecorator.backgroundColor(ExcelColorPalette.DARK_YELLOW))
.and(ExcelCellStyleDecorator.fontColor(ExcelColorPalette.LIGHT_GREEN))
);

// Add Formatting & Cell Style for Data
writer.addDataCellStyle(FieldLocationPredicate.negativeNumber(), ExcelCellStyleDecorator.fontColor(ExcelColorPalette.RED)
.and(ExcelCellStyleDecorator.italic()));
writer.addDataCellStyle(FieldLocationPredicate.evenRowIndex(), ExcelCellStyleDecorator.backgroundColor(ExcelColorPalette.GREY_25_PERCENT));

Job.run(reader, writer);

document.save(new File("example/data/output/transactions-with-formatting-and-styles.xlsx"));
}

}