https://bz.apache.org/bugzilla/show_bug.cgi?id=65916

--- Comment #7 from moimoi.chk <moimoi....@gmail.com> ---
Hey Tom!
Several years have passed and I had no choice but to return to help with this
problem^^/!

ExcelFile:
https://docs.google.com/spreadsheets/d/15yg4CwC_MBHOmjArTOJFumzCe6bz0Aic/edit?usp=sharing&ouid=114966700205032259907&rtpof=true&sd=true

package test

import com.true_stage.truexcel.excel.Aggregate
import org.apache.poi.ss.usermodel.*
import java.io.File
import java.io.FileOutputStream

fun main(vararg args: String) {
    val book = WorkbookFactory.create(File("/Users/takano/test.xlsx"))

    //  create sheet
    val baseSheetIndex = book.getSheetIndex("base")
    if (baseSheetIndex == -1) {
        throw Exception()
    }
    val sheet = book.cloneSheet(baseSheetIndex)
    val newSheetIndex = book.getSheetIndex(sheet)
    book.setSheetName(newSheetIndex, "TomRiddle")

    //  issue point
    clearAll(sheet)

    //  write as other file
    write(book, File("/Users/takano/garbage.xlsx"))
}

fun write(workbook: Workbook, file: File): String? {
    var out: FileOutputStream? = null
    return try {
        out = file.outputStream()
        workbook.write(out)
        file.absolutePath
    } catch (e: Exception) {
        null
    } finally {
        out?.close()
    }
}

fun clearAll(sheet: Sheet) {
    val itr = sheet.rowIterator()
    while (itr.hasNext()) {
        val row = itr.next()
        if (row.rowNum >= 4) {
            clearRow(row)
        }
    }
}

fun clearRow(row: Row) {
    val itr = row.cellIterator()
    while (itr.hasNext()) {
        itr.next()
        itr.remove()
    }
}

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org
For additional commands, e-mail: dev-h...@poi.apache.org

Reply via email to