Skip to content

Instantly share code, notes, and snippets.

@anakahala
Created December 20, 2021 23:38
Show Gist options
  • Select an option

  • Save anakahala/fe2c74627c7b8abfea367061b5e258b9 to your computer and use it in GitHub Desktop.

Select an option

Save anakahala/fe2c74627c7b8abfea367061b5e258b9 to your computer and use it in GitHub Desktop.
ClosedXMLSample
using ClosedXML.Excel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClosedXmlSample
{
class Program
{
static void Main(string[] args)
{
// ExcelのBookを生成する
using(var book = new XLWorkbook()) {
// BookにSheetを追加
var sheet = book.Worksheets.Add("Sample Sheet");
// B列の幅を変更
sheet.Columns("B").Width = 50;
// B2に文字を設定する
sheet.Cell("B2").Value = "Closed XML Sample";
// B2の罫線を設定する
sheet.Range("B2").Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
// B2の罫線の色を設定する
sheet.Range("B2").Style.Border.OutsideBorderColor = XLColor.Red;
// Bookを保存
book.SaveAs(@"C:\work\sample.xlsx");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment