I have a google sheet where the cells in the first tab pull data from cells on the second tab.
for example Sheet1 cell A1 has =Sheet2!A1
This is true for every cell on Sheet1
When I do a File - Download As - Microsoft Excel (.xlsx)
It exports the cells with formulas. Is there a way to export the sheets as values and not formulas
In this case, Sheet1 cell A1 would not contain =Sheet2!A1 but the value of =Sheet2!A1?
You can copy your original google spreadsheet and, in the copy, change the formula for the first cell for each tab to import data from the original one:
=IMPORTRANGE("spreadsheet id","'tab name'!range")
Ex:
=IMPORTRANGE("1C-PS4wAHS8ssCNgVDfOsssREAz7PjuQGX23Rk0sssss","'measurement with spaces'!A12:F44")
The ID you can get via original spreadsheet URL:
https://docs.google.com/spreadsheets/d/1C-PS4wAHS8ssCNgVDfOsssREAz7PjuQGX23Rk0sssss/edit#gid=99999999
The exported xlsx file from the copy will have only the values
#fabceolins answer is simple and good for normal scenarios, i noticed however Excel will still contain reference to IMPORTRANGE formula which can cause access issues.
I created Google App script to copy in the following method.
If you can use Google App scripts, add the following functions:
function update_view(dup_id, TL="A1", BR="Z991") {
// Open current Sheet
var ss = SpreadsheetApp.getActiveSpreadsheet()
// Supply a duplicate google doc ID. This document will be exported to excel
var ds = SpreadsheetApp.openById(dup_id)
// UI element for notifying in the google sheets
var ui = SpreadsheetApp.getUi()
//Copy each sheet one by one
var sheets = ss.getSheets();
for (i=0; i<sheets.length; i++) {
src_sheet = sheets[i];
sheet_name = src_sheet.getName();
// If same sheet exists in the destination delete it and create an empty one
dst_sheet = ds.getSheetByName(sheet_name);
if (dst_sheet != null) {
ds.deleteSheet(dst_sheet)
}
dst_sheet = ds.insertSheet(sheet_name);
//set column width correctly
for(j=1; j<=src_sheet.getLastColumn(); j++){
dst_sheet.setColumnWidth(j, src_sheet.getColumnWidth(j))
}
src_range = src_sheet.getRange(TL + ":" + BR);
dst_range = dst_sheet.getRange(TL + ":" + BR);
//Note: DisplayValues is set as Values, formulas are removed in dup sheet
dst_range.setValues(src_range.getDisplayValues());
//Nice to haves for formatting
dst_range.setFontColors(src_range.getFontColors());
dst_range.setFontStyles(src_range.getFontStyles());
dst_range.setBackgrounds(src_range.getBackgrounds());
dst_range.setHorizontalAlignments(src_range.getHorizontalAlignments());
dst_range.setVerticalAlignments(src_range.getVerticalAlignments());
dst_range.setWraps(src_range.getWraps());
dst_contents_range = dst_sheet.getDataRange();
dst_contents_range.setBorder(true, true, true, true, true, true);
}
//Completed copy, Now open the dup document and export.
ui.alert("Backup Complete, Please open " + dup_id + " sheet to view contents.")
}
function update_mydoc_view(){
// https://docs.google.com/spreadsheets/d/<spreadsheet_id>/
update_view("<spreadsheet_id>")
}
To run the function, go to tools->macros->import , import the function and run update_mydoc_view().
After it is completed, export the google sheet into an excel document.
If you want to download a single sheet spreadsheet, instead of download it as .XLSX, download it as .CSV.
If by open the .CSV file by double clicking it shows strange characters, the default encoding of your computer is different from the one used by the Google servers, to fix this do the following:
Open Excel
Click File > Open
Select the .CSV file
The import wizard will be shown. One of the steps will allow you to select the file encoding, select UTF-8.
Once you finish with the import wizard save your file as .XLSX
Related
Microsoft Excel mangles Diacritics in .csv files?
Is it possible to force Excel recognize UTF-8 CSV files automatically?
I did the following and it worked for me :
Duplicate the file
CTRL+A > CTRL+X > CTRL + V Paste Value only (from the paste icon displayed after pressing CTRL+V)
If you want to keep only the values from Sheet1, just select the data in the sheet, copy it, open a new Excel work book and when you paste, rather than using the conventional hotkeys Ctrl+V, right click cell A1 and select Paste values under the Paste options category of the right click menu.
If the problem is that the downloaded Excel does not have functional formulas that take information from your second sheet and instead show the formulas as text, do what the previous commenter said. check your view to make sure you are not in formula view. use the hotkey Ctrl+ ~, or go to the view tab to check your view options.
By default this is what happens - you will see the values not the formula.
Are you sure you are not in formula view in Excel?
If you check "Show formula" it will switch in formula view.
Or generally speaking you can try those:
MS Excel showing the formula in a cell instead of the resulting value
I would be surprised if it was indeed a google sheet problem - it's about Excel display.
Related
I copy some text from Notepad++ and paste it into google sheets. It pastes it tab-delimited. I want it to be pasted as new-line delimited. Tabs shouldn't be taken into account for delimiting.
I tried by deleting extra columns, keeping just one. but it creates extra columns. In excel there is an option to import text with a required delimiter. In Google sheets, how to achieve this? If there is no such thing, can it be achieved via app-script?
Just in case. Here is the little snippet that splits contents of selected cell by lines and puts these lines into bottom cells:
function split_cell() {
var sheet = SpreadsheetApp.getActiveSheet();
var cell = sheet.getActiveRange();
var value = cell.getValue();
var cells = value.split('\n').map(x => [x]);
sheet.getRange(cell.getRow(),cell.getColumn(),cells.length).setValues(cells)
}
If you want to import the text from the txt file, you can simply choose the delimiter you want.
For instance, when using the Import option in Sheets:
You can select a custom separator:
However, if you are simply copying the text from the txt file, you may want to check the settings for the text editor you are using when it comes to the delimiter chosen.
Reference
Import data sets & spreadsheets.
I use importrange for combine 2 google sheet Target A and Source B
In sheet A =
Importrange(“linkgooglesheetB”,”SheetB!!A2:M1000)
It’s done
But when data in sheet Source B cleared/changed, then
Data in sheet Target A cleared/changed too
What formula can use same my above formula but data in Target A do not change after combined (A&B), when B changed.
Answer:
You can do this with Google Apps Script.
Explanation:
The IMPORTRANGE formula will always automatically update when the range from which it is importing had a data change. In fact, this is a feature of all sheet formulae; they are designed to keep everything up-to-date when data changes.
For this reason, you can not use a formula. You will have to do this using Google Apps Script.
Example code:
The idea is as such:
When the sheet is edited, a script will run.
If the cell data matches a certain pattern, then the script will paste in the data permanently, in the same way that IMPORTRANGE works.
function runOnEdit(e) {
// We will make the patten here. In this case, the text entered in the cell must be of the form:
// "IMPORT(link,range)
// example:
// IMPORT,https://docs.google.com/spreadsheets/d/some-id/edit, SheetB!A2:M1000
const patternStart = "IMPORT"
const compareVals = e.value.split(",")
if (compareVals.length != 3 || compareVals[0] != patternStart) return
try {
const ss = SpreadsheetApp.openByUrl(compareVals[1])
const importRange = compareVals[2].split('!')
const sheetName = importRange[0]
const range = importRange[1]
const sheet = ss.getSheetByName(sheetName)
console.log(sheetName)
console.log(range)
const data = sheet.getRange(range).getValues()
const formatting = sheet.getRange(range).getTextStyles()
const activeSheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
const row = e.range.getRow()
const col = e.range.getColumn()
activeSheet.getRange(row, col, data.length, data[0].length).setValues(data).setTextStyles(formatting)
}
catch (err) {
e.range.setValue(err)
}
}
Things to note:
The pattern can not start with an = as this will be read as a formula by Sheets and throw an error.
This must be set up as an installable trigger, as opening a separate Spreadsheet requires authorisation, which can not be done from a simple trigger.
You can install the trigger by clicking on the clock logo in the left toolbar from the Apps Script editor, then clicking + Add Trigger in the bottom right and using the following settings:
Choose which function to run: runOnEdit
Which runs at deployment: Head
Select event source: From spreadsheet
Select event type: On edit
Visual example:
Most of the formula is live update, including query function. However in order not to have your data change for importrange, there is two possible solution:
1)Create a backup sheet by copy paste data from the main sheet, and importrange from the backup sheet, so any change in main sheet will not have impact on your result
2)Write Google App Scrip to copy data, but it take time to learn
I am trying to create data validation dropdown from a single cell which has all , separated values and I am splitting them using SPLIT(K4,","). But when I apply the formula drop-down just goes away. Here is how it looks:
And here is where I have applied validation:
It just happens and I can't see any drop-down here. Even validation doesn't work as I type a value from given values, it still identifies it as invalid:
Here it says that it is actually not possible, but otherwise, my data column will grow very big, that's why I wanted to keep it in a single cell.
Method to reproduce: Just make a copy of this sheet and experiment on your own whatever you want it to be like:
It is not possible to do this from the sheets editor, but you could use Google Apps Script to accomplish this:
Open the script editor by selecting Tools > Script editor.
Copy and run this function:
function createDataValidation() {
const sheet = SpreadsheetApp.getActiveSheet();
const values = sheet.getRange("A1").getValue().split(","); // Get array with values from A1
const rule = SpreadsheetApp.newDataValidation().requireValueInList(values); // Create DV
sheet.getRange("F8").setDataValidation(rule); // Set DV to F8
}
Reference:
Class DataValidationBuilder
After making a copy of a google spreadsheet, I would like to have the copied spreadsheet automatically sync any changes made to the original spreadsheet. Is this already being done? If not, how do I make it so?
The syncing is only one-way -> from original to copied.
It will be a hassle make copies of the original spreadsheet whenever new changes are made.
To start, open up the spreadsheet or tab you want to copy to the new Sheet > copy the sheet’s URL
Make a note of the cells you want to import
Open the new sheet where you want the data to appear
In the cell begin to type > =IMPORTRANGE (you’ll see the code as you begin to type)
Type > quotation “ (very important) then paste the URL from the sheet and add another quotation mark at the end of the URL
Then add a comma , > quotation mark again “ > then type the exact name of the specific tab you want to copy followed by an exclamation mark!
Finally, type the range of cells you want to import eg: A1:A19 followed by “ quotation marks
Press > Enter and your data will now appear in your new Sheet
.
Examle:
IMPORTRANGE("https://docs.google.com/spreadsheets/d/abcd123abcd123", "sheet1!A1:C10")
IMPORTRANGE(A2,"B2")
.
For more information look HERE or HERE
I would like to open a specific sheet of a Google Sheets from a hyperlink in another spreadsheet.
I have different links in my master spreadsheet and each should have a hyperlink to the same slave spreadsheet but to a different sheet.
I know hyperlink function but it doesn't go to a specific sheet.
You can use this custom script (Tools > Script Editor) function and connect it with e.g. custom drawing (Insert > Drawing... > Save and Close, then right click on new drawing> Assign Script... > "goToSheet2")
function goToSheet2() {
goToSheet("Sheet2");
}
function goToSheet(sheetName) {
var sheet = SpreadsheetApp.getActive().getSheetByName(sheetName);
SpreadsheetApp.setActiveSheet(sheet);
}
Update:
In the newest version you can select cell and add link (Insert > Link) and select link to specific sheet directly:
The HYPERLINK function can link to another sheet in the same workbook; if you observe the URL of the spreadsheet, at the end of it there is #gid=x where x is unique for each sheet.
The problem is, it will open the sheet as a new instance of the spreadsheet in another tab, which is probably not desirable. The workaround would be to insert images or drawings as buttons, and assigning a script to them that will activate specific sheets.
I personnaly did this based on what #rejthy said:
In scripts I created this function:
/**
* Return the id of the sheet. (by name)
*
* #return The ID of the sheet
* #customfunction
*/
function GET_SHEET_ID(sheetName) {
var sheetId = SpreadsheetApp.getActive().getSheetByName(sheetName).getSheetId();
return sheetId;
}
and then in my sheet where I need the link I did this: =HYPERLINK("#gid="&GET_SHEET_ID("Factures - "&$B$1);"Année en cours")
So what I understand from the OP is that you have one master spreadsheet that you want to have links to individual sheets, where one or more of those sheets may be in single or multiple spreadsheet files.
The HYPERLINK function only turns a URL into a hyperlink and is really only useful when you want to have hypertext instead of just a link. If you enter the raw URL as the data, it's automatically turned into a hyperlink, so there's no additional work.
As mentioned in other answers, the solution is to have the spreadsheet's URL then use the gid value to calculate the link to the desired sheet within the spreadsheet. You can write a simple app that collects all of the individual sheets' links and writes them into the master.
Below are some snippets of pseudocode (Python) that can help you get started. I'm leaving out all the boilerplate auth code, but if you need it, see this blog post and this video. The code below assumes your API service endpoint is SHEETS.
This reads a target spreadsheet to build links for each of its sheets:
# open target Sheet, get all sheets & Sheet URL
SHEET_ID = TARGET_SHEET_DRIVE_FILE_ID
res = SHEETS.spreadsheets().get(spreadsheetId=SHEET_ID,
fields='sheets,spreadsheetUrl').execute()
sheets = res.get('sheets', [])
url = res['spreadsheetUrl']
# for each sheet, dump out its name & full URL
for sheet in sheets:
data = sheet['properties']
print('** Sheet title: %r' % data['title'])
print(' - Link: %s#gid=%s' % (url, data['sheetId']))
Instead of printing to the screen, let's say you stored them in a (name, URL) 2-tuple array in your app, so bottom-line, it looks something like this list called sheet_data:
sheet_data = [
('Intro', 'https://docs.google.com/spreadsheets/d/SHEET_ID/edit#gid=5'),
('XData', 'https://docs.google.com/spreadsheets/d/SHEET_ID/edit#gid=3'),
('YData', 'https://docs.google.com/spreadsheets/d/SHEET_ID/edit#gid=7')
]
You can then write them to the master (starting from the upper-left corner, cell A1) like this:
SHEET_ID = MASTER_SHEET_DRIVE_FILE_ID
SHEETS.spreadsheets().values().update(
spreadsheetId=SHEET_ID, range='A1',
body={'values': sheet_data},
valueInputOption='USER_ENTERED'
).execute()
Some caveats when using gid:
The first default sheet created for you (Sheet1) always has a gid=0.
Any sheets you add after that will have a random gid.
Don't bank on a gid=0 for the 1st sheet in your spreadsheets however as you or someone else may have deleted the original default sheet, like my example above.
If you want to see more examples of using the Sheets API, here are more videos I've made (along with posts that delve into each code sample):
Migrating SQL data to a Sheet plus code deep dive post
Formatting text using the Sheets API plus code deep dive post
Generating slides from spreadsheet data plus code deep dive post
Then when you open up the master in the Sheets UI, you can clickthrough to any of the individual sheets, regardless of which spreadsheet files they're in. If you want them automatically opened by another app or script, most programming languages offer developers a ways to launch a web browser given the target URL. In Python, it would be the webbrowser module (docs):
import webbrowser
webbrowser.open_new(url) # or webbrowser.open_new_tab(url)
Alternatively, you can try creating a custom function. With the spreadsheet open, click the Tools menu, then Script editor.... Paste the code into the editor:
/**
* Gets the Sheet ID from Sheet Name
*
* #param {string} input The Sheet Name
* #return The Sheet ID
* #customfunction
*/
function SHEETID(input) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var tab = ss.getSheetByName(input);
return tab.getSheetId();
}
Save, refresh the spreadsheet, and then type in your custom function
=SHEETID("Your Custom Sheet Name")
=SHEETID(A1)
And voila! The unique ID for the tab (in the current spreadsheet) is output. You can hyperlink to it by using the following formula:
=HYPERLINK("#gid="&SHEETID(A1),"Link")
In case you want to create a link to another sheet which will open the sheet in the same browser tab here is what you want to do:
1. Get the id of the sheet. Check the link in your browser and you will see #gid=x where x is the sheet id
2. Then you want to set the formula (hyperlink) to the cell and make it show as a hyperlink
SpreadsheetApp.getActiveSheet().getRange("A1").setFormula('=HYPERLINK("#gid=X","test")').setShowHyperlink(true);
If you don't use setShowHyperlink(true) it will be shown as a regular text.
This is basically a code version for the update provided by #rejthy above