Last active
July 17, 2016 14:44
-
-
Save kawa-xxx/3061cde3ecf03509d32875e96b6db398 to your computer and use it in GitHub Desktop.
ClosedXML のサンプル
This file contains 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
static void Main(string[] args) | |
{ | |
var path = ConfigurationManager.AppSettings["InputPath"]; | |
var outPath = ConfigurationManager.AppSettings["OutputPath"]; | |
var files = Directory.GetFiles(path); | |
var allRows = new List<AlertModel>(); | |
foreach (var file in files) | |
{ | |
using (var book = new XLWorkbook(file, XLEventTracking.Disabled)) | |
{ | |
var sheet = book.Worksheet(ConfigurationManager.AppSettings["SheetName"]); | |
var lastRowNumber = sheet.LastRowUsed().RowNumber(); | |
foreach (var row in sheet.Range("A:R").Rows(9, lastRowNumber) | |
{ | |
allRows.Add(new Model | |
{ | |
DateTime = row.Cell(1).Value.ToString(), | |
Description = row.Cell(2).Value.ToString(), | |
}); | |
} | |
} | |
} | |
using (var outbook = new XLWorkbook()) | |
{ | |
var sheet = outbook.Worksheets.Add("一覧"); | |
sheet.Cell(1, 1).Value = allRows; | |
outbook.SaveAs(Path.Combine(outPath, "all.xlsx")); | |
} | |
} | |
This file contains 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
public class Model | |
{ | |
public string DateTime { get; set; } | |
public string Description { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment