2013-02-20 151 views
0

我想用LibreOffice Basic编写一个UFT8编码的文本文件。如何在LibreOffice中编写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

解决方法是先将所有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

改编