OO-Snippets: Importing a plain text encoded with a given character set

Commons

KeywordsText (encoded), FilterOptions
LanguageOOBasic
ApplicationWriter
AuthorsCedric Bosdonnat (initial)
Supported Versions2.0.x  
Supported OSAll  
QuestionHow to import a plain text file encoded with a given character set

Simply suppose we need to import MyTest.txt which is encoded in IBM850, also knwon as cp850.

Answer

For this, we need to use the 'Text (encoded)' filter and configure it properly as shown by the code snippet.

The possible character set codes are all listed on this page: http://equalitylearning.org/~robertz/oo_encoding_indexes.html

Code-Snippet-Listing (snippet-source)

	Dim oMediaDescriptor(1) as new com.sun.star.beans.PropertyValue
	
	sFileUrl = convertToUrl( "H:\My Test.txt" )
	
	oMediaDescriptor(0).name = "FilterName"
	oMediaDescriptor(0).value = "Text (encoded)"
	oMediaDescriptor(1).name = "FilterOptions"
	oMediaDescriptor(1).value = "IBM_850"
    oDoc = StarDesktop.loadComponentFromURL(sFileURL, "_blank", 0, oMediaDescriptor)

Changelog

DateUserModification
2007-01-03cedricbosdoInitial version

and