Created
December 20, 2021 23:38
-
-
Save anakahala/fe2c74627c7b8abfea367061b5e258b9 to your computer and use it in GitHub Desktop.
ClosedXMLSample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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