2012-05-27 2 views
0


Calc에 지정된 행을 반복하고 사전 정의 된 헤더를 검색 한 다음 전체 열 (헤더 포함)을 삭제하는 다음 매크로를 작성했습니다. 그러나 관련 열은 삭제됩니다.해당 헤더를 기반으로 특정 열을 삭제하십시오.

나는 결함을 발견했습니다. 사전 정의 된 목록의 헤더 중 하나라도 파일에서 누락 된 경우 "검색 키를 찾을 수 없음"이라는 오류 메시지가 표시되고 대신 다른 관련이없는 열이 삭제됩니다 (예 : 코드가 "Text1", " Text2 ","Text3 "헤더가 있지만"Text2 "가 없으면 오류 메시지가 팝업되고 관련없는 일부 열이 삭제됩니다.

이 파일에 루프가없는 경우 자동으로 다음 값으로 건너 뛰는 유효성 검사가 있어야합니다.

조건 :

  • 헤더 행은 관련 열이 언급 한 행에 어디서나 나타날 수 항상 7
  • 목록의 항목입니다.
  • 헤더 전체 열을 삭제해야 위치하고 있으면 (
    빈 열이 이후에 남아한다)의 일부 헤더 자동으로 다음
    검색 값으로 이동해야하는 코드가 누락 된 경우.

Calc/Excel 코드가 약간 씩 다르므로 필자가 필요로하는 일부 Excel 코드 예제를 찾았지만 내 경우에는 사용할 수 없습니다.

도움을 주시면 대단히 감사하겠습니다.

sub DeleteSystemFields 
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 switch to active cell A7 

dim args1(0) as new com.sun.star.beans.PropertyValue 
args1(0).Name = "ToPoint" 
args1(0).Value = "$A$7" 

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

rem search conditions 

dim args4(17) as new com.sun.star.beans.PropertyValue 
args4(0).Name = "SearchItem.StyleFamily" 
args4(0).Value = 2 
args4(1).Name = "SearchItem.CellType" 
args4(1).Value = 0 
args4(2).Name = "SearchItem.RowDirection" 
args4(2).Value = true 
args4(3).Name = "SearchItem.AllTables" 
args4(3).Value = false 
args4(4).Name = "SearchItem.Backward" 
args4(4).Value = false 
args4(5).Name = "SearchItem.Pattern" 
args4(5).Value = false 
args4(6).Name = "SearchItem.Content" 
args4(6).Value = false 
args4(7).Name = "SearchItem.AsianOptions" 
args4(7).Value = false 
args4(8).Name = "SearchItem.AlgorithmType" 
args4(8).Value = 1 
args4(9).Name = "SearchItem.SearchFlags" 
args4(9).Value = 65536 

rem search criteria parameters - corresponds to args4(10) in the next section 

args4(10).Name = "SearchItem.SearchString" 
args4(10).Value = "" 
args4(11).Name = "SearchItem.Locale" 
args4(11).Value = 255 
args4(12).Name = "SearchItem.ChangedChars" 
args4(12).Value = 2 
args4(13).Name = "SearchItem.DeletedChars" 
args4(13).Value = 2 
args4(14).Name = "SearchItem.InsertedChars" 
args4(14).Value = 2 
args4(15).Name = "SearchItem.TransliterateFlags" 
args4(15).Value = 1280 
args4(16).Name = "SearchItem.Command" 
args4(16).Value = 3 
args4(17).Name = "Quiet" 
args4(17).Value = true 

rem search values start 

args4(10).Name = "SearchItem.SearchString" 

args4(10).Value = "Text1" 

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

dispatcher.executeDispatch(document, ".uno:DeleteColumns", "", 0, Array()) 


args4(10).Name = "SearchItem.SearchString" 

args4(10).Value = "Text2" 

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

dispatcher.executeDispatch(document, ".uno:DeleteColumns", "", 0, Array()) 

args4(10).Name = "SearchItem.SearchString" 


args4(10).Value = "Text3" 

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

dispatcher.executeDispatch(document, ".uno:DeleteColumns", "", 0, Array()) 


end sub 

답변

0

확실하지하지만 응답이

args4(10).Name = "SearchItem.SearchString" 
args4(10).Value = "Text1" 

found = dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args4()) 

If found.result = True then 

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

    dispatcher.executeDispatch(document, ".uno:DeleteColumns", "", 0, Array()) 

End If 
+0

감사하십시오이

found = dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args4()) If found.result = True then dispatcher.executeDispatch(document, ".uno:DeleteColumns", "", 0, Array()) End If 

후속

을 시도,이 때마다 검색 기준 중 하나 (작동하는 것 헤더 이름)이 미리 정의 된 목록에서 누락 된 경우 관련이없는 열을 삭제하지 않습니다. 그러나 이제는 ** 헤더 ** 만 삭제되고 나머지 열은 여전히 ​​남아 있습니다. 그것을 수정하는 방법을 알고 있습니까 (내 전체 매크로를 삭제하는 원래 매크로에서)? – user1420414

+0

if 부분에서'dispatcher.executeDispatch (document, ".uno : ExecuteSearch", ", 0, args4())를 다시 호출하면 어떻게됩니까? –

+0

고마워, 나는 그것을 밖으로 시도 할 것이다. – user1420414

관련 문제