private void editOsPayOff(OsPayOffData[] pod) { //readyExcelRows(pod.Length, 6); //int sNo = 6; readyExcelRows(pod.Length, 9); int sNo = 9; decimal sum = 0M; for (int i = 0; i < pod.Length; i++) { if (i == 0) { //oWSheet.Cell(1, 2).Value = pod[i].ReportDate.ToString("Y"); //oWSheet.Cell(2, 2).Value = Conv.bList[Conv.OfficeCodeIndex(pod[i].OfficeCode)] + "/" + Conv.dNmList[Conv.DepNoIndex(pod[i].Department)]; //oWSheet.Cell(3, 2).Value = pod[i].Item; oWSheet.Cell(2, 1).Value = Convert.ToString(pod[i].ReportDate.Month) + "月分"; oWSheet.Cell(2, 6).Value = Conv.bList[Conv.OfficeCodeIndex(pod[i].OfficeCode)] + "/" + Conv.dNmList[Conv.DepNoIndex(pod[i].Department)]; oWSheet.Cell(5, 2).Value = pod[i].Item; itemCode = pod[i].ItemCode; } //oWSheet.Cell(sNo + i, 1).Value = pod[i].TaskCode; //oWSheet.Cell(sNo + i, 2).Value = pod[i].TaskName; //oWSheet.Cell(sNo + i, 5).Value = pod[i].Cost; //oWSheet.Cell(sNo + i, 6).Value = pod[i].LeaderMName; oWSheet.Cell(sNo + i, 1).Value = pod[i].TaskCode; oWSheet.Cell(sNo + i, 2).Value = pod[i].TaskName; oWSheet.Cell(sNo + i, 6).Value = pod[i].Cost; oWSheet.Cell(sNo + i, 7).Value = pod[i].LeaderMName; sum += pod[i].Cost; } int lastRows = oWSheet.LastRowUsed().RowNumber(); // Excel最終行位置 //oWSheet.Cell(lastRows, 5).Value = sum; oWSheet.Cell(lastRows, 6).Value = sum; }
// Wakamatsu 20170302 /// <summary> /// DataGridViewの最後にデータが存在する行数と現在のエクセルの行数を比較し、エクセルの行数が少ないようなら /// エクセルの行数を増加させる。 /// 比較の差異は列ヘッダーの行数、合計行の行数は除外する。 /// </summary> /// <param name="dgv"></param> /// <param name="stCol"></param> /// <param name="endCol"></param> /// <param name="headerLine"></param> private void readyExcelRows(DataGridView dgv, int stCol, int endCol, int exLine) { int lastRows = dgvRowsCount(dgv, stCol, endCol); // 表示対象の最終行 // 不足行追加 int sheetRowsCount = oWSheet.LastRowUsed().RowNumber(); // Excel最終行位置 sheetRowsCount -= exLine; // タイトル行と合計行を行数から除く if (lastRows > sheetRowsCount) { var rowCount = oWSheet.Row(6).InsertRowsBelow(lastRows - sheetRowsCount); } }