簡體   English   中英

Libreoffice calc:刪除行的 function

[英]Libreoffice calc: function that deletes rows

我是 Libreoffice Calc 的新手。
我的 if/else function 填充新工作表中的單元格。
function 在新工作表中生成大量空行。
是否可以使用 function 刪除那些空行?
就像是:

=IF(NOT(ISEMPTY(sheet1.A1));sheet2.A1; delete row ???)

還是應該用宏來完成?
非常歡迎任何幫助我入門的幫助。

我不確定 Standard Filter 是如何工作的,但我只是編寫了這個應該可以解決問題的宏代碼。 假設:

  1. 適用於當前活動工作表
  2. 僅檢查第一列是否有空白內容或空白字符串
  3. 連續空行超過 100 行后,代碼將停止。 如果您認為可以有更多,可以將 cMaxBlankRows 設置為更高的數字,但如果設置得太高,代碼將花費更長的時間運行。
const cMaxBlankRows = 100 ' stop processing if there are more than this number of blanks in a row
const cMaxRows = 1048575 ' LibreOffice max number of rows - 1, it is zero based
Sub subDeleteBlankRows()
    oDoc = ThisComponent
    oSheet1 = oDoc.getCurrentController().getActiveSheet()
    iIdx = 0
    iConBlank = 0    ' number of continuous blanks
    Do While iIdx <= cMaxRows 
        oCell = oSheet1.getCellByPosition(0,iIdx)
        If oCell.getType() = com.sun.star.table.CellContentType.EMPTY OR Len(oCell.getString()) = 0 Then
            ' found an empty cell, delete the row
            oSheet1.Rows.removeByIndex(iIdx,1)
            iConBlank = iConBlank + 1
            ' don't advance iIdx
            if iConBlank > cMaxBlankRows Then Exit Do
        Else
            iIdx = iIdx + 1
            iConBlank = 0
        End If
    Loop
End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM