feat(sn): CS 기준 UI 통일 및 지도 팝업 표준화
This commit is contained in:
@@ -1,83 +1,97 @@
|
||||
// import type { sheetParameter } from '@/index';
|
||||
import * as XlsxPopulate from '@xlsx/xlsx-populate';
|
||||
import type { SheetParameter } from './index';
|
||||
import type * as XlsxPopulateTypes from "@xlsx/xlsx-populate";
|
||||
import type { SheetParameter } from "./index";
|
||||
|
||||
const loadXlsxPopulate = () => import("@xlsx/xlsx-populate");
|
||||
|
||||
const makeCellStyle = (styleQ: XlsxPopulateTypes.StyleQuery) => {
|
||||
styleQ.fill({ type: "solid", color: { rgb: "9bc1e7" } });
|
||||
styleQ.borderEach({ style: "thin", color: { rgb: "FFFFFF" } });
|
||||
styleQ.wrapText(true);
|
||||
// styleQ.fontColor({rgb:"FFFFFF"});
|
||||
styleQ.fontSize(13);
|
||||
styleQ.horizontalAlignment("center");
|
||||
styleQ.verticalAlignment("center");
|
||||
styleQ.bold(true);
|
||||
};
|
||||
|
||||
const makeCellStyle =(styleQ: XlsxPopulate.StyleQuery )=>{
|
||||
styleQ.fill({ type: "solid", color: {rgb:"9bc1e7"} });
|
||||
styleQ.borderEach( { style: "thin", color: { rgb: "FFFFFF" } } );
|
||||
styleQ.wrapText(true);
|
||||
// styleQ.fontColor({rgb:"FFFFFF"});
|
||||
styleQ.fontSize(13);
|
||||
styleQ.horizontalAlignment("center");
|
||||
styleQ.verticalAlignment("center");
|
||||
styleQ.bold(true);
|
||||
}
|
||||
const makeExcelFile = async (
|
||||
workbook: XlsxPopulateTypes.Workbook,
|
||||
fileNm: string,
|
||||
) => {
|
||||
const outputData = await workbook.output("array-buffer");
|
||||
const blob = new Blob([outputData], { type: "application/octet-stream" });
|
||||
const link = document.createElement("a");
|
||||
link.href = URL.createObjectURL(blob);
|
||||
link.download = fileNm + ".xlsx";
|
||||
link.click();
|
||||
};
|
||||
|
||||
const makeExcelFile = async(workbook: XlsxPopulate.Workbook,fileNm:string)=>{
|
||||
const outputData = await workbook.output("array-buffer");
|
||||
const blob = new Blob([outputData], { type: "application/octet-stream" });
|
||||
const link = document.createElement("a");
|
||||
link.href = URL.createObjectURL(blob);
|
||||
link.download = fileNm+".xlsx";
|
||||
link.click();
|
||||
export const excelStyle = async (
|
||||
data: ArrayBuffer,
|
||||
range: string = "A1:V3",
|
||||
fileNm: string,
|
||||
) => {
|
||||
const XlsxPopulate = await loadXlsxPopulate();
|
||||
const workbook = await XlsxPopulate.Workbook.fromData(data);
|
||||
const rangeCells = workbook.activeSheet(0)?.sheet(0)?.range(range);
|
||||
console.log(rangeCells);
|
||||
rangeCells?.style((styleQ) => {
|
||||
makeCellStyle(styleQ);
|
||||
});
|
||||
makeExcelFile(workbook, fileNm);
|
||||
};
|
||||
|
||||
}
|
||||
export const excelArrayStyle = async (
|
||||
data: ArrayBuffer,
|
||||
range: SheetParameter[],
|
||||
fileNm: string,
|
||||
) => {
|
||||
const XlsxPopulate = await loadXlsxPopulate();
|
||||
const workbook = await XlsxPopulate.Workbook.fromData(data);
|
||||
if (range) {
|
||||
range.forEach((item, index) => {
|
||||
const rangeCells = workbook
|
||||
.activeSheet(index)
|
||||
?.sheet(index)
|
||||
?.range(item.headerRange);
|
||||
console.log(rangeCells);
|
||||
rangeCells?.style((styleQ) => {
|
||||
makeCellStyle(styleQ);
|
||||
});
|
||||
|
||||
|
||||
export const excelStyle = async (data: ArrayBuffer, range: string = "A1:V3", fileNm:string) => {
|
||||
const workbook = await XlsxPopulate.Workbook.fromData(data);
|
||||
const rangeCells = workbook.activeSheet(0)?.sheet(0)?.range(range);
|
||||
console.log(rangeCells);
|
||||
rangeCells?.style((styleQ)=>{
|
||||
makeCellStyle(styleQ)
|
||||
});
|
||||
makeExcelFile(workbook, fileNm)
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
export const excelArrayStyle = async (data: ArrayBuffer, range: SheetParameter[], fileNm: string) => {
|
||||
const workbook = await XlsxPopulate.Workbook.fromData(data);
|
||||
if (range) {
|
||||
range.forEach((item, index) => {
|
||||
const rangeCells = workbook.activeSheet(index)?.sheet(index)?.range(item.headerRange);
|
||||
console.log(rangeCells);
|
||||
rangeCells?.style((styleQ) => {
|
||||
makeCellStyle(styleQ)
|
||||
});
|
||||
|
||||
// 모든 데이터 셀에 세로 가운데 정렬 적용
|
||||
if (item.data && item.data.length > 0) {
|
||||
const numCols = item.data[0]?.length || 0;
|
||||
const numRows = item.data.length;
|
||||
const lastColLetter = getExcelColumnLetter(numCols);
|
||||
const dataRange = workbook.activeSheet(index)?.sheet(index)?.range(`A1:${lastColLetter}${numRows}`);
|
||||
dataRange?.style((styleQ) => {
|
||||
styleQ.verticalAlignment("center");
|
||||
});
|
||||
}
|
||||
// 모든 데이터 셀에 세로 가운데 정렬 적용
|
||||
if (item.data && item.data.length > 0) {
|
||||
const numCols = item.data[0]?.length || 0;
|
||||
const numRows = item.data.length;
|
||||
const lastColLetter = getExcelColumnLetter(numCols);
|
||||
const dataRange = workbook
|
||||
.activeSheet(index)
|
||||
?.sheet(index)
|
||||
?.range(`A1:${lastColLetter}${numRows}`);
|
||||
dataRange?.style((styleQ) => {
|
||||
styleQ.verticalAlignment("center");
|
||||
});
|
||||
}
|
||||
makeExcelFile(workbook, fileNm)
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
makeExcelFile(workbook, fileNm);
|
||||
};
|
||||
|
||||
export const excelStyleWithKoreanHeaders = async (
|
||||
data: ArrayBuffer,
|
||||
range: string = "A1:V3",
|
||||
data: ArrayBuffer,
|
||||
range: string = "A1:V3",
|
||||
fileNm: string,
|
||||
headerMapping: { [key: string]: string },
|
||||
sampleData: any,
|
||||
mergeRanges?: string[]
|
||||
mergeRanges?: string[],
|
||||
) => {
|
||||
const XlsxPopulate = await loadXlsxPopulate();
|
||||
const workbook = await XlsxPopulate.Workbook.fromData(data);
|
||||
const sheet = workbook.activeSheet();
|
||||
|
||||
|
||||
if (!sheet) {
|
||||
throw new Error('워크시트를 찾을 수 없습니다.');
|
||||
throw new Error("워크시트를 찾을 수 없습니다.");
|
||||
}
|
||||
|
||||
// 1. 영문 헤더를 한글로 교체
|
||||
@@ -97,7 +111,7 @@ export const excelStyleWithKoreanHeaders = async (
|
||||
// 3. 모든 데이터 셀에 세로 가운데 정렬 적용
|
||||
const numCols = englishHeaders.length;
|
||||
const numRows = sheet.usedRange()?.endCell()?.rowNumber() || 1;
|
||||
|
||||
|
||||
if (numRows > 1) {
|
||||
const lastColLetter = getExcelColumnLetter(numCols);
|
||||
const dataRange = sheet.range(`A1:${lastColLetter}${numRows}`);
|
||||
@@ -117,14 +131,12 @@ export const excelStyleWithKoreanHeaders = async (
|
||||
await makeExcelFile(workbook, fileNm);
|
||||
};
|
||||
|
||||
|
||||
const getExcelColumnLetter = (colIndex: number): string => {
|
||||
let letter = '';
|
||||
while (colIndex > 0) {
|
||||
const mod = (colIndex - 1) % 26;
|
||||
letter = String.fromCharCode(65 + mod) + letter;
|
||||
colIndex = Math.floor((colIndex - 1) / 26);
|
||||
}
|
||||
return letter;
|
||||
};
|
||||
|
||||
let letter = "";
|
||||
while (colIndex > 0) {
|
||||
const mod = (colIndex - 1) % 26;
|
||||
letter = String.fromCharCode(65 + mod) + letter;
|
||||
colIndex = Math.floor((colIndex - 1) / 26);
|
||||
}
|
||||
return letter;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user