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
Binary file added example/data/input/product_list.xlsx
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.northconcepts.datapipeline.examples.cookbook;

import java.io.File;

import com.northconcepts.datapipeline.core.DataReader;
import com.northconcepts.datapipeline.core.DataWriter;
import com.northconcepts.datapipeline.core.Field;
import com.northconcepts.datapipeline.core.ProxyReader;
import com.northconcepts.datapipeline.core.Record;
import com.northconcepts.datapipeline.csv.CSVWriter;
import com.northconcepts.datapipeline.excel.ExcelDocument;
import com.northconcepts.datapipeline.excel.ExcelDocument.ProviderType;
import com.northconcepts.datapipeline.excel.ExcelFieldMetadata;
import com.northconcepts.datapipeline.excel.ExcelHyperlink;
import com.northconcepts.datapipeline.excel.ExcelReader;
import com.northconcepts.datapipeline.job.Job;

public class ReadHyperlinksFromExcel {

private static File INPUT_FILE = new File("example/data/input", "product_list.xlsx");
private static File OUTPUT_FILE = new File("example/data/output", "product_list.csv");

public static void main(String[] args) {
ExcelDocument document = new ExcelDocument(ProviderType.POI_XSSF_SAX)
.open(INPUT_FILE);
DataReader reader = new ExcelReader(document)
.setFieldNamesInFirstRow(true)
.setAutoCloseDocument(true)
.setReadMetadata(true);

reader = new ExcelHyperlinkReader(reader);

DataWriter writer = new CSVWriter(OUTPUT_FILE);

Job.run(reader, writer);
}
}

class ExcelHyperlinkReader extends ProxyReader {

private ExcelFieldMetadata metadata = new ExcelFieldMetadata();

public ExcelHyperlinkReader(DataReader dataReader) {
super(dataReader);
}

@Override
protected Record interceptRecord(Record record) throws Throwable {
Field field = record.getField("product_name");
metadata.setField(field);

ExcelHyperlink excelHyperlink = metadata.getExcelHyperlink();
record.addField("product_link", excelHyperlink == null ? null : excelHyperlink.getLocation());

return super.interceptRecord(record);
}

}