Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8121531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:31:18+00:00 2026-06-06T05:31:18+00:00

i have a short script where i’m trying to grab data from a URL

  • 0

i have a short script where i’m trying to grab data from a URL and write it to a sheet of an existing spreadsheet. the script is as follows:

function urlDataImport() {
  var input = "https://reports.acc-q-data.com/clientreports/ecaldwell_201206192722/ecaldwell_20122722.txt";
  // The code below gets the HTML code.
  var response = UrlFetchApp.fetch(input);
  var data = response.getContentText();
  Logger.log(data);
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var ptSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("pt");
  ptSheet.getActiveRange().setValues(data);
}

the information in data is tab delimited and shows up properly in the log but because it’s a string i can’t use .setValues to write it to the sheet pt and i’m not sure how to get the information from the URL in any other way.

i’m sorry for the rudimentary nature of this question but i’m very new to scripting so any help would be appreciated.

Updated Code:

function ptDataImport() { 
  var input = "https://reports.acc-q-data.com/clientreports/ecaldwell_201206192722/ecaldwell_2012062.txt";  
  var response = UrlFetchApp.fetch(input);  // Get the data from the URL as an object.
  var data = response.getContentText();  // Convet the object to text
  var dataSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("pt");  // Get the sheet to write the data to  
  var rows = data.split('\n');  // Splits the text into rows
  dataSheet.clear();
  var dataSet = new Array();
  for ( var i in rows){
    dataSet[i] = rows[i].split('\t'); // Split the rows into individual fields and add them to the 2d array
  }
  dataSet.pop(); // Had a blank row at the bottom that was giving me an error when trying to set the range - need to make this conditional somehow
  var numColumns = dataSet[0].length;
  var numRows = dataSet.length;
  var lastRow = dataSet[(numRows -1)];
  dataSheet.getRange(1,1,numRows,numColumns).setValues(dataSet);  // Get a range the size of the data and set the values
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:31:22+00:00Added an answer on June 6, 2026 at 5:31 am

    @Serge, I think Evan’s question was different. Evan is concerned that the split does not take rows into consideration.

    The solution to that is to use two splits. First,

    var rows = data.split('\n'); 
    

    And then

    for ( var i in rows){
      tmp = rows[i].split('\t'); // Use Serge's method if this doesn't work
      /* Get the range here */
      range.setValues([tmp]); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very painful slow script that gets lots of data from MySQL
I'm trying to figure out how to have a short, one line conditional statement.
I have written this short script (which I've stripped away some minor detail for
I have a script (KSH script to be precise) that downloads 3 files from
I have a short script to start my application (it invokes java with some
I have a very short tutorial perl script: #!/usr/bin/perl print The date is ,`date`;
I have written a short python script that opens Google music in web view
So I wrote this short script (correct word?) to download the comic images from
I have a short question, please :) I have a script where i make
I have a question about PHP require() function. I have a PHP script called

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.