Class XlsxTemplate
java.lang.Object
net.sf.basedb.clients.web.plugins.XlsxTemplate
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ExportTemplate
Template implementation that exports data to Excel format (xlsx).
- Since:
- 3.15
- Author:
- nicklas
-
Field Summary
Modifier and TypeFieldDescriptionprivate String
private int
private org.apache.poi.ss.usermodel.Row
private final OutputStream
private final List<ExportedProperty>
private int
private final org.apache.poi.ss.usermodel.Sheet
private final CellStyleCreator
private final org.apache.poi.ss.usermodel.Workbook
-
Constructor Summary
ConstructorDescriptionXlsxTemplate
(OutputStream out, List<ExportedProperty> properties, Item itemType, long numItems, String collectionSeparator) Create a new template. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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.Get the default file extension to give to files generated by this template.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
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
-