//テキストを指定文字コードで任意形式のファイルとして保存する public void write_anyfile_encode_by(string data, string encode, string filename) { d_messenger message = new d_messenger(w_messenger); Encoding enc = null; switch (encode) { case "sjis": enc = System.Text.Encoding.GetEncoding("shift_jis"); break; case "euc": enc = System.Text.Encoding.GetEncoding("euc-jp"); break; default: enc = new System.Text.UTF8Encoding(false); break; } StreamWriter sw = new StreamWriter(filename, false, enc); sw.Write(data); sw.Close(); main_form.Invoke(message, "保存に成功しました。(" + filename + ")"); }
//検査メインページに移動 public void browse_sv_mainpage() { //basic認証の処理 if (_basic_auth_flag.Equals("yes") && _basic_authenicated == false) { d_messenger message = new d_messenger(w_messenger); main_form.Invoke(message, "【お知らせ】基本認証オプションが有効化されています。ログインアラートで認証してください。"); _basic_authenicated = true; } _wd.Navigate().GoToUrl(sv_mainpage_url_base + _projectID); }
//配列をテキストファイルとして書き込み public void write_text_data(List <string> data, string filename) { d_messenger message = new d_messenger(w_messenger); Encoding enc = new System.Text.UTF8Encoding(false); StreamWriter sw = new StreamWriter(filename, false, enc); for (int i = 0; i < data.Count; i++) { string row = (string)data[i] + "\r\n"; sw.Write(row); } sw.Close(); main_form.Invoke(message, "保存に成功しました。(" + filename + ")"); }
//Excelファイルに出力 public void save_xlsx_as(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("Sheet1"); //行のループ 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]; ws.Cell(i + 1, j + 1).SetValue <string>(fetch_overflow_characters(col)); 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; ws.Cell(i + 1, j + 1).Style.Font.FontName = "MS Pゴシック"; ws.Cell(i + 1, j + 1).Style.Alignment.SetVertical(XLAlignmentVerticalValues.Top); } } wb.SaveAs(filename); main_form.Invoke(message, "保存に成功しました。(" + filename + ")"); } } catch (Exception ex) { main_form.Invoke(message, "【エラー】" + ex.Message); return; } }
//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; } }