我现在试图这样做两天了: 使用LibreOffice 5.4在Mac上工作。
我有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内部过滤宏?
答案 0 :(得分:0)
录制通常不是学习或编写宏的好方法。相反,在线查找示例和文档。在Google上搜索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
结果: