ADO.NET Provider for Google Sheets

Build 20.0.7654

SELECT INTO ステートメント

SELECT INTO ステートメントを使って、書式付きデータをファイルにエクスポートできます。

SQL クエリを使ったデータのエクスポート

次のクエリは、comma-separated values(CSV)ファイルフォーマットにデータをエクスポートします。

C#

String connectionString = "InitiateOAuth=GETANDREFRESH;Spreadsheet=NorthwindOrders";

using (GoogleSheetsConnection connection = new GoogleSheetsConnection(connectionString)) {
  GoogleSheetsCommand cmd = new GoogleSheetsCommand("SELECT Id, Column1 INTO [csv://Spreadsheet1_Sheet1.txt] FROM [Spreadsheet1_Sheet1] WHERE Column2 = 'Bob' ", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "InitiateOAuth=GETANDREFRESH;Spreadsheet=NorthwindOrders" 

Using connection As New GoogleSheetsConnection(connectionString)
  Dim cmd As New GoogleSheetsCommand("SELECT Id, Column1 INTO [csv://Spreadsheet1_Sheet1.txt] FROM [Spreadsheet1_Sheet1] WHERE Column2 = 'Bob'", connection)
  Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using
URI で他のファイルフォーマットを指定できます。以下の例は、tab-separated values(TSV)にエクスポートします。

C#

String connectionString = "InitiateOAuth=GETANDREFRESH;Spreadsheet=NorthwindOrders";

using (GoogleSheetsConnection connection = new GoogleSheetsConnection(connectionString)) {
  GoogleSheetsCommand cmd = new GoogleSheetsCommand("SELECT * INTO [Spreadsheet1_Sheet1] IN [csv://filename=c:/Spreadsheet1_Sheet1.csv;delimiter=tab] FROM [Spreadsheet1_Sheet1] WHERE Column2 = 'Bob'", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "InitiateOAuth=GETANDREFRESH;Spreadsheet=NorthwindOrders" 

Using connection As New GoogleSheetsConnection(connectionString)
  Dim cmd As New GoogleSheetsCommand("SELECT * INTO [Spreadsheet1_Sheet1] IN [csv://filename=c:/Spreadsheet1_Sheet1.csv;delimiter=tab] FROM [Spreadsheet1_Sheet1] WHERE Column2 = 'Bob'", connection)
  Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using

Copyright (c) 2020 CData Software, Inc. - All rights reserved.
Build 20.0.7654