I'd like to copy each line and paste 5 times

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
GeorgeAnto
Posts: 5
Joined: Fri Mar 01, 2019 10:28 pm

I'd like to copy each line and paste 5 times

Post by GeorgeAnto »

I have a long list of items (exported from our WooCommerce Products database) that I'd like to be able to upload as a feed.

What I'd like to do is copy each line and then make certain modifications and paste beneath the original line 5 times.

For example :

TITLE — SKU — LINK — HEIGHT — WIDTH — PARENT/CHILD — PARENT SKU - PRICE
art1 — sku495483 — www.artsale.com/art1/ — 44 — 36 — parent — n/a — 250

I'd like to copy this and modify the following fields : title, sku, parent/child, parent sku & price.

Changes to be made :
• Title becomes same with addition of "with brushtrokes" afterwards
• sku becomes same with addition of "-bs" after it
• parent/child becomes "child"
• parent sku gets filled with the product SKU
• price = price + 60

And then I'd like similar lines pasted with different variations.... ie. "with frame" instead of "with brushstrokes", etc

How is this possible?

Thanks very much,
George
OpenOffice 4.16 / Mac OS X High Sierra 10.13.6
JeJe
Volunteer
Posts: 2784
Joined: Wed Mar 09, 2016 2:40 pm

Re: I'd like to copy each line and paste 5 times

Post by JeJe »

You can use the split function to separate the items from line
items = split(line," — ")
so
items(0)="art1"
items(1)= "sku495483"
etc

then

items(0)= items(0) & "with brushtrokes"
items(1)= items(1) & "-bs"

etc
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
GeorgeAnto
Posts: 5
Joined: Fri Mar 01, 2019 10:28 pm

Re: I'd like to copy each line and paste 5 times

Post by GeorgeAnto »

Thank you for the information... although I'm afraid I don't know how to do the first part, which is copy each row and paste it 5 times with the changes? Is this something obvious... I'm pretty much a newbie to macros... so all help is welcome!

Thanks again!
OpenOffice 4.16 / Mac OS X High Sierra 10.13.6
JeJe
Volunteer
Posts: 2784
Joined: Wed Mar 09, 2016 2:40 pm

Re: I'd like to copy each line and paste 5 times

Post by JeJe »

I'm presuming you have a text file with those lines in?
What you mean by "upload as a feed" and what document you are putting it into - a Calc one?
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
GeorgeAnto
Posts: 5
Joined: Fri Mar 01, 2019 10:28 pm

Re: I'd like to copy each line and paste 5 times

Post by GeorgeAnto »

I will place a few lines of what I plan to use. We have around 9000 products that I'd like to build a feed with for sending to Amazon. But each product also have 5 variations, thus I want to copy each line and make the appropriate changes when it's pasted in the 5 times for each type of variation.

Here is a sample of the first few lines attached as a ODS file.
Attachments
test-mini-feed.ods
(30.77 KiB) Downloaded 195 times
OpenOffice 4.16 / Mac OS X High Sierra 10.13.6
GeorgeAnto
Posts: 5
Joined: Fri Mar 01, 2019 10:28 pm

Re: I'd like to copy each line and paste 5 times

Post by GeorgeAnto »

Thanks..! please let me know if this needs clarification. Thanks!
OpenOffice 4.16 / Mac OS X High Sierra 10.13.6
JeJe
Volunteer
Posts: 2784
Joined: Wed Mar 09, 2016 2:40 pm

Re: I'd like to copy each line and paste 5 times

Post by JeJe »

Don't know much about spreadsheets, someone else might be able to help more. Here is a thread on copying rows:

viewtopic.php?f=20&t=11955

and accessing cells to change the contents:

https://wiki.openoffice.org/wiki/Docume ... s_directly

If you try and make a start on writing your code then someone might be able to help you with where you get stuck. Doing something 5 times is just a question of a loop

for i = 1 to 5
'what you want to do here
next
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
GeorgeAnto
Posts: 5
Joined: Fri Mar 01, 2019 10:28 pm

Re: I'd like to copy each line and paste 5 times

Post by GeorgeAnto »

Thanks very much! I'll check all that out and appreciate your help!
OpenOffice 4.16 / Mac OS X High Sierra 10.13.6
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: I'd like to copy each line and paste 5 times

Post by Villeroy »

test-mini-feed2.ods
(21.71 KiB) Downloaded 199 times
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