Package com.atlan.samples.writers
Class ExcelWriter
- java.lang.Object
-
- com.atlan.samples.writers.ExcelWriter
-
public class ExcelWriter extends java.lang.ObjectUtility class for creating and writing to Excel files, using Apache POI.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classExcelWriter.DataCell
-
Constructor Summary
Constructors Constructor Description ExcelWriter(int batch)Construct a new Excel file writer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDataCell(org.apache.poi.ss.usermodel.Row row, int index, boolean value)Add a data cell with a boolean value.voidaddDataCell(org.apache.poi.ss.usermodel.Row row, int index, double value)Add a data cell with a numeric value.voidaddDataCell(org.apache.poi.ss.usermodel.Row row, int index, long value)Add a data cell with a numeric value.voidaddDataCell(org.apache.poi.ss.usermodel.Row row, int index, java.lang.String value)Add a data cell with a string value.voidaddHeader(org.apache.poi.ss.usermodel.Sheet worksheet, java.util.Map<java.lang.String,java.lang.String> headers)Create a header row for the worksheet.voidaddHeaderCell(org.apache.poi.ss.usermodel.Row header, int index, java.lang.String name, java.lang.String description)Add a header cell to the worksheet.voidappendRow(org.apache.poi.ss.usermodel.Sheet worksheet, java.util.List<ExcelWriter.DataCell> data)Add a row of data to the end of a worksheet.java.io.ByteArrayOutputStreamasByteArray()Flush out the contents of the workbook to a ByteArrayOutputStream.voidcreate(java.lang.String fileLocation)Flush out the contents of the workbook to a file, creating the XLSX file.org.apache.poi.ss.usermodel.SheetcreateSheet(java.lang.String name)Create a new worksheet within the workbook.
-
-
-
Method Detail
-
createSheet
public org.apache.poi.ss.usermodel.Sheet createSheet(java.lang.String name)
Create a new worksheet within the workbook.- Parameters:
name- of the sheet to create- Returns:
- the worksheet
-
create
public void create(java.lang.String fileLocation) throws java.io.IOExceptionFlush out the contents of the workbook to a file, creating the XLSX file.- Parameters:
fileLocation- location of the Excel file to create- Throws:
java.io.IOException- on any errors creating or accessing the file
-
asByteArray
public java.io.ByteArrayOutputStream asByteArray() throws java.io.IOExceptionFlush out the contents of the workbook to a ByteArrayOutputStream.- Returns:
- the contents of the workbook as an output stream of bytes
- Throws:
java.io.IOException- on any errors creating or writing to the byte array output stream
-
addHeader
public void addHeader(org.apache.poi.ss.usermodel.Sheet worksheet, java.util.Map<java.lang.String,java.lang.String> headers)Create a header row for the worksheet.- Parameters:
worksheet- in which to create the header rowheaders- ordered map of header names and descriptions
-
appendRow
public void appendRow(org.apache.poi.ss.usermodel.Sheet worksheet, java.util.List<ExcelWriter.DataCell> data)Add a row of data to the end of a worksheet.- Parameters:
worksheet- the worksheet into which to add the rowdata- the row of data to add
-
addHeaderCell
public void addHeaderCell(org.apache.poi.ss.usermodel.Row header, int index, java.lang.String name, java.lang.String description)Add a header cell to the worksheet.- Parameters:
header- row for the headerindex- location of the cell (column index)name- of the header columndescription- of the header column (will be put into a comment)
-
addDataCell
public void addDataCell(org.apache.poi.ss.usermodel.Row row, int index, java.lang.String value)Add a data cell with a string value.- Parameters:
row- in which to add the cellindex- column for the cellvalue- to set for the cell
-
addDataCell
public void addDataCell(org.apache.poi.ss.usermodel.Row row, int index, boolean value)Add a data cell with a boolean value.- Parameters:
row- in which to add the cellindex- column for the cellvalue- to set for the cell
-
addDataCell
public void addDataCell(org.apache.poi.ss.usermodel.Row row, int index, long value)Add a data cell with a numeric value.- Parameters:
row- in which to add the cellindex- column for the cellvalue- to set for the cell
-
addDataCell
public void addDataCell(org.apache.poi.ss.usermodel.Row row, int index, double value)Add a data cell with a numeric value.- Parameters:
row- in which to add the cellindex- column for the cellvalue- to set for the cell
-
-