sub adjustrowheight0()dim modelsheet as worksheet, printsheet as worksheet
dim modelrng as range '模板單元格
dim modelrowheight() as double '模板行高資料
dim modelrowcount as long '模板行數
dim summodelheight as double '模板累計行高
dim adjustscale as double '調整比例
const model_count = 5 ' 每一頁放置多少個單據rowsinonepage / modelrowcount
dim desrng as range '貼上位置
dim breakrange as range '水平分頁符位置
dim pageheight as double '累計首頁行高
dim i as long '行號
set modelsheet = thisworkbook.worksheets("單據模板")
set printsheet = thisworkbook.worksheets("批量列印")
with modelsheet
'計數防止計算行號發生錯誤
endrow = .cells.find("*", .cells(1, 1), xlvalues, xlwhole, xlbyrows, xlprevious).row + 1
endcol = .cells.find("*", .cells(1, 1), xlvalues, xlwhole, xlbycolumns, xlprevious).column
'獲取單據模板單元格區域
set modelrng = .range(.cells(1, 1), .cells(endrow, endcol))
'獲取模板單元格行數和累計行高
modelrowcount = modelrng.rows.count
redim modelrowheight(1 to modelrowcount)
summodelheight = 0
for i = 1 to modelrowcount
modelrowheight(i) = modelrng.rows(i).rowheight
summodelheight = summodelheight + modelrng.rows(i).rowheight
next i
end if
end with
with printsheet
.cells.clear
'批量複製單據模板
for i = 1 to 25
set desrng = .range("a1")
else
endrow = .cells.find("*", .cells(1, 1), xlvalues, xlwhole, xlbyrows, xlprevious).row + 2
set desrng = .cells(endrow, 1)
end if
modelrng.copy desrng '實際操作時還需要填入資料
next i
'只有內容超出一頁時,excel才會自動新增分頁符
if .hpagebreaks.count > 0 then
'獲取第乙個垂直分頁符所在的單元格
set breakrange = .hpagebreaks(1).location
'累計第一頁所有行的高度
i = 1
do while i < breakrange.row
pageheight = pageheight + .rows(i).rowheight
i = i + 1
loop
'獲取最後乙個成績單末尾的空白行行號
rowsinonepage = breakrange.row
rowsinonepage = rowsinonepage - 1
loop
'計算調整比例
adjustscale = pageheight / (summodelheight * model_count)
'逐行調整
endrow = .cells.find("*", .cells(1, 1), xlvalues, xlwhole, xlbyrows, xlprevious).row + 1
r = 0
for i = 1 to endrow
r = r + 1
.rows(i).rowheight = modelrowheight(r) * adjustscale
if r = modelrowcount then r = 0 '逐個單據調整
next i
end if
end with
set modelsheet = nothing: set printsheet = nothing
end sub
Java POI Excel 行高自適應
在excel處理的過程中,可能有需要用到行高自適應的時候。下面貼出用poi實現excel行高自適應的 該 可以處理一行excel按內容自適應高度。可以處理合併單元格。上 根據行內容重新計算行高 param row public static void calcandsetrowheigt hssfr...
iReport自適應行高
ireport設計報表,當detail的行高需要自適應時,應按如下設定 1.所有textfield的 position type fix relative to top 或fix relative to bottom 2.所有textfield的 stretch type relative to b...
關於UILabel行高自適應的方法
關於uilabel行高根據內容自適應,如下 uilabel label uilabel alloc init label.font uifont systemfontofsize 14 label.numberoflines 0 nsstring string string 人生是一場旅程。我們經歷...