LoginSignup
0
0

cscの作法 その347

Posted at

概要

cscの作法、調べてみた。
練習問題、やってみた。

練習問題

closedxmlで書式を設定した、xlsxを作れ。

写真

image.png

サンプルコード


using System;
using System.IO;
using ClosedXML.Excel;

namespace App
{
	class Program {
		static void Main(string[] args) {
			var filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Book11.xlsx");
			var wb = new XLWorkbook();
			var ws = wb.Worksheets.Add("Sheet1");
			ws.Cell("A1").Style.NumberFormat.Format = "@";
			ws.Cell("B1").Value = "Hello, Excel!";
			ws.Cell("B1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right;
			ws.Cell("C1").Value = "0123456789";
			ws.Cell("D1").Value = "0123456789";
			ws.Cell("D1").Style.NumberFormat.Format = "@";
			ws.Cell("E1").Value = 0123456789;
			ws.Cell("E1").Style.NumberFormat.Format = "@";
			ws.Cell("F1").SetValue("0123456789").Style.NumberFormat.SetFormat("@");
			ws.Cell("G1").SetValue(0123456789).Style.NumberFormat.SetFormat("@");
			ws.Cell("A2").Value = 0123456789;
			ws.Cell("A2").Style.NumberFormat.Format = "#,##0.0";
			ws.Cell("B2").Value = 123456789;
			ws.Cell("B2").Style.NumberFormat.Format = "#,##0";
			ws.Cell("C2").Value = "2345";
			ws.Cell("C2").Style.NumberFormat.Format = "#,##0.0";
			ws.Cell("A3").Style.NumberFormat.Format = "yyyy/mm/dd";
			ws.Cell("B3").Value = "2017/08/01";
			ws.Cell("B3").Style.NumberFormat.Format = "yyyy/mm/dd";
			ws.Cell("C3").Value = "2017/08/02";
			ws.Cell("D3").Value = "DATE";
			ws.Cell("D3").Style.NumberFormat.Format = "yyyy/mm/dd";
			ws.Cell("A4").Style.NumberFormat.Format = "HH:mm:ss";
			ws.Cell("B4").Value = "13:14:01";
			ws.Cell("B4").Style.NumberFormat.Format = "HH:mm:ss";
			ws.Cell("C4").Value = "13:15:01";
			ws.Cell("D4").Value = "TIME";
			ws.Cell("D4").Style.NumberFormat.Format = "HH:mm:ss";
			wb.SaveAs(filePath);
			Console.WriteLine("ok");
		}
	}
}





以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0