如何在LibreOffice中编写UFT8编码文件?

时间:2013-02-20 09:30:09

标签: utf-8 libreoffice

我想用LibreOffice Basic编写一个UFT8编码的文本文件。

此处的示例http://wiki.openoffice.org/wiki/Documentation/BASIC_Guide/Structure_of_Text_Documents#Example:_simple_HTML_export显示了使用常规文本编写

 Filename = "c:\temp\text.html"
 FileNo = Freefile
 Open Filename For Output As #FileNo   
 Print #FileNo, "<html><body>"

我逐段遍历文档,并在段落文本元素

中遍历
 Enum2 = TextElement.createEnumeration
 While Enum2.hasMoreElements
     TextPortion = Enum2.nextElement
     ...
 Wend

根据调查结果,文档内容将写入文本HTML文件。

但是不写入Unicode字符。是否可以启用UFT8字符编写?

1 个答案:

答案 0 :(得分:1)

解决方法是首先将所有Unicode字符转换为NCR。那么PRINT命令不处理Unicode也没关系。

' search and replace Unicode values with NCRs (Numerical Character References)
' http://en.wikipedia.org/wiki/NCR

Dim oDoc,aFind,aReplace,aRayCount,oFandR

    oDoc = thisComponent

    aFind = Array("Ɛ","ɛ","Ɔ","ɔ","Ŋ","ŋ")
    aReplace = Array("&#x190;","&#x25B;","&#x186;","&#x254;","&#x14A;","&#x14B;")
    index = 0

    oFandR = oDoc.createReplaceDescriptor
    oFandR.SearchCaseSensitive = true
    oFandR.SearchRegularExpression = false
    While index <= uBound(aFind)
        oFandR.setSearchString(aFind(index))
        oFandR.setReplaceString(aReplace(index))
        index = index + 1
        oDoc.ReplaceAll(oFandR)
    Wend
End Sub

改编自

http://forum.openoffice.org/en/forum/viewtopic.php?f=21&t=2437