2018年5月6日 星期日

用Libreoffice writer巨集方便整理文章

為了用LibreOffice writer整理OCR後的文章內容,到網路上(Ask LibreOffice 互助問答)詢問和搜尋,加上自己實作和推想,得到了整理文書的好用巨集,紀錄在這兒,讓有用到的人可以參考。

1.直接將「Hledat」內的字串,取代為「Nahradit」的字串: (來自Lio ooo社團
----------------
Sub Najdi_Nahrad()
    Dim oDoc,oText,oVC,oStart,oEnd,oFind,FandR
    oDoc = ThisComponent : oText = oDoc.Text
    oVC = oDoc.CurrentController.getViewCursor
        Hledat = Array("0","1", "2","3" ,"4", "5" ,"6" ,"7", "8","仿佛","却", "Search", "Value")
        Nahradit = Array("〇","一", "二", "三", "四", "五", "六", "七", "八","彷彿","卻", "hledat", "Hodnota")
        Pocet = 0
       While Pocet <= uBound(Hledat)
          oStart = oText.createTextCursorByRange(oVC.Start)
          If Not oVC.isCollapsed then oEnd = oText.createTextCursorByRange(oVC.End)
             FandR = oDoc.createReplaceDescriptor
             With FandR
                .SearchString = Hledat(Pocet)
                .ReplaceString = Nahradit(Pocet)
                .SearchWords = false
             End With
          If isEmpty(oEnd) then 'Do whole document.
               oDoc.replaceAll(FandR)
          Else
               Do
                   oFind = oDoc.FindNext(oStart.End,FandR)
                   If isNull(oFind) then Exit Do
                   If oText.compareRegionEnds(oFind,oEnd) < 0 then Exit Do
                   oFind.setString(FandR.ReplaceString)
                   oFind = oDoc.FindNext(oFind.End,FandR)
              Loop
          EndIf
       Pocet = Pocet + 1
        Wend     
End Sub
---------------
2.回到文章最前面,即〔按[Ctrl+Home〕
----------------
sub Ctrlhome1
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 -----------------------------------
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())
end sub
----------------
3.找「args1(11).Value = "? "」字串
---------------
sub no01
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(21) as new com.sun.star.beans.PropertyValue
args1(0).Name = "SearchItem.StyleFamily"
args1(0).Value = 2
args1(1).Name = "SearchItem.CellType"
args1(1).Value = 0
args1(2).Name = "SearchItem.RowDirection"
args1(2).Value = true
args1(9).Name = "SearchItem.AlgorithmType"
args1(9).Value = 0
args1(10).Name = "SearchItem.SearchFlags"
args1(10).Value = 0
args1(11).Name = "SearchItem.SearchString"
args1(11).Value = "? "
args1(12).Name = "SearchItem.ReplaceString"
args1(12).Value = ""
args1(13).Name = "SearchItem.Locale"
args1(13).Value = 255
args1(14).Name = "SearchItem.ChangedChars"
args1(14).Value = 2
args1(15).Name = "SearchItem.DeletedChars"
args1(15).Value = 2
args1(16).Name = "SearchItem.InsertedChars"
args1(16).Value = 2
args1(17).Name = "SearchItem.TransliterateFlags"
args1(17).Value = 256
args1(18).Name = "SearchItem.Command"
args1(18).Value = 0
args1(19).Name = "SearchItem.SearchFormatted"
args1(19).Value = false
args1(20).Name = "SearchItem.AlgorithmType2"
args1(20).Value = 1
args1(21).Name = "Quiet"
args1(21).Value = true

dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args1())
end sub
--------------
4.執行上一個動作(如3.),再新增段落
---------------
sub fixz0
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 = "Quiet"
args1(0).Value = true

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

rem -----------------------------------
dim args2(1) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Count"
args2(0).Value = 1
args2(1).Name = "Select"
args2(1).Value = false

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

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

rem -----------------------------------
dim args4(0) as new com.sun.star.beans.PropertyValue
args4(0).Name = "Quiet"
args4(0).Value = true

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

rem -----------------------------------
dim args5(1) as new com.sun.star.beans.PropertyValue
args5(0).Name = "Count"
args5(0).Value = 1
args5(1).Name = "Select"
args5(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args5())

rem -----------------------------------
dispatcher.executeDispatch(document, ".uno:InsertPara", "", 0, Array())
end sub
-------------------
5.刪除全文中的半型空白和全型空白
-------------------
sub bit20
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(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Count"
args1(0).Value = 1
args1(1).Name = "Select"
args1(1).Value = true

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

rem -----------------------------------
dim args2(21) as new com.sun.star.beans.PropertyValue
args2(0).Name = "SearchItem.StyleFamily"
args2(0).Value = 2
args2(1).Name = "SearchItem.CellType"
args2(1).Value = 0
args2(2).Name = "SearchItem.RowDirection"
args2(2).Value = true
args2(9).Name = "SearchItem.AlgorithmType"
args2(9).Value = 0
args2(10).Name = "SearchItem.SearchFlags"
args2(10).Value = 65536
args2(11).Name = "SearchItem.SearchString"
args2(11).Value = " "
args2(12).Name = "SearchItem.ReplaceString"
args2(12).Value = ""
args2(13).Name = "SearchItem.Locale"
args2(13).Value = 255
args2(14).Name = "SearchItem.ChangedChars"
args2(14).Value = 2
args2(15).Name = "SearchItem.DeletedChars"
args2(15).Value = 2
args2(16).Name = "SearchItem.InsertedChars"
args2(16).Value = 2
args2(17).Name = "SearchItem.TransliterateFlags"
args2(17).Value = 1280
args2(18).Name = "SearchItem.Command"
args2(18).Value = 3
args2(19).Name = "SearchItem.SearchFormatted"
args2(19).Value = false
args2(20).Name = "SearchItem.AlgorithmType2"
args2(20).Value = 1
args2(21).Name = "Quiet"
args2(21).Value = true

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

end sub
----------------------
6.將所有半型改為全型
---------------------
sub word2bit1   '全部改為全型
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 -----------------------------------
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())

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

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

rem -----------------------------------
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())
end sub
 -------------------
7.除了「sString 」中的字串外,刪除段落(將下一段文字接到前段)
  參考LibreOffice正體中文使用者社團 → pastebin - Miscellany - post number 3992044
----------------
sub Main003
  Dim oCurrentController As Variant
  Dim oViewCursor As Variant
  Dim oText As Variant
  Dim oObj1 As Variant
  Dim oObj2 As Boolean
  Dim oObj3 As Boolean
  Dim sString As String

  oCurrentController = ThisComponent.getCurrentController()
  oViewCursor = oCurrentController.getViewCursor()
  oText = oViewCursor.getText()
 
  oObj1 = oText.createTextCursorByRange(oViewCursor)
  oObj1.gotoEndOfParagraph(False)
  oObj1.goLeft(1, True)
 
  sString = oObj1.getString()
  oObj1.collapseToEnd()
  oObj1.gotoEndOfParagraph(False)
  oViewCursor.gotoRange(oObj1, False)
    document   = oCurrentController.Frame
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")   

  if sString = "。" or sString ="?" or sString ="." or sString ="…"  or sString ="!" or sString ="x" or sString ="」"  or sString =":"  or sString ="★"  or sString ="※" then
    rem -----------------------------------
      dispatcher.executeDispatch(document, ".uno:GoToNextPara", "", 0, Array())

  else
    dispatcher.executeDispatch(document, ".uno:Delete", "", 0, Array())
   
  end if
 
end sub
-----------------------8.重複執行巨集(Main003)三次
----------------
Sub my_Procedure()
    Call Main003
    Call Main003
    Call Main003
 End Sub
-----------------
9.將以上各巨集全部合成一個巨集,由前向後執行
---------------
Sub fi2pro_all()
    Call  fire01 '取代文字

Call Ctrlhome1 '回到最前面
    Call no01       '找到"? "   
        Call find_xz       '新增段落,並重複執行

Call Ctrlhome1 '回到最前面
    Call no02      '找到"」 "
   
        Call find_xz       '新增段落,並重複執行
                Call find_xz       '新增段落,並重複執行
Call Ctrlhome1 '回到最前面
    Call no03      '找到": "
   
        Call find_xz        '新增段落,並重複執行
Call Ctrlhome1 '回到最前面
    Call no04      '找到"。 "
 
        Call find_xz       '新增段落,並重複執行
                Call find_xz      '新增段落,並重複執行

Call Ctrlhome1 '回到最前面
    Call no05      '找到"! "
 
        Call find_xz       '新增段落,並重複執行

Call Ctrlhome1 '回到最前面
    Call no06      '找到"』 "則換一段
 
        Call find_xz       '新增段落,並重複執行
               
Call Ctrlhome1 '回到最前面
Call bit20        '刪去空白(包括全型半型)
Call word2bit1          '全部改為全型符號
Call Ctrlhome1       
Call my_Procedure        '接斷行 
    end sub
--------------

2018年5月5日 星期六

用手機測量血壓、血糖和作計步器

你可能不知道,帶著手機就可以隨時測量血壓血糖值和作為計步器等。實在是方便哩!
前兩天看BBC,有關醫學、健康的節目,其中有談到用手機測量血壓,因為我有「家傳」的高血壓,於是到Google Play商店找測量血壓的app,果然有欸!(若要更準確的測量值,可以到一般儀器測量,然後和手機app校準個兩、三次即可)【可能準確性有待改進,有些app已移除
  
如果你有健康方便需要測量的身體狀況,不妨到 play商店去找找看有什麼app可用。
  
計步器app,將手機帶在身上就可以用來測量一天走了多少步,或散步、慢跑、快走時走了多少步,很方便喔!
  
有什麼想法,三不五時到Play 商店找找看有沒有app可用,倒是給生活帶來許多方便哩!

2018年5月3日 星期四

申請發票手機條碼載具--自動幫你對獎又環保

每次買東西開發票,臺灣一年估計就需要印掉五萬棵樹的紙張。所以去申請電子發票手機條碼載具吧!好處多多:
  
1.環保;
2.自動幫你對獎,中獎後還通知你;
3.設定帳號,獎金自動匯入,連領獎手續都省了。
 真是方便啊!

※如何申請呢!
1.到「財政部電子發票整合服務平台」,點雲端發票申請
2.輸入手機號碼Email ,再點擊「我要申請」即可。(若沒手機,可找家人中任何一支手機;若沒Email,可到google申請一個mail信箱)

※如何使用和設定銀行帳號等,請參考下面這一篇的詳細說明:
如何申請及使用電子發票手機條碼載具?

※接下來,若你想用手機app:
1.在下載之後,直接用「電子信箱帳號」及「手機驗證碼」登入,就可以開始使用。
2.買東西時,向結帳人員說:「我有載具」,然後點app中你的專屬條碼讓他掃一下,發票對獎號碼就歸戶了,開獎時,就自動幫你對獎了。
2.另外,app也可自動掃描已開的統一發票或手動輸入號碼等資料,等開獎時,手機會自動幫你對獎,超方便的。

就醬,趕快動個手吧!環保又方便!