//---------------------------------------------------------/ // Method //---------------------------------------------------------/ public void ExcelFile(string proc) { string tempFile = Folder.DefaultLocation() + @"\.~temp.xlsx"; Cursor.Current = Cursors.WaitCursor; // マウスカーソルを砂時計(Wait) // Wakamatsu 20170313 try { using (oWBook = new XLWorkbook(fileName)) { // 編集 switch (procList.IndexOf(proc)) { case 0: case 1: if (pod == null || pod.Length == 0) { DMessage.DataNotExistence("中断します!"); return; } //MessageBox.Show("Excel書込み開始"); if (proc == payoff) { oWSheet = oWBook.Worksheet(1); // シートを開く editOsPayOff(pod); // 起案書発行 } else { // Wakamatsu 20170313 //decimal sum = 0M; //int page = pod.Length / posRow; //if (pod.Length % posRow > 0) page++; //for (int i = 0; i < page; i++) //{ // oWSheet = oWBook.Worksheet(i + 1); // シートを開く // oWSheet.Cell(3, 5).Value = "'" + (i + 1).ToString() + "/" + page.ToString(); // sum = editOsPayOffS(pod, posRow * i, sum); // 起案書発行 //} oWSheet = oWBook.Worksheet(1); // シートを開く oWSheet.Cell(3, 5).Value = "'1/1"; editOsPayOffS(pod, posRow, 0); // 起案書発行 // Wakamatsu 20170313 } break; case 2: if (pmd == null || pmd.Length == 0) { DMessage.DataNotExistence("中断します!"); return; } //MessageBox.Show("Excel書込み開始"); oWSheet = oWBook.Worksheet(1); // シートを開く editOsPayment(pmd); // 調書発行 break; default: break; } // 保存 oWBook.SaveAs(tempFile); // Excel保存 } } catch (Exception ex) { MessageBox.Show(ex.Message); Cursor.Current = Cursors.Default; // マウスカーソルを戻す return; } // Wakamatsu 20170313 Cursor.Current = Cursors.Default; // マウスカーソルを戻す //System.Diagnostics.Process.Start("Excel.exe", tempFile); // 表示用Excel // pdf file 出力 DateTime now = DateTime.Now; outputFile = System.IO.Path.GetDirectoryName(tempFile) + @"\" + pNameList[procList.IndexOf(proc)] + "_" + itemCode + "_" + now.ToString("yyMMddHHmmss"); PublishExcelToPdf etp = new PublishExcelToPdf(); // Wakamatsu 20170313 //etp.ExcelToPDF(tempFile, outputFile); if (etp.ExcelToPDF(tempFile, outputFile) == true) { if (File.Exists(tempFile)) { File.Delete(tempFile); } } }
//---------------------------------------------------------/ // Method //---------------------------------------------------------/ public void ExcelFile() { string tempFile = Folder.DefaultLocation() + @"\.~temp.xlsx"; Cursor.Current = Cursors.WaitCursor; // マウスカーソルを砂時計(Wait) // Wakamatsu 20170315 try { using (oWBook = new XLWorkbook(fileName)) { if (tla == null || tla.Length == 0) { DMessage.DataNotExistence("中断します!"); return; } // 編集 oWSheet = oWBook.Worksheet(1); // シートを開く // Wakamatsu 20170315 //readyExcelRows(tla.Length, 5); readyExcelRows(tla.Length, 4); int sNo = 5; for (int i = 0; i < tla.Length; i++) { // Wakamatsu 20170315 using (IXLRange SetRange = oWSheet.Range("A5:I5")) // テンプレートデータ行コピー/ペースト SetRange.CopyTo(oWSheet.Cell(sNo + i, 1)); // Wakamatsu 20170315 if (i == 0) { officeName = tla[i].OfficeName; departName = tla[i].DepartName; // Wakamatsu 20170315 //oWSheet.Cell(1, 7).Value = DateTime.Today; oWSheet.Cell(2, 2).Value = DateTime.Today; oWSheet.Cell(3, 2).Value = officeName + " " + departName; // Wakamatsu 20170315 } oWSheet.Cell(sNo + i, 1).Value = tla[i].TaskCode; oWSheet.Cell(sNo + i, 2).Value = tla[i].TaskName; oWSheet.Cell(sNo + i, 3).Value = tla[i].PartnerName; oWSheet.Cell(sNo + i, 4).Value = tla[i].Contract; oWSheet.Cell(sNo + i, 5).Value = tla[i].StartDate; oWSheet.Cell(sNo + i, 6).Value = tla[i].EndDate; oWSheet.Cell(sNo + i, 7).Value = tla[i].SalesM; oWSheet.Cell(sNo + i, 8).Value = tla[i].LeaderM; oWSheet.Cell(sNo + i, 9).Value = tla[i].IssueDate; // Wakamatsu 20170315 if (i != 0) { oWSheet.Range(sNo + i, 1, sNo + i, 9).Style.Border.TopBorder = XLBorderStyleValues.Hair; } if (i == tla.Length - 1) { oWSheet.Range(sNo + i, 1, sNo + i, 9).Style.Border.BottomBorder = XLBorderStyleValues.Thin; } else { oWSheet.Range(sNo + i, 1, sNo + i, 9).Style.Border.BottomBorder = XLBorderStyleValues.Hair; } // Wakamatsu 20170315 } } // 保存 oWBook.SaveAs(tempFile); // Excel保存 } // Wakamatsu 20170315 catch (Exception ex) { MessageBox.Show(ex.Message); Cursor.Current = Cursors.Default; // マウスカーソルを戻す return; } // Wakamatsu 20170315 Cursor.Current = Cursors.Default; // マウスカーソルを戻す //System.Diagnostics.Process.Start("Excel.exe", tempFile); // 表示用Excel // pdf file 出力 DateTime now = DateTime.Now; outputFile = System.IO.Path.GetDirectoryName(tempFile) + @"\業務一覧表_" + officeName + "_" + departName + "_" + now.ToString("yyMMddHHmmss"); PublishExcelToPdf etp = new PublishExcelToPdf(); etp.ExcelToPDF(tempFile, outputFile); if (File.Exists(tempFile)) { File.Delete(tempFile); } }