Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ClosedXML のサンプル
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"));
}
}
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