0

I have a data-set in Google Sheets that needs to be rearranged. I have data across multiple rows and columns that I would like to be pasted onto a single row, sequentially, following a logic of left to right per row, then proceed downwards for each row.

The amount of initial rows varies per entry, so ideally, I would highlight the number of rows and the output would respond accordingly. The quantity of columns containing values will be 4 cells per row.

An example of the initial state

Initial State

An example of the desired state

enter image description here

I would like to write this myself, as the logic is not complex, but I have never programmed with JavaScript, which, to my understanding, is the only language for Google Apps Scripts. Is there a way to write these scripts in Python, Java, and or C, and use them with Google Sheets? Those are the languages I'm more familiar with.

1
  • All you need to do is to flatten out the array
    – Cooper
    Oct 25 at 1:53

2 Answers 2

0
function myFunck() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName("Sheet0");
  const vs = sh.getRange(1, 1, sh.getLastRow(), sh.getLastColumn()).getValues().flat();
  const osh = ss.getSheetByName("Sheet1");
  osh.clearContents();
  osh.getRange(1, 1, 1, vs.length).setValues([vs]);
}
0

Google Apps Script only uses JavaScript, but ou can use the Google Sheets API with almost any programming language. To learn about it, go to https://developers.google.com/sheets. More specifically, go to https://developers.google.com/sheets/api/guides/concepts

Notes:

You might use TypeScript under certain conditions because TypeScript is a variant of JavaScript.

You might use any run time to create Google Workspace add-ons, including add-ons for Google Sheets. Don't confuse Workspace add-ons with Editor add-ons; the Editor add-ons can only be made using Apps Script.

If you want to handle your "scripts" from the Google Sheets user interface, the supported way is through Google Apps Script. You might try to use a web browser automation framework like Selenium, but it will likely require you to learn more things instead of fewer.

Spend some time learning about Google Colaboratory, https://colab.google/. In a very simplistic way, it's a web app for scripting that uses Python.

2
  • Thank you! So to clarify, when I click "Extensions" in Google Sheets, are the "Add-Ons" listed there Workspace, Editor, or both Add-Ons? Oct 24 at 19:26
  • It should not take too long to figure it out by yourself. Comments are intended to ask for clarification and provide feedback to improve a post. Follow-up questions should be posted as a new question on a site where they are on-topic.
    – Rubén
    Oct 24 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.