private void w_data_grid_as_RepoTask(List <List <string> > data) { DataTable tbl = new DataTable("RepoTaskTable"); //カラム設定 List <string> head_row = (List <string>)data[0]; foreach (string col in head_row) { tbl.Columns.Add(col); } //行のループ for (int i = 0; i < data.Count; i++) { if (i == 0) { continue; } List <string> row = (List <string>)data[i]; DataRow newRow = tbl.NewRow(); //列のループ for (int j = 0; j < row.Count; j++) { string col = (string)row[j]; if (j == 2) { col = TextUtil.jis2016_encode(col); } newRow[head_row[j]] = col; } tbl.Rows.Add(newRow); } data_grid_form.init(tbl); data_grid_form.col_auto_size(0, 2, 3, 4, 5); data_grid_form.Show(); }
//Excelファイルに出力(RepoTask) public void repo_task_save_xlsx(List <List <string> > data, string filename) { d_messenger message = new d_messenger(w_messenger); try { using (var wb = new ClosedXML.Excel.XLWorkbook()) { var ws = wb.Worksheets.Add("検査結果"); int sv_index = 5; //行のループ for (int i = 0; i < data.Count; i++) { List <string> row = (List <string>)data[i]; //列のループ for (int j = 0; j < row.Count; j++) { string col = (string)row[j]; col = TextUtil.trim(col); //32767文字を超える文字列処理 col = fetch_overflow_characters(col); //達成基準番号をJIS2016形式に変換 if (i > 0 && j == 2) { col = TextUtil.jis2016_encode(col); } //達成基準番号が日付に変換されるためSetValue<string>()を使用する ws.Cell(i + 1, j + 1).SetValue <string>(col); //基本的な書式設定 ws.Cell(i + 1, j + 1).Style.Alignment.SetVertical(XLAlignmentVerticalValues.Top); ws.Cell(i + 1, j + 1).Style.Font.FontName = "MS Pゴシック"; ws.Cell(i + 1, j + 1).Style.Border.TopBorder = XLBorderStyleValues.Thin; ws.Cell(i + 1, j + 1).Style.Border.BottomBorder = XLBorderStyleValues.Thin; ws.Cell(i + 1, j + 1).Style.Border.LeftBorder = XLBorderStyleValues.Thin; ws.Cell(i + 1, j + 1).Style.Border.RightBorder = XLBorderStyleValues.Thin; //header cell if (i == 0) { ws.Cell(i + 1, j + 1).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center); ws.Cell(i + 1, j + 1).Style.Font.Bold = true; } //data cell else { string sv_val = (string)row[sv_index]; sv_val = TextUtil.trim(sv_val); if (sv_val == "適合") { ws.Cell(i + 1, j + 1).Style.Fill.BackgroundColor = XLColor.FromArgb(0x89FFFF); } else if (sv_val == "適合(注記)") { ws.Cell(i + 1, j + 1).Style.Fill.BackgroundColor = XLColor.FromArgb(0x99FF99); } else if (sv_val == "不適合") { ws.Cell(i + 1, j + 1).Style.Fill.BackgroundColor = XLColor.FromArgb(0xFFB3B3); } else if (sv_val == "非適用") { ws.Cell(i + 1, j + 1).Style.Fill.BackgroundColor = XLColor.FromArgb(0xDDDDDD); } } } } wb.SaveAs(filename); main_form.Invoke(message, "保存に成功しました。(" + filename + ")"); } } catch (Exception ex) { main_form.Invoke(message, "【エラー】" + ex.Message); return; } }