概要
cscの作法、調べてみた。
練習問題、やってみた。
練習問題
closedxmlでsqliteを流し込んだ、xlsxを作れ。
写真
サンプルコード
using System;
using System.Text;
using System.IO;
using System.Data;
using System.Data.Common;
using System.Transactions;
using System.Data.SQLite;
using ClosedXML.Excel;
namespace App
{
	class Program {
		static void Main(string[] args) {
			var filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Book8.xlsx");
			var wb = new XLWorkbook();
			var ws = wb.Worksheets.Add("Sheet1");
			int i = 1;
			ws.Cell(i, 1).Value = "Id";
			ws.Cell(i, 2).Value = "Name";
			ws.Cell(i, 3).Value = "Number";
			ws.Cell(i, 4).Value = "Price";
			SQLiteConnectionStringBuilder ConnectionStr = new SQLiteConnectionStringBuilder();
			ConnectionStr.DataSource = "db0.sqlite";
			using (SQLiteConnection Connection = new SQLiteConnection(ConnectionStr.ToString()))
			{
				Connection.Open();
				using(SQLiteCommand Command = new SQLiteCommand(Connection))
				{
					Command.CommandText = "SELECT * FROM fruit ORDER BY id ASC";
					using (SQLiteDataReader Reader = Command.ExecuteReader())
					{
						while (Reader.Read())
						{
							i++;
							string Id = Reader.GetInt32(0).ToString();
							string Name = Reader.GetString(1);
							string Number = Reader.GetInt32(2).ToString();
							string Price = Reader.GetInt32(3).ToString();
							ws.Cell(i, 1).Value = Id;
							ws.Cell(i, 2).Value = Name;
							ws.Cell(i, 3).Value = Number;
							ws.Cell(i, 4).Value = Price;
						}
					}
				}
			}
			wb.SaveAs(filePath);
			Console.WriteLine("ok");
		}
	}
}
以上。

