Calc import txt script

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
Mekemba
Posts: 2
Joined: Fri Oct 03, 2008 8:19 am

Calc import txt script

Post 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:
OOo 2.4.X on Mandriva
User avatar
Villeroy
Volunteer
Posts: 31365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Calc import txt script

Post by Villeroy »

Yes, there is. And guess where you can find it: It's all in your head already.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Mekemba
Posts: 2
Joined: Fri Oct 03, 2008 8:19 am

Please

Post by Mekemba »

I do not know what you wanted to say…
But I need that somebody gives script to me
OOo 2.4.X on Mandriva
User avatar
Villeroy
Volunteer
Posts: 31365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Calc import txt script

Post 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.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
Posts: 31365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Calc import txt script

Post 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.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ronaldwin
Posts: 2
Joined: Thu Dec 04, 2008 7:34 am

Re: Calc import txt script

Post 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
OOo 3.0.X on Ms Windows XP
User avatar
probe1
Volunteer
Posts: 277
Joined: Mon Oct 08, 2007 1:34 am
Location: Chonburi Thailand

Re: Calc import txt script

Post 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?
Cheers
Winfried

DateTime2 extension: insert date, time or timestamp, formatted to your needs
Ronaldwin
Posts: 2
Joined: Thu Dec 04, 2008 7:34 am

Re: Calc import txt script

Post 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.
OOo 3.0.X on Ms Windows XP
User avatar
Villeroy
Volunteer
Posts: 31365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Calc import txt script

Post 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.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply