Create a new Google Docs Spreadsheet from content using AJAX


This example shows how one could use jQuery to make an AJAX request that creates new Google Docs Spreadsheet from existing text/csv content. This particular examples uses ClientLogin
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"
        type="text/javascript"></script>

<script type="text/javascript">
var token = 'YOUR_CLIENTLOGIN_AUTH_TOKEN';

function constructContentBody(docTitle, docType, contentBody, contentType) {
  var atom = ["<?xml version='1.0' encoding='UTF-8'?>",
              '<entry xmlns="http://www.w3.org/2005/Atom">',
              '<category scheme="http://schemas.google.com/g/2005#kind"',
              ' term="http://schemas.google.com/docs/2007#', docType, '"/>',
              '<title>', docTitle, '</title>',
              '</entry>'].join('');
             
  var body = ['--END_OF_PART\r\n',
              'Content-Type: application/atom+xml;\r\n\r\n',
              atom, '\r\n',
              '--END_OF_PART\r\n',
              'Content-Type: ', contentType, '\r\n\r\n',
              contentBody, '\r\n',
              '--END_OF_PART--\r\n'].join('');
  return body;
}

function createSpreadsheetFromContent(title, content, contentType) {
  netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");

  $.ajax({
    type: 'POST',
    url: 'http://docs.google.com/feeds/documents/private/full',
    contentType: 'multipart/related; boundary=END_OF_PART',
    data: constructContentBody(title, 'spreadsheet', content, contentType),
    dataType: 'xml',
    beforeSend: function(xhr) {
      $('#data').html('uploading...');
      xhr.setRequestHeader('Authorization', 'GoogleLogin auth=' + token);
    },
    success: function(resp) {
      $('#data').html('Spreadsheet created!');
    }
  });
}
</script>
</head>
<body>

<div id="data"></div>

<button onclick="createSpreadsheetFromContent('ANewTitle', '1,2,3,4', 'text/csv')">Create spreadsheet w/ content</button>
</body>
</html>

35 comments:

Unknown said...

Thank you Eric. This helps a lot with the problem that we were working on earlier.

http://groups.google.com/group/Google-Docs-Data-APIs/browse_thread/thread/dbde4686bb338c54/8f8b4be80b830e93?pli=1

http://spanishgringo.blogspot.com

Unknown said...

Thank you for posting this, it formed the basis of an application I am working on.

I do have another question for you about it though, if you are able to help that is. What sort of characters are not allowed to be passed through this? I sometimes get an error [The reference to entity "I" must end with the ';' delimiter.]. Do you think a simple encodeURI( str ) would solve it?

FRAMEWeRKS said...

Um, no go.. "Method not allowed"

Uday said...

This is not working and when using browser gives error that cross domain post is not allowed(405 method not allowed). What is the work around for this. Did you test it before posting this?

dongsheng said...

Et voici la preuve photographique. Cette sneak peek [ci-dessus] illustre la stratgie d'tre abattu par l'oncle Karl lui-mme, et bien que nous tions secrtement cherche voir miss Dellal apportant ses battues cuirs noirs sur la campagne, shes regardant puissante dame comme porter un gilet blanc et arc dlicate dans leur cheveux tresss.

Thunk Whoda ci.
Mais ne vous inquitez pas, le bord marque Alices continue tre en raison de tact pour saisines de eye-liner noir en plus d'une lvre rouge vif. Le modle est perch sur une table de toilette l'intrieur d'un appartement somptueux haussmannien, tout en prsentant un sac main gris matelass avec la collection Sac Hermès Mini Plume. Nous sommes impatients d'en savoir vraiment ce blog.


Sac Hermès Shoulder Birkin

Microsoft Office said...

Outlook 2010 provides you with a world-class experience to maintain your efficiency and keep in touch with personal and business networks. You can use download Outlook 2010, through a rich set of features and custom communication with one or more recipients.

epictoon said...
This comment has been removed by the author.
avulsion fracture said...

Thank U For Your Article !

Unknown said...

Energy: energy is it? Effort of the uniqueness of a person, a physical, when a people tired of his refined gas will decline, but when a person is in the excited state, his energy is unlimited,diablo 3 items Wu now Monk completely contrary to the natural law. And monks only have the "energy" this kind of energy, I feel extremely unreasonable.

Unknown said...

Luckily, you will find but from and to someone guildwars 2 gold will be sick. The same old swill, with the gun barrel missed a number of, yet good-hearted conquer as well as alternatively opens up a new, more compact, however good quality barrel A replacement of today drums and liquids through buy guild wars 2 gold cheap, you get fast with regards to Mmo.

Cyntia Clara said...

Thank you for another essential article. Where else could anyone get that kind of information in such a complete way of writing? I have a presentation incoming week, and I am on the lookout for such information. Info Smartphone readmore

Unknown said...

LG Electronics 65LB6300 65-Inch 1080p 120Hz Smart LED TV
LG Electronics 60LB5900 60-Inch 1080p 120Hz LED TV
LG Electronics 55LB5900 55-Inch 1080p 120Hz LED TV
LG Electronics 47LB5900 47-Inch 1080p 120Hz LED TV
LG Electronics 42LB5600 42-Inch 1080p 60Hz LED TV
LG Electronics 39LB5600 39-Inch 1080p 60Hz LED TV
LG Electronics 32LB5600 32 Inch 1080p 60Hz LED TV

Unknown said...


jual rumah murah tasikmalaya
shorelinewa
bdo
bts
assembly
here
newportbeachca
prh
samhsa
fhwa
onlinewebcheck
nixonlibrary
newportbeachca
alliancecreditunion
nasa
spaceflight
planning
bcgolfpages
transtats

Unknown said...

Thank you for posting this, it formed the basis of an application I am working on.
I do have another question for you about it though, if you are able to help that is
--------------------------------
Văn Hệ - 0938 45 8080
Phòng Kinh Doanh Bánh trung thu Kinh Đô
Fanpage: https://www.facebook.com/banhtrungthu.info
Click nếu bạn quan tâm: Bánh Trung Thu Kinh Đô chính hãng giá sỉ tốt nhất mua ở đâu tại TPHCM
hoặc Banh trung thu kinh do chinh hang gia si tot nhat mua o dau tai tphcm

Unknown said...

Thank you!
-------------------------------------------
Trọng Nguyễn - 0938 458 080
Phòng Marketing
Fanpage: https://www.facebook.com/banhtrungthu.info
Click nếu bạn quan tâm: Bánh trung thu Như Lan giá sỉ chất lượng uy tín nhất ở TPHCM hoặc Banh trung thu nhu lan gia si chat luong uy tin nhat o TPHCM

Unknown said...

Bài viết rất hay, mong add có thể chia sẻ nhiều bài viết có nội dung hay hơn nữa. thank add
-------------------------------------------
Trọng Nguyễn - 0938 458 080
Phòng Marketing
Fanpage: https://www.facebook.com/banhtrungthu.info
Click nếu bạn quan tâm: Bánh trung thu Như Lan giá sỉ chất lượng uy tín nhất ở TPHCM hoặc Banh trung thu nhu lan gia si chat luong uy tin nhat o TPHCM

Unknown said...

Dich vu ke toan ACB chuyên cung cấp dịch vụ kế toán trọn gói uy tín chuyên nghiêp giá rẻ nhất tại HCM và các tỉnh lân cận với chi phí bỏ ra chỉ từ 500.000-1.500.000đ.
Liên hệ: Dich vu ke toan , Dịch vụ kế toán.
Lầu 4, Tòa nhà Long Mã, 602 Cộng Hòa,P.13,Q.Tân Bình,HCM.
Hotline: (08) 62 97 97 97 - 0966 660 888.

Unknown said...

I really thank the author of this article, the article has great significance for me, it just leads me to do better things for this life. Very meaningful, thank you very much, wish you happy
Mobimatic Review
Mobimatic App Builder
Mobimatic Bonus
Vid Reaper Bonus
Mobimatic App Builder
Mobimatic Bonus
Vid Reaper Bonus
Mobimatic App Builder
Mobimatic Bonus
Vid Reaper Bonus
Mobimatic App Builder
Mobimatic Bonus
Vid Reaper Bonus
Mobimatic App Builder
Mobimatic Bonus

Smith John Live said...

If you own an Android smartphone, then Google Cloud Print, HP Smart Print, and ‘ePrint’ let you print from anywhere with stable internet connection. For those who use an Apple device, Apple Airprint helps you do the same. It offers a monthly duty cycle of 50,000 pages which is exceptional. Moreover, it has a printing speed of 28 ppm. It also comes with device documentation, a power cable, and a USB cable. Besides, the printer comes with a CD to download the driver software for the printer. Although, it can also be downloaded from the official HP website.
Contact us to know more about the HP COLOR LASERJET PRO MFP M479 FDW Wireless Setup by calling our toll-free number.

Pemainayam.net said...

Jangan Lewatkan Event Bolavita Menyambut Natal & Tahun Baru 2019/2020 Bagi-Bagi Hadiah !
» Hp Samsung Galaxy S10
» Hp Vivo V17 Pro
» Hp Xiaomi Note 7
» Hp Oppo Reno 2
» Hp Advan G3

Promo Bonus Terbaru Agen Bolavita ! Partner Judi Online Terpercaya Di Indonesia Sejak 2014 !

★ Bonus 10% Deposit Pertama !
★ Bonus Deposit Harian 5%
★ Bonus Cashback Mingguan s/d 10%
★ Bonus Referral 7% + 2%
★ Bonus 100% (bila anda 8x menang secara beruntun)
★ Bonus Rollingan Mingguan 0.5% + 0.7%

Menyediakan Berbagai Jenis Taruhan Online Uang Asli :

» Taruhan Bola Online ( SBOBET / IBC BET / 368BET / NOVA88 / CBET )
» Casino Live ( Bakarat / Rolet / Dadu / Blacjkack / Dragon Tiger / )
» Sabung Ayam Live ( S128 / SV388 )
» Bola Tangkas
» Togel Online ( HK / SGP / KL )
» Tembak Ikan
» Slot / Ding - Dong ( JACKPOT )
» Poker Online

Link Pendaftaran : http://159.89.197.59/register/
Link Whatsapp 24 Jam : https://bit.ly/31SZvwy
Link Live Chat : https://bit.ly/2VD8fER

Lainnya :
» Judi Online Linkaja
» Taruhan Bola Liga Inggris
» Taruhan Bola Liga Eropa
» Judi Bola Over Under
» Tembak Ikan Online Uang Asli

#Linkaja

Andrew303john said...

Economics Assignment Help

We Fullassignment.com is among the best companies on the Economics assignment help writing market. We offer top-notch essays, Public Economics Assignment help research papers, thesis and other types of works that can be assigned to you at a high school or college. We also provide Psychology Assignment help from our experts.

https://fullassignment.com/

Ricky Martin said...

This blog presented itself in a very easy and clear way. The owner of this blog found a very simple way to express its view but when you read this blog completely, you would get to know about how hard it could be to express such in an easy way.

Mumbai Escorts
Bangalore Escorts
Kolkata Escorts
Chennai Escorts
Delhi Escorts

Pankaj Tripathi said...

Great content & Thanks for sharing with oflox. Do you now what is Voice Search SEO

ASK CARZ said...

Thru Wall

Air Conditioner

Travel Trailer Air Conditioner Units
Auto Air

Conditioner

Dyson

Air Conditioner Reviews

Upright

Window Air Conditioner

Slider

Window Air Conditioner

15 000 Btu

Air Conditioner

As Seen

On Tv Air Conditioner

Energy Efficient Air Conditioner Unit
Smallest

Btu Air Conditioner

Mumbai Escorts ( Sneha Singh ) said...

Hello, friends I am Sneha Singh from Mumbai and I am providing the best erotic service if you want to take and enjoy life with me then come here:-
Chennai Escorts
Coimbatore Escorts
Cuddalore Escorts
Dharmapuri Escorts
Dindigul Escorts
Erode Escorts

keith said...

Creative content thanks for sharing it
Canon Printer Error Code b204

Printer Repair City said...

Amazing, learn how to resolve Canon Printer Error u052 and solve canon printer error 6a81 Also canon printer error 5200 and this is good Canon Printer Error Code 1007 find out canon printer error e04 as well as canon printer error code p22

singapore assignment help said...

really appreciate your efforts in sharing this valuable information with us. make my thesis

Goodtime said...

Wonderful and useful, post, this so timely as it is very useful and relevant to the work i am currently on, this post has really made my day i must say, thank so much for sharing cut off mark for Nigerian Maritime University Okerenkoko, Delta State

onlineAssignmenthelp said...

We are here to provide you online SPSS support from the most trusted and trusted SPSS tutors. We provide students with excellent and quality support in completing SPSS assignments for a nominal fee. There are hundreds of SPSS assignment support providers online. But why are we the best of them? If you enlist your help in SPSS assignments, you will reap many benefits from us. You will get 24 * 7 online support. This means you can contact us around the clock.
Spss Assignment help

Leo Oliver said...


Finance is a branch of economics that deals with money. Our Finance Assignment Help consultants will make sure that your finance assignment is completed as fast as possible and that your financial assignment enhances your abilities. A team of our qualified authors composes financial assignment for students finance assignment writing service.

Unknown said...

https //ij.start.cannon
Install latest software and drivers of canon printer and plug in the USB cable to computer and printer. It’ll automatically be connected; however, you’ve to follow on-screen guidelines.
http //ij.start.canon

Unknown said...

Canon IJ Network Tool is a toolkit software with the options to keep a check on most of your Canon printer network settings and adjust them according to your requirements.

Canon IJ Printer Utility is a complete software package meant to adjust and modify the configurations of your printer device as per the requirement. It is one of the essential utility software offered by Canon to ease your printer configuration alteration using a few clicks.


Canon.com/ijsetup/mg2500
is the Canon support link to get you the latest printer drivers and software to set up your PIXMA MG2500 or MG2520.

Studytonight said...

Hi there, thank you for sharing such great informative post with us. It is really helpful.
ERR_CONNECTION_RESET
ePSXe Black Screen problem
NET::ERR_CERT_AUTHORITY_INVALID Error
MSVCP140.dll Missing Windows 10 error

The Dark Attitude said...

This content is really helpful and easy to understand, Thank you for sharing!
Gothic Clothing Uk