Skip to content

Instantly share code, notes, and snippets.

Matthew Brunelle ciferkey

Block or report user

Report or block ciferkey

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
struct Posts {
children: Vec<Post>
View example.json
"kind": "Listing",
"data": {
"children": [....]
View rowAndCell.kt
fun Sheet.row(rowNumber: Int? = null, block: Row.() -> Unit): Row {
return createRow(rowNumber ?: physicalNumberOfRows).apply(block)
fun Row.cell(value: Any? = null, column: Int? = null, block: Cell.() -> Unit = {}): Cell {
val cell = createCell(column ?: physicalNumberOfCells)
when (value) {
is Calendar -> cell.setCellValue(value)
is Date -> cell.setCellValue(value)
is Boolean -> cell.setCellValue(value)
View sheet.kt
fun Workbook.sheet(name: String? = null, block: Sheet.() -> Unit = {}): Sheet {
return if (name != null) {
} else {
public void createWorkbook() {
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0);
View default.kt
fun workbook(wb: Workbook = HSSFWorkbook(), block: Workbook.() -> Unit = {}): Workbook {
return wb
fun tryItOut() {
// use the default HSSFWorkbook
workbook {
View property.kt
fun tryItOut() {
// Also since the block is the only parameter we can even drop the parenthesis all together!
workbook {
// We can directly set the value for isHidden!
isHidden = true
// We cannot change setSelectedTab because Workbook only has a setter for this and no getter (because POI is a PITA).
// This prevents Kotlin from autogenerating the "synthetic accessor"
View setter.kt
// This example is lovingly lifted directly from the Kotlin documentation
class Foo() {
// Note that in Kotlin variable types are inferred, you can say "var" (or val if you want it immutable) instead of specifying the type.
// Here we are defining a field named "counter" with a value of 1.
var counter = 0
// Here we are providing a setter that only updates the field if the new value is positive.
set(value) {
if (value >= 0) field = value
View receiver.kt
// Notice the parameter is now of type "Workbook.() -> Unit" rather than "(Workbook) -> Unit"
fun workbook(block: Workbook.() -> Unit): Workbook {
var wb = HSSFWorkbook()
return wb
fun tryItOut() {
// Since we defined the lambda as using a Receiver Type of "Workbook.()" we can now directly call the methods without referencing the paramter
View workbook.kt
// In Kotlin function definitions start with the keywork "fun"
// Additionally Kotlin lets you have "top level" functions that do not need to be inside a class
// "(Workbook) -> Unit" means "a function that takes a workbook and returns nothing (Unit)
fun workbook(block: (Workbook) -> Unit): Workbook {
var wb = HSSFWorkbook()
// Note that in Kotlin we can direcly call "block" rather than needing to call "accept" on it
return wb
You can’t perform that action at this time.