Skip to content

Instantly share code, notes, and snippets.

@kawa-xxx
Last active July 17, 2016 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kawa-xxx/3061cde3ecf03509d32875e96b6db398 to your computer and use it in GitHub Desktop.
Save kawa-xxx/3061cde3ecf03509d32875e96b6db398 to your computer and use it in GitHub Desktop.
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