2017-09-01 152 views
0

我試圖這樣做兩天現在: 在Mac上使用LibreOffice 5.4。LibreOffice包括一個過濾器宏

我有CSV文件與幾個約會,日期等 什麼我需要這個文件做的打開,正在過濾今天的所有約會。我到目前爲止的是,我檢查每一行,並將1添加到最後一行,如果它匹配或添加0如果今天不是今天。

其實我記錄了我的動作,所以我現在的宏並不是最優的,這就是爲什麼我沒有發佈它。

https://picload.org/thumbnail/rwwiiaaa/image.jpg 這裏是一張表的一部分的圖片。 這是我的宏至今:

sub csvfilter 
rem ---------------------------------------------------------------------- 
rem define variables 
dim document as object 
dim dispatcher as object 
rem ---------------------------------------------------------------------- 
rem get access to the document 
document = ThisComponent.CurrentController.Frame 
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") 

rem ---------------------------------------------------------------------- 
dim args1(0) as new com.sun.star.beans.PropertyValue 
args1(0).Name = "ToPoint" 
args1(0).Value = "$AI$1" 

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1()) 

rem ---------------------------------------------------------------------- 
dim args2(0) as new com.sun.star.beans.PropertyValue 
args2(0).Name = "StringName" 
args2(0).Value = "=TEXT(TODAY();"+CHR$(34)+"YYYY-MM-DD"+CHR$(34)+")" 

dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, args2()) 

rem ---------------------------------------------------------------------- 
dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array()) 

rem ---------------------------------------------------------------------- 
dim args4(0) as new com.sun.star.beans.PropertyValue 
args4(0).Name = "StringName" 
args4(0).Value = "=IF(AI$1=LEFTB(C2;10);"+CHR$(34)+"1"+CHR$(34)+";"+CHR$(34)+"0"+CHR$(34)+")" 

dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, args4()) 

rem ---------------------------------------------------------------------- 
dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array()) 

rem ---------------------------------------------------------------------- 
dim args6(0) as new com.sun.star.beans.PropertyValue 
args6(0).Name = "ToPoint" 
args6(0).Value = "$AI$2" 

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args6()) 

oSheet = thisComponent.sheets(0) 
ocursor = oSheet.createCursor() 
ocursor.gotoStart() 
ocursor.gotoEndofUsedArea(false) 

rem ---------------------------------------------------------------------- 
dim args7(0) as new com.sun.star.beans.PropertyValue 
args7(0).Name = "EndCell" 
args7(0).Value = "$AI" & ocursor.getRangeAddress.endRow+1 

dispatcher.executeDispatch(document, ".uno:AutoFill", "", 0, args7()) 

rem ---------------------------------------------------------------------- 
dim args8(0) as new com.sun.star.beans.PropertyValue 
args8(0).Name = "ToPoint" 
args8(0).Value = "$AI$2:$AI$18" 

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args8()) 

rem ---------------------------------------------------------------------- 
dim args9(0) as new com.sun.star.beans.PropertyValue 
args9(0).Name = "ToPoint" 
args9(0).Value = "$AI$1" 

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args9()) 

rem ---------------------------------------------------------------------- 
rem dispatcher.executeDispatch(document, ".uno:DataFilterStandardFilter", "", 0, Array()) 

rem ---------------------------------------------------------------------- 
dispatcher.executeDispatch(document, ".uno:FilterExecute", "", 0, Array()) 
end sub 

我的問題是,我怎麼能在宏內部的最後一排,篩選了1 S'

+1

首先你應該添加你的代碼,你已經嘗試過什麼(即使是錯誤的,不完美的或東西),所以任何人誰幫助有事與...合作。 (2)CSV文件中不能有宏(只能保存數據)。 (3)如果可以,請還提供您的工作表的屏幕截圖。如果人們能夠看到哪些數據位於哪一列,那麼人們就會更容易理解諸如「*過濾所有今天的約會*」之類的東西。 –

+0

在我的文章中添加了我的代碼csv文件的圖片(因爲我認爲necesarry的部分,因爲它包含大量的個人信息) –

+0

圖片太小,無法閱讀。 –

回答

0

錄製通常不是學習或編寫宏的好方法。相反,請在線查找示例和文檔。搜索谷歌搜索openoffice macro filter帶來了大量有用的結果。

假設電子表格看起來像這樣。

A B C 
~~ ~~ ~~ 
1 A AA 
0 B BB 
0 C CC 
1 D DD 
1 E EE 
1 F FF 
0 G GG 
0 H HH 
1 I II 
0 J JJ 

下面是隱藏除那些列A爲1,適於從所述清單的OpenOffice User Guide Filters page 5中的所有行的宏。

Sub SimpleSheetFilter() 
    Dim oSheet ' Sheet that will contain the filter. 
    Dim oFilterDesc ' Filter descriptor. 
    Dim oFields(0) As New com.sun.star.sheet.TableFilterField 
    oSheet = ThisComponent.getSheets().getByIndex(0) 
    oFilterDesc = oSheet.createFilterDescriptor(True) 
    With oFields(0) 
    .Field = 0 ' Column A 
    .IsNumeric = True 
    .NumericValue = 1 
    .Operator = com.sun.star.sheet.FilterOperator.EQUAL 
    End With 
    oFilterDesc.setFilterFields(oFields()) 
    oSheet.filter(oFilterDesc) 
End Sub 

結果:

filtered result