概要
cscの作法、調べてみた。
練習問題やってみた。
練習問題
Excelで、列幅と行の高さを設定せよ。
サンプルコード
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), "Book8.xlsx");
var wb = new XLWorkbook();
var sheet = wb.Worksheets.Add("Sheet1");
sheet.Cell("A1").Value = "中央揃え";
sheet.Cell("A1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
sheet.Cell("A2").Value = "下詰め";
sheet.Cell("A2").Style.Alignment.Vertical = XLAlignmentVerticalValues.Bottom;
sheet.Cell("A3").Value = "インデント=2";
sheet.Cell("A3").Style.Alignment.Indent = 2;
sheet.Cell("A4").Value = "折り返して全体を表示";
sheet.Cell("A4").Style.Alignment.WrapText = true;
sheet.Cell("A5").Value = "縮小して全体を表示";
sheet.Cell("A5").Style.Alignment.ShrinkToFit = true;
sheet.Cell("A6").Value = "45度";
sheet.Cell("A6").Style.Alignment.TextRotation = 45;
sheet.Cell("A7").Value = "縦方向";
sheet.Cell("A7").Style.Alignment.TopToBottom = true;
sheet.Cell("A8").SetValue("メソッドで設定")
.Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center)
.Alignment.SetVertical(XLAlignmentVerticalValues.Center)
.Alignment.SetTextRotation(45);
sheet.Cell("C5").Value = "aqua";
sheet.Cell("C5").Style.Fill.BackgroundColor = XLColor.Aqua;
sheet.Cell("C8").Value = "widtht";
sheet.Cell("C8").Style.Font.FontColor = XLColor.Tomato;
sheet.Cell("C9").Value = "height";
sheet.Cell("C9").Style.Font.FontColor = XLColor.Tomato;
sheet.Cell("C10").Value = "point";
sheet.Cell("C10").Style.Font.FontSize = 40;
sheet.Column("C").Width = 50;
sheet.Row(10).Height = 50;
wb.SaveAs(filePath);
Console.WriteLine("ok");
}
}
}
写真
以上。