using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
namespace ReadingExcel
{
public class Program
{
public static void Main(string[] k)
{
string connectionString = @"Provider= Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\SaiKiran\Desktop\MyExl.xlsx;Extended Properties=Excel 12.0 Xml";
//Create the connection
System.Data.OleDb.OleDbConnection excelConnection = new System.Data.OleDb.OleDbConnection(connectionString);
string excelQuery = @"Select * from [Sheet1$]";
//string excelQuery1 = @"Select * from [Sheet1$]";
System.Data.OleDb.OleDbCommand excelCommand = new System.Data.OleDb.OleDbCommand(excelQuery, excelConnection);
excelConnection.Open();
System.Data.OleDb.OleDbDataReader excelReader;
excelReader = excelCommand.ExecuteReader();
while (excelReader.Read())
{
//Globals.Sheet1.Cells[1, 3] = "Set my data";
Console.WriteLine("id={0}", excelReader[0].ToString());
Console.ReadLine();
}
excelConnection.Close();
}
}
}
私のExcelには.xlsx形式の列A、B、Cがあります。現在のコードでは、現在1列しか読み取ることができません。すべての列を読み取るループか何かを教えてください。