Page 1 of 1

Calc import txt script

Posted: Fri Oct 03, 2008 8:34 am
by Mekemba
I would like to know if a macro exists so that Calc it inserts the content of an archive of simple .txt text in a specific cell.
I would like that it made this when opening automatically the spread sheet.
Thanks.
:mrgreen:

Re: Calc import txt script

Posted: Fri Oct 03, 2008 11:03 am
by Villeroy
Yes, there is. And guess where you can find it: It's all in your head already.

Please

Posted: Fri Oct 03, 2008 11:18 am
by Mekemba
I do not know what you wanted to say…
But I need that somebody gives script to me

Re: Calc import txt script

Posted: Fri Oct 03, 2008 11:39 am
by Villeroy
... inserts the content of an archive of simple .txt text in a specific cell.
You are so unspecific that you want us to read your mind. Do you really want to read a whole text file with line-breaks and everything into a single spreadsheet cell? Never seen such a thing.

Re: Calc import txt script

Posted: Fri Oct 03, 2008 12:48 pm
by Villeroy

Code: Select all

Sub Main
oCell = thisComponent.Sheets.getByIndex(0).getCellByPosition(0,0)
iNumber = freefile()
open "/tmp/dummy.txt" for input as iNumber
While not eof(iNumber)
Line Input #iNumber, sLine
If sLine <>"" then
	sMsg = sMsg & sLine & chr(10)
end if
wend
Close #iNumber
oCell.setString(sMsg)
End Sub
Most of it copied from the Basic help.

Re: Calc import txt script

Posted: Thu Dec 04, 2008 7:45 am
by Ronaldwin
Hi All,

I copy the script on Calc. Try to run it. Nothing is seen.

I rename the txt file path to d:\tmp\dummy.txt

Please help me how to run

Also, the dummy.txt contain about 360,000 data record. Is it work?

Wait for your return.

Mr. Ronald

Re: Calc import txt script

Posted: Thu Dec 04, 2008 8:20 am
by probe1
Welcome to the forum.
Ronaldwin wrote:contain about 360,000 data record. Is it work?
You are kidding: 360K records into one cell?

Re: Calc import txt script

Posted: Thu Dec 04, 2008 12:56 pm
by Ronaldwin
To Probe 1,

My objective is to insert one data record to one cell in Calc. However, the txt database contain 360K data records.

When I use the posted script, I did not see any response. Please let me know how to get the result/response

2). When I import the .txt database by Calc (Open Office 3.0) import function, the Calc response that it is over 65536 row limit.

Please help me.

Wait for your return.

Re: Calc import txt script

Posted: Thu Dec 04, 2008 2:00 pm
by Villeroy
Put your txt file in it's own directory.
File>New>Database...
[X] Connect to existing database
Type: Text
Specify the directory of your text database.
Specify details of your text file (and other files that may be in the same directory as well)
[X] Register database (for further use in Writer or Calc)
Store the database document.