Use*_*234 8 .net c# google-api google-sheets
我想将现有的Google文档电子表格复制到新的Google文档电子表格中.我不认为v2.0 .NET API本身可以处理它(或者如果是这样我找不到类/方法),但是它看起来像v3.0协议可以,但我不知道如何在当前的框架,或者即使有可能使用当前的.net api.例如.~DocumentsFeed.copy()(伪代码).
导出到临时excel文件然后使用新名称上传是不可能的,因为一些复杂的公式在转换过程中搞砸了.
我是一个.NET菜鸟所以任何信息将非常感激,例如.如果我只能使用v3协议(ajax等)而不是.NET API,我将如何在.NET中执行此操作.
谢谢
编辑:(最后的课程感谢@langsamu的帮助!)
using System;
using Google.GData.Documents;
using Google.GData.Client;
using Google.GData.Extensions;
public class GoogleDocument
{
private DocumentsService ds;
private String username;
private String password;
public GoogleDocument(String username, String password)
{
this.ds = new DocumentsService("doc service name");
this.username = username;
this.password = password;
this.ds.setUserCredentials(username, password);
this.ds.QueryClientLoginToken();
}
public void copyDocument(String oldFileName, String newFileName)
{
SpreadsheetQuery query = new Google.GData.Documents.SpreadsheetQuery();
query.Title = oldFileName;
query.TitleExact = true;
DocumentsFeed feed = this.ds.Query(query);
AtomEntry entry = feed.Entries[0];
entry.Title.Text = newFileName;
var feedUri = new Uri(DocumentsListQuery.documentsBaseUri);
this.ds.Insert(feedUri, entry);
}
}
Run Code Online (Sandbox Code Playgroud)
Google.GData.Documents.DocumentsService service = new Google.GData.Documents.DocumentsService("YOUR_APPLICATIONS_NAME");
service.setUserCredentials("YOUR_USERNAME", "YOUR_PASSWORD");
Google.GData.Documents.SpreadsheetQuery query = new Google.GData.Documents.SpreadsheetQuery();
query.Title = "YOUR_SPREADSHEETS_TITLE";
query.TitleExact = true;
Google.GData.Documents.DocumentsFeed feed = service.Query(query);
Google.GData.Client.AtomEntry entry = feed.Entries[0];
var feedUri = new Uri(Google.GData.Documents.DocumentsListQuery.documentsBaseUri);
service.Insert(feedUri, entry);
Run Code Online (Sandbox Code Playgroud)
该解决方案基本上是关于service.Query使用文档列表 API检索现有电子表格 ( )并重新插入它 ( service.Insert)。
确保替换 ALL CAPS 应用程序名称、用户名、密码和电子表格标题。
添加对 Google.GData.Documents 的引用。
这是使用 .NET 4(也应该适用于较低版本)和Google Documents List Data API v2.0(DLL 表示版本为 1.6.0.0: google-gdata),它似乎使用了该协议的 3.0 版。
| 归档时间: |
|
| 查看次数: |
4841 次 |
| 最近记录: |