Class XlsxTemplate
java.lang.Object
net.sf.basedb.clients.web.plugins.XlsxTemplate
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ExportTemplate
public class XlsxTemplate extends Object implements ExportTemplate
Template implementation that exports data to Excel format (xlsx).
- Since:
- 3.15
- Author:
- nicklas
-
Field Summary
Fields Modifier and Type Field Description private String
collectionSeparator
private int
colNum
private org.apache.poi.ss.usermodel.Row
currentRow
private OutputStream
out
private List<ExportedProperty>
properties
private int
rowNum
private org.apache.poi.ss.usermodel.Sheet
sheet
private CellStyleCreator
styleCreator
private org.apache.poi.ss.usermodel.Workbook
workbook
-
Constructor Summary
Constructors Constructor Description XlsxTemplate(OutputStream out, List<ExportedProperty> properties, Item itemType, long numItems, String collectionSeparator)
Create a new template. -
Method Summary
Modifier and Type Method Description void
beginDocument()
Reset row and column to 0.void
beginItem(int id)
Reset column number and create a new row.void
close()
Dispose and close workbook.void
endDocument(ProgressReporter progress)
Write the Excel workbook to the output stream and close.void
endItem()
Do nothing.String
getDefaultFileExtension()
Get the default file extension to give to files generated by this template.String
getMimeType()
Get the MIME type to assign to files generated by this template.void
writeAnnotations(ExportedProperty ep, List<?> values, String unit)
Join the annotation values into a single string with a comma.void
writeCollection(ExportedProperty ep, Collection<?> values)
Writes a collection of values.void
writeHeaders()
Write the headers on a single row.void
writeProperty(ExportedProperty ep, Object data)
Write the data object.
-
Field Details
-
out
-
properties
-
colNum
private int colNum -
rowNum
private int rowNum -
collectionSeparator
-
workbook
private final org.apache.poi.ss.usermodel.Workbook workbook -
sheet
private final org.apache.poi.ss.usermodel.Sheet sheet -
styleCreator
-
currentRow
private org.apache.poi.ss.usermodel.Row currentRow
-
-
Constructor Details
-
XlsxTemplate
public XlsxTemplate(OutputStream out, List<ExportedProperty> properties, Item itemType, long numItems, String collectionSeparator)Create a new template.- Parameters:
out
- The stream to write toproperties
- All exported propertiesitemType
- The type of items we are exporting
-
-
Method Details
-
getMimeType
Description copied from interface:ExportTemplate
Get the MIME type to assign to files generated by this template.- Specified by:
getMimeType
in interfaceExportTemplate
- Returns:
- application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
-
getDefaultFileExtension
Description copied from interface:ExportTemplate
Get the default file extension to give to files generated by this template.- Specified by:
getDefaultFileExtension
in interfaceExportTemplate
- Returns:
- Always "xlsx"
-
beginDocument
Reset row and column to 0.- Specified by:
beginDocument
in interfaceExportTemplate
- Throws:
IOException
- If there is an error
-
writeHeaders
Write the headers on a single row.- Specified by:
writeHeaders
in interfaceExportTemplate
- Throws:
IOException
- If there is an error
-
beginItem
Reset column number and create a new row.- Specified by:
beginItem
in interfaceExportTemplate
- Parameters:
id
- Id of the new item.- Throws:
IOException
- If there is an error
-
writeAnnotations
Join the annotation values into a single string with a comma.- Specified by:
writeAnnotations
in interfaceExportTemplate
- Parameters:
ep
- Exported property the annotations belongs tovalues
- Annotation values to be written.unit
- The unit of the annotation values, or null to not display write a unit- Throws:
IOException
- If there is an error
-
writeProperty
Write the data object.- Specified by:
writeProperty
in interfaceExportTemplate
- Parameters:
ep
- The exported property thedata
belongs to.data
- Data to be written.- Throws:
IOException
- If there is an error
-
writeCollection
Writes a collection of values.- Specified by:
writeCollection
in interfaceExportTemplate
- Parameters:
ep
- Exported property the values belong tovalues
- The values to be written- Throws:
IOException
-
endItem
Do nothing.- Specified by:
endItem
in interfaceExportTemplate
- Throws:
IOException
- If there is an error
-
endDocument
Write the Excel workbook to the output stream and close.- Specified by:
endDocument
in interfaceExportTemplate
- Throws:
IOException
- If there is an error
-
close
Dispose and close workbook.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-