I have a google script which is returning the values [[All columns], [], [], [], [], [],…
- User
I have a google script which is returning the values [[All columns], [], [], [], [], [], [], [Values], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []] while I'm performing a normal getrange function var DataRange = ss.getRange("Handler Information!B:B").getValues() What could be the reason I don't get the correct data?
- Assistant
The reason you are not getting the correct data is that the "getValues()" function returns a two-dimensional array, even if you are retrieving data from a single column range.
To access the values correctly in your case, you need to specify the column index when accessing the array. Here is an example:
var DataRange = ss.getRange("Handler Information!B:B").getValues(); var columnData = DataRange.map(function(row) { return row[0]; // Accessing the first (and only) element of each row });In the above code, the "map()" function is used to iterate through each row in the "DataRange" array and access the first element (column B) of each row. This will result in an array containing only the values from column B.
By doing this, you will be able to correctly retrieve the data from the range "Handler Information!B:B" and get rid of the empty array elements.
- User
this is not solving the problem, I get now [All columns, , , , , , , Values, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ] as output but still not the values from that specific column
- Assistant
I apologize for the confusion. It seems that the issue lies with the spreadsheet itself and not with the script.
Here are a few things you can check:
- Make sure the sheet name "Handler Information" is correct, including any leading or trailing spaces.
- Ensure that the column B range you are specifying ("Handler Information!B:B") is correct and does not include any empty rows or extra characters.
- Verify that the spreadsheet is not protected or restricted in any way that would prevent the script from accessing the data.
If none of the above solutions work, it would be helpful if you could provide more details about your specific script and the data in the spreadsheet, so that I can assist you further.
- User
all information seems correct. Column B is containing empty cells but only at the bottom of the page. The dataset is however an extract from a bigquery data connector. Can this be the reason? If yes, how to solve it?
- Assistant
If the data in column B is extracted from a BigQuery data connector and there are empty cells at the bottom, it's possible that the empty cells are being recognized as valid values by the
getValues()function.You can try the following approaches to handle this issue:
- Trim or clean the data: You can modify the code to remove any empty rows or empty values at the bottom of the column using the
filter()orslice()functions. Here's an example:
var DataRange = ss.getRange("Handler Information!B:B").getValues(); var columnData = DataRange.map(function(row) { return row[0]; }).filter(function(value) { return value !== ""; // Filter out empty values });- Detect the last row with values: You can use
getLastRow()function to determine the last row with values in the column and retrieve only that range. Here's an example:
var sheet = ss.getSheetByName("Handler Information"); var lastRow = sheet.getLastRow(); var DataRange = sheet.getRange(1, 2, lastRow).getValues(); // Retrieve values up to last row var columnData = DataRange.map(function(row) { return row[0]; }); - Trim or clean the data: You can modify the code to remove any empty rows or empty values at the bottom of the column using the
- User
still having the same issue, for me it's not necessary to filter out the empty values, I just want to retrieve ALL values. Now i'm getting no usable result at all
- Assistant
I apologize for the confusion. If you want to retrieve all values from column B, including the empty cells at the bottom, you can modify the code as follows:
var sheet = ss.getSheetByName("Handler Information"); var lastRow = sheet.getLastRow(); var DataRange = sheet.getRange("B1:B" + lastRow).getDisplayValues(); var columnData = DataRange.map(function(row) { return row[0] !== "" ? row[0] : ""; // Keep empty values as empty strings });In this code, I used the
getDisplayValues()method instead ofgetValues()because it returns the formatted display values. Then themap()function is used to iterate through the values and keep the empty values as empty strings.By using this code, you should be able to retrieve all the values from column B, including empty cells at the bottom, while still keeping the array intact.
- User
getdisplayvalues is also not returning any values from the bigquery extract
- Assistant
I apologize for the confusion earlier. If the
getRange("Handler Information!B:B").getValues()method is not returning the values from the BigQuery extract, and thegetRange("Handler Information!B:B").getDisplayValues()method is also not working, it might indicate an issue with how the data is being imported into the sheet or the format of the data itself.You can try the following steps to troubleshoot the problem:
- Confirm that the BigQuery extract is correctly imported into the "Handler Information" sheet and that the data is visible.
- Double-check that the column B range ("Handler Information!B:B") accurately corresponds to the column where the values from the BigQuery extract are present.
- Verify that there are no additional factors affecting the visibility of the data, such as filtering or hidden rows or columns.
If none of the above steps resolve the issue, it would be helpful to have more information about how the data is imported and the format of the data itself. Additionally, if you can provide a sample of the data, it would aid in further troubleshooting.
- User
the issue seemed to be a filter on the extracted data, thx
- Assistant
I'm glad to hear that the issue was resolved! It's possible that a filter on the extracted data was causing the problem by hiding certain rows. Removing the filter allowed the
getRange().getValues()method to retrieve all the data correctly. If you have any further questions or need any additional assistance, feel free to ask.