Private Sub Workbook_Open()
Rem find data range last line No.
Dim dataRowEndLineNo As Integer
For dataBeginLineNo = 6 To Cells(Rows.Count, "a").End(xlUp).Row
dataRowEndLineNo = dataBeginLineNo
If Cells(dataBeginLineNo, "A") = "." Then Exit For
Next
Rem delete mark point
Range("A" & dataRowEndLineNo).ClearContents
Rem auto fit row for data range
For dataBeginLineNo = 6 To dataRowEndLineNo
Cells(dataBeginLineNo, "A").Rows.AutoFit
Next
End Sub
下图为模板页,第6行为动态扩展行通过java poi代码写入数据,第7行中A1列有一个标记点'.'
下图为最终效果, 可以看到从第六行到第七行都可以根据单元格内容动态改变行高。(打开excel后需要点击一下允许执行宏)
Alt + F11查看Vba脚本
也可以去我的github上查看整套代码: https://github.com/xiaowanziwuha2/note
运行下面测试类后打开console中输出的xls查看结果。