
let getExcel2 = function (data) {

  
  let sheet_title = "품목코드등록";
  let file_name = "품목코드등록";

  const work_Book = new ExcelJS.Workbook();  // ExcelJS 라이브러리로 새 워크북 생성
  const work_Sheet = work_Book.addWorksheet(sheet_title);   // 새 워크시트 추가

  const all_border = {
    top: { style: "thin", color: { argb: "FF000000" } },
    left: { style: "thin", color: { argb: "FF000000" } },
    bottom: { style: "thin", color: { argb: "FF000000" } },
    right: { style: "thin", color: { argb: "FF000000" } },
  };
  const field_css = {
    yellow: {
      border: all_border,
      font: { color: { argb: "FF9C5700" }, bold: true },
      alignment: { vertical: "middle", horizontal: "center" },
      fill: {
        type: "pattern",
        pattern: "solid",
        fgColor: { argb: "FFFFEB9C" },
      },
    },
    green: {
      border: all_border,
      font: { color: { argb: "FF006100" }, bold: true },
      alignment: { vertical: "middle", horizontal: "center" },
      fill: {
        type: "pattern",
        pattern: "solid",
        fgColor: { argb: "FFC6EFCE" },
      },
    },
    red: {
      border: all_border,
      font: { color: { argb: "FF9C0006" }, bold: true },
      alignment: { vertical: "middle", horizontal: "center" },
      fill: {
        type: "pattern",
        pattern: "solid",
        fgColor: { argb: "FFFFC7CE" },
      },

    },
    blue: {
      border: all_border,
      font: { font: { size: 11 }, color: { argb: "0E3979" }, bold: true },
      alignment: { vertical: "middle", horizontal: "center" },
      fill: {
        type: "pattern",
        pattern: "solid",
        fgColor: { argb: "EAEFF3" },

      }
    },
    title: {
      font: { size: 15, bold: true },
      alignment: { vertical: "middle", horizontal: "center" },
    },
    box: {
      border: all_border,
      alignment: { vertical: "middle", horizontal: "center" },
      font: { size: 11 },

    },


  };

  // // 첫 번째 행 설정, 높이와 제목 설정

  // let ws_row1 = work_Sheet.getRow(1);
  // ws_row1.height = 32;
  // ws_row1.getCell(1).value = "검사항목";
  // ws_row1.getCell(1).style = field_css.title
  // work_Sheet.mergeCells('A1:E1');

    // 코드 가변처리, 항목추가시 편의성 개선
  let headers = [
    { name: "품목", width: 15 },
    { name: "품목(명)", width: 30 },
    { name: "품목그룹", width : 15},
    { name: "공순", width: 15 },
    { name: "공정코드", width: 15 },
    { name: "준비시간", width: 15 },
    { name: "공정시간", width: 15 },
    { name: "공정단가", width: 15 },
    //{ name: "검사번호", width: 15 },
    { name: "검사명", width: 15 },
    { name: "측정기", width: 15 },
    { name: "검사방법", width: 15 },
    { name: "OK/NG(Y/N)", width: 15 },
    { name: "기준값(㎜)", width: 15 },
    { name: "상한치(㎛)", width: 15 },
    { name: "하한치(㎛)", width: 15 }
  ];

  let ws_row = work_Sheet.getRow(1);
  ws_row.height = 25;

  headers.forEach((header, index) => {
    let cell = ws_row.getCell(index + 1);
    cell.style = field_css.blue;
    cell.value = header.name;
  });

  work_Sheet.columns = headers.map(header => ({ width: header.width }));

  
/*
  let ws_row = work_Sheet.getRow(1);
  ws_row.height = 25;
  // ws_row.getCell(1).style = field_css.blue;
  // ws_row.getCell(1).value = "NO.";
  ws_row.getCell(1).style = field_css.blue;
  ws_row.getCell(1).value = "품목";
  ws_row.getCell(2).style = field_css.blue;
  ws_row.getCell(2).value = "품목(명)";
  ws_row.getCell(3).style = field_css.blue;
  ws_row.getCell(3).value = "공순";
  ws_row.getCell(4).style = field_css.blue;
  ws_row.getCell(4).value = "공정코드";
  ws_row.getCell(5).style = field_css.blue;
  ws_row.getCell(5).value = "준비시간";
  ws_row.getCell(6).style = field_css.blue;
  ws_row.getCell(6).value = "공정시간";
  ws_row.getCell(7).style = field_css.blue;
  ws_row.getCell(7).value = "공정단가";
  ws_row.getCell(8).style = field_css.blue;
  ws_row.getCell(8).value = "검사명";
  ws_row.getCell(9).style = field_css.blue;
  ws_row.getCell(9).value = "측정기";
  ws_row.getCell(10).style = field_css.blue;
  ws_row.getCell(10).value = "검사방법";
  ws_row.getCell(11).style = field_css.blue;
  ws_row.getCell(11).value = "기준값(㎜)";
  ws_row.getCell(12).style = field_css.blue;
  ws_row.getCell(12).value = "상한치(㎛)";
  ws_row.getCell(13).style = field_css.blue;
  ws_row.getCell(13).value = "하한치(㎛)";
  work_Sheet.columns = [
    { width: 15 },
    { width: 30 },
    { width: 15 },
    { width: 15 },
    { width: 15 },

    { width: 15 },
    { width: 15 },
    { width: 15 },
    { width: 15 },
    { width: 15 },

    { width: 15 },
    { width: 15 },
    { width: 15 },
  ];
  */




   // 파일 생성 및 다운로드 부분

  work_Book.xlsx.writeBuffer().then((data) => {
    const blob = new Blob([data], {
      type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    });
    const url = window.URL.createObjectURL(blob);
    const anchor = document.createElement("a");
    anchor.href = url;
    anchor.download = file_name;
    anchor.click();
    window.URL.revokeObjectURL(url);
  });
}
