//************************************************************************** //作業者一覧の更新 //引数: //戻値: //************************************************************************** private bool SetOperatorName(List <string> name) { OpenOffice calc = new OpenOffice(); //parameterファイルを開く calc.OpenFile(Constants.ParameterFilePath); // sheetを取得 calc.SelectSheet("OperatorName"); //作業者一覧の更新 int i = 0; //行=ROW 列=COLUMN foreach (string item in name) { calc.cell = calc.sheet.getCellByPosition(1, 1 + i); calc.cell.setFormula(item); i++; } // Calcファイルを保存して閉じる if (!calc.SaveFile()) { return(false); } return(true); }
public bool SaveDailyCheck() { OpenOffice calc = new OpenOffice(); try { //当月点検データファイルが存在するかどうかの判定 string date = DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss"); //dateは"yyyy年MM月dd日 HH:mm:ss"の形式で保存 string year = date.Substring(0, 4); string month = date.Substring(5, 2); if (!System.IO.File.Exists(Constants.日常点検FolderPath + year + "年" + month + "月.ods")) { //既存検査データがなければ新規作成 File.Copy(Constants.日常点検FolderPath + "format.ods", Constants.日常点検FolderPath + year + "年" + month + "月.ods"); } //当月日常点検ファイルを開く string filepath = Constants.日常点検FolderPath + year + "年" + month + "月.ods"; calc.OpenFile(filepath); // sheetを取得 calc.SelectSheet("Sheet1"); int newRow = 0; for (; ;) //使用されているセルの最終行を検索する { Application.DoEvents(); if (calc.sheet.getCellByPosition(0, newRow).getFormula() == "") { break; } newRow++; } //最終行にデータを追加 int i = 0; foreach (var data in new string[] { date, "OK", State.OperatorName }) { calc.cell = calc.sheet.getCellByPosition(i, newRow); calc.cell.setFormula(data); i++; } // Calcファイルを上書き保存して閉じる if (!calc.SaveFile()) { return(false); } return(true); } catch { return(false); } finally { calc.CloseFile();//calcファイルが開いている場合のみクローズ処理する } }
//************************************************************************** //試験データの保存 //引数: //戻値: //************************************************************************** public static bool SaveTestData(List <string> testData) { string dataFilePath = ""; //State.date = dt.ToString("yyyyMMdd,HH:mm:ss"); var year = State.date.Substring(0, 4); var month = State.date.Substring(4, 2); dataFilePath = Constants.検査データBcrFolderPath + year + "年" + month + "月.ods"; //PC4内に当月試験データファイルがなければ新規作成する if (!System.IO.File.Exists(dataFilePath)) { File.Copy(Constants.検査データBcrFolderPath + "format.ods", dataFilePath); } OpenOffice calc = new OpenOffice(); try { //parameterファイルを開く calc.OpenFile(dataFilePath); // sheetを取得 calc.SelectSheet("Sheet1"); //使用されているセルの最終行を検索する int newRow = 1; //2行目からが試験データです for (; ;) //使用されているセルの最終行を検索する { Application.DoEvents(); if (calc.sheet.getCellByPosition(0, newRow).getFormula() == "") { break; } newRow++; } //最終行にデータを追加 int i = 0; foreach (var data in testData) { calc.cell = calc.sheet.getCellByPosition(i, newRow); calc.cell.setFormula(data); i++; } // Calcファイルを上書き保存して閉じる if (!calc.SaveFile()) { return(false); } return(true); } catch { return(false); } finally { calc.CloseFile(); } }