แสดงบทความที่มีป้ายกำกับ convert thai number แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ convert thai number แสดงบทความทั้งหมด

วันจันทร์ที่ 18 กรกฎาคม พ.ศ. 2554

แปลงเลขอาราบิกให้เป็นเลขไทยใน LibreOffice/OpenOffice.org

จาก post http://www.leknarm.com/2010/10/openofficeorg-writer.html ผมได้เขียนมาโครง่ายๆ และได้ทำเป็น extension ไว้ให้ลองเล่นกันแล้ว แต่ว่ามี bug อยู่จำนวนมาก และจากงาน OpenOffice.org Codefest#9 ก็ได้มีเพื่อนๆ ช่วยกันพัฒนา extension นี้จนสมบูรณ์ขึ้นมา

แต่ระหว่างที่ผมกำลัง review และปรับปรุง extension อยู่นั้นก็ได้เกิดเหตุการที่ไม่คาดฝันขึ้น มีบุคคลนึงเอา extension จาก post ที่กล่าวมาเอาไป publish ที่ OpenOffice.org Extensions เฉยเลย
http://extensions.services.openoffice.org/en/project/thai-number-converter (ไม่ขอทำเป็น link นะครับเพราะ SEO) น่าเศร้าใจเป็นที่สุด

แต่ตอนนี้ทางทีมก็ได้ publish extension ที่แก้ไขและปรับปรุงเรียบร้อยแล้วไว้ที่ http://extensions.services.openoffice.org/project/convertdigit ทุกท่านสามารถ download และทดลองใช้ได้เลยครับ หากมี bug หรือ comment ในส่วนไหนสามารถ comment ได้ที่ extension หรือที่ blog นี้ก็ได้ครับ
Continue Reading...

วันศุกร์ที่ 22 ตุลาคม พ.ศ. 2553

เปลี่ยนตัวเลขอาราบิก ให้เป็นเลขไทยบน OpenOffice.org Writer ด้วยมาโคร

เนื่องจาก @gumara ได้ฝากถามมาว่าบน OpenOffice.org สามารถกด keypad แล้วพิมพ์เป็นเลขไทยได้ไหม เพราะพวกหนังสือราชการนั้นจำเป็นต้องเป็นเลขไทย ให้คอยมากด shift + เลข ก็เสียเวลา

ปัญหาดังกล่าวไม่สามารถทำได้บน OpenOffice.org เนื่องมาจาก key ที่ให้เราสามารถตั้งค่าการทำงานต่างๆ บน OpenOffice.org มีอยู่จำกัดและไม่สามารถเพิ่มเองได้เหมือนกับ Microsoft Office ดังนั้นผมจึงคิดว่าควรทำเป็น extension หรือ ง่ายกว่านั้นก็คือ macro 

ดังนั้นผมจึงเขียนมาโครที่ทำการ convert ตัวเลขอาราบิกทั้งหมดภายในเอกสารให้กลายเป็นตัวเลขไทยซะดังนี้

sub main
  dim descriptor
  dim foundall
  dim found
 
  descriptor = ThisComponent.createSearchDescriptor()
  thainum = array("๐", "๑", "๒", "๓", "๔", "๕", "๖", "๗", "๘", "๙")
  for num = 0 to 9
    with descriptor
      .SearchString = num
      .SearchCaseSensitive = False
    end with
  
    foundall = ThisComponent.findall(descriptor)
    for i = 0 to foundall.getcount() -1
      found = foundall.getbyindex(i)
      found.setstring(thainum(num))
    next
  next
end sub

แค่นี้ เมื่อกดรันมาโครดังกล่าว ตัวเลขภายในเอกสารของเราก็จะกลายเป็นเลขไทยแล้ว

-----------------------------------------------------------

เพิ่มเติมอีกนิด สำหรับการแก้ไขเลขไทยเฉพาะส่วนที่คลุมครับ

sub mainselected
  dim leftpos
  dim rightpos
  dim found
  dim descriptor

  descriptor = ThisComponent.createSearchDescriptor()
  thainum = array("๐", "๑", "๒", "๓", "๔", "๕", "๖", "๗", "๘", "๙")
  for num = 0 to 9
    with descriptor
      .SearchString = num
      .SearchCaseSensitive = False
    end with
    leftpos = thiscomponent.getcurrentcontroller().getviewcursor().getstart()
    rightpos = thiscomponent.getcurrentcontroller().getviewcursor().getend()

    found = thiscomponent.findnext(leftpos.getstart(), descriptor)
    do while not isnull(found)
      if -1 = thiscomponent.gettext().compareRegionEnds(found, rightpos) then exit do
      found.setstring(thainum(num))
      found = thiscomponent.findnext(found.end, descriptor)
    loop
  next
end sub

-----------------------------------------------------------
update

ทำเป็น extension เพื่อให้ติดตั้งแล้วใช้งานได้ทันทีครับ


download

เมื่อติดตั้งแล้วจะอยู่ที่เมนู format > convert to native number ครับโดยต้องคลุมก่อนแล้วเลือกใช้งานครับ
Continue Reading...

Blogroll

About