[Solved] Getting Strings from Calc to .txt

Discuss the spreadsheet application
Post Reply
pechart
Posts: 3
Joined: Fri Jan 25, 2008 10:54 pm

[Solved] Getting Strings from Calc to .txt

Post by pechart »

Hello everybody!
First of all: I'm new to Calc, so I don't even know where I can start to search for related topics. Sorry for that.

I would like to know, if it is possible to create a string from different cells and create a new string. Then I want to export the created new strings to a .txt File (or even better a .bat file).
But i just don't know where to start. I open up my document and create a new function. But what is the right syntax?
My columns are like [No.] [Name] [Startpoint] [Endpoint]. My goal is to have a Textfile with a string like " ...<Text> [No.] named [Name] from [Startpoint] to [Endpoint] <Text>... " for each row of the sheet.
Hmm, sorry if that's somewhat hard to understand.
My other problem is, that i'm short on time in a project and I can't spend to much time on reading the docs etc. yet. So it would be really great, if someone could help me with this.

Thank you!
Last edited by pechart on Sat Jan 26, 2008 1:45 pm, edited 2 times in total.
User avatar
kingfisher
Volunteer
Posts: 2123
Joined: Tue Nov 20, 2007 10:53 am

Re: Getting Strings from Calc to .txt

Post by kingfisher »

You could use the CONCATENATE function or simply =A1&B1&C1&D1

Copy and special paste to another column. De-select 'formulas' in the dialogue. Copy and paste the new column to your text document. (You may be able to copy and paste the formulas column straight to a text document; I forget.)
Apache OpenOffice 4.1.9 on Linux
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Getting Strings from Calc to .txt

Post by acknak »

You can use something like this to have more control over how the text is put together:

[No.] & " named " & [Name] & " from " & [Startpoint] & " to " & [Endpoint]

As an actual formula, you need the cell references in there, of course. Something like:

=A1 & " named " & B1 & " from " & C1 & " to " & D1

You can copy that to include all your raw data, then export the formatted data to a text file: File > Save As, file type = "Text (CSV)".
AOO4/LO5 • Linux • Fedora 23
pechart
Posts: 3
Joined: Fri Jan 25, 2008 10:54 pm

Re: Getting Strings from Calc to .txt

Post by pechart »

Nice, thanks for your help! Works really good. One more Question then, what is the syntax for embedding a " in that string? like

=A1&" -proj "c:\documents and settings\" "&B2

I really appreciate your help! You don't know how much this speeds up my workflow, bacause I have to set up a whole bunch of commandlines in that style, that otherwise would take me hours or even days. Now i can enter the formula once and paste it through the whole document with automaticaly changing values. Awesome!

Oh, and one (hopefully) last question: Is there a way to declare variables like

string $mr=" -r blablabla";

and then use that in the formula?

Anyway, thanks again.
User avatar
Hagar Delest
Moderator
Posts: 32658
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Getting Strings from Calc to .txt

Post by Hagar Delest »

pechart wrote:what is the syntax for embedding a " in that string? like
=A1&" -proj "c:\documents and settings\" "&B2
What I would do is to put the following code in a cell and then refer to the cell instead of the code itself (note the single quote at the beginning)

Code: Select all

' -proj "c:\documents and settings\"
pechart wrote:Oh, and one (hopefully) last question: Is there a way to declare variables like
string $mr=" -r blablabla";
and then use that in the formula?
Don't know if it's possible but I would rather put the string "-r blablabla" in a cell and refer to that cell when needed in a formula. Cells are containers that act like a variable.

Thanks to add '[Solved]' in your first post title (edit button) if your issue has been fixed.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
pechart
Posts: 3
Joined: Fri Jan 25, 2008 10:54 pm

Re: Getting Strings from Calc to .txt

Post by pechart »

Thanks again. Good point, that the cell is a container... That will work.
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: [Solved] Getting Strings from Calc to .txt

Post by acknak »

You can include double quotes in a string constant by typing two quotes together:

="A hollow voice said ""Plugh"""

Right, cells are the containers, but you can easily use them as variables by giving the cell a name. This is a good practice, but often overlooked because it takes some time to set it up. Calc also may bite you at some point, because it has not been thorough treated to make everything work with names in place of a cell address. It's probably 95% there, so it's still useful.

Cell names are good for fixed references, whereas in your example you have columns of data. The reference needs to reference a relative location. You can set up column labels for that case:
col_labels.png
col_labels.png (6.26 KiB) Viewed 3061 times
Calc will automatically find the column labels, but it seems to get confused in this case. I had to use Insert > Names > Labels to specifically tell it that A1:D1 are the labels for the data in A2:D4.
AOO4/LO5 • Linux • Fedora 23
User avatar
kingfisher
Volunteer
Posts: 2123
Joined: Tue Nov 20, 2007 10:53 am

Re: [Solved] Getting Strings from Calc to .txt

Post by kingfisher »

pechart wrote:Is there a way to declare variables like string $mr=" -r blablabla";
and then use that in the formula?
Possibly. Menu: Insert >Names >Define. I've only used it for assigning names to formulas (or to ranges) but I think you could assign a name to a string.
Apache OpenOffice 4.1.9 on Linux
Post Reply