Ad
Replace NULL Values When Importing CSV In A Spreadsheet
With this code I can import from a CSV to my sheet.
Now, I would avoid to display NULL values in the cells and replace them with an empty value.
What I could add to the code I use?
function testf() {
var response = UrlFetchApp.fetch("https://xxx.csv");
var ss = SpreadsheetApp.getActiveSpreadsheet();
var dest = ss.getActiveSheet();
SpreadsheetApp.flush();
var req = { pasteData: { data: response.getContentText(), delimiter: ",", coordinate: { sheetId: dest.getSheetId() } } };
Sheets.Spreadsheets.batchUpdate({requests: [req]}, ss.getId());
}
Ad
Answer
From Now, I would avoid to display NULL values in the cells and replace them with an empty value.
, if you want to replace NULL
in the cells with the empty value, how about the following modification?
Modified script:
function testf() {
var response = UrlFetchApp.fetch("https://xxx.csv");
var ss = SpreadsheetApp.getActiveSpreadsheet();
var dest = ss.getActiveSheet();
SpreadsheetApp.flush();
var sheetId = dest.getSheetId();
var reqs = [
{ pasteData: { data: response.getContentText(), delimiter: ",", coordinate: { sheetId } } },
{ findReplace: { find: "NULL", replacement: "", sheetId } }
];
Sheets.Spreadsheets.batchUpdate({ requests: reqs }, ss.getId());
}
- In this modification, after the CSV was inserted, the value of
NULL
in the cells is replaced with""
using the batchUpdate method. In this case, this request can be run by one API call. - In your script,
SpreadsheetApp.flush()
might not be required to be used.
Reference:
Ad
source: stackoverflow.com
Related Questions
- → OctoberCMS - Creating file attachment in seeder
- → Laravel save CSV file error
- → October CMS export data to CSV from backend
- → Importing large CSV files in MySQL using Laravel
- → VBA how do I edit cell contents based on contents of two other cells in same row
- → Rake task handle 404
- → Can I assign products to collections using csv in shopify?
- → Shopify customize order export csv file
- → Shopify import reviews via API?
- → Can files be updated and read using the JavaScript FileReader interface?
- → Export a list of users in OctoberCMS to CSV
- → Convert array to CSV including multi-line image
- → Shopify_api Ruby Gem not creating fulfillment
Ad