파일 업로드

파일 업로드 셀 유형은 파일을 업로드하는 버튼 셀입니다. 버튼 셀은 스프레드를 사용하여 페이지에 로컬 파일을 추가하려는 경우 유용할 수 있습니다.

설명
app.js
index.html
styles.css

파일 업로드 셀을 만들려면 다음 예를 따르십시오.

const sheet = spread.getActiveSheet();
const fileUpload = new GC.Spread.Sheets.CellTypes.FileUpload();
sheet.setCellType(1, 1, fileUpload);
// FileUpload support three formatted data types: blob, dataUrl, and GC.Spread.Sheets.CellTypes.IFileInfo.
// sheet.setValue(1, 1, dataUrl);
// sheet.setValue(1, 1, blob);
// sheet.setValue(1, 1, { name: 'test1.png', blob: blob });
// sheet.setValue(1, 1, { name: 'test2.txt', dataUrl: dataUrl });

valuePath 속성을 사용하여 셀 값 경로를 사용자 정의할 수 있습니다. 기본값은 'dataUrl'입니다.

fileUpload.valuePath(undefined); // After uploading the file, a special object(GC.Spread.Sheets.CellTypes.IFileInfo) will be stored in the cell.
// sheet.getValue(1, 1); // { name: 'test1.png', dataUrl: dataUrl, blob: blob }
// fileUpload.valuePath('dataUrl'); // After uploading the file, a string(dataUrl) will be stored in the cell.
// sheet.getValue(1, 1); // string
// fileUpload.valuePath('blob'); // After uploading the file, a special object(Blob) will be stored in the cell.
// sheet.getValue(1, 1); // Blob object

제공되는 많은 API를 사용하여 버튼을 사용자 정의할 수 있습니다. 셀의 버튼 위치를 제어하려면 다음 메서드를 사용합니다.

  • marginTop: 버튼의 위쪽 여백을 셀에 상대적인 픽셀 수로 가져오거나 설정합니다.
  • marginRight: 버튼의 오른쪽 여백을 셀에 상대적인 픽셀 수로 가져오거나 설정합니다.
  • marginBottom: 버튼의 아래쪽 여백을 셀에 상대적인 픽셀 수로 가져오거나 설정합니다.
  • marginLeft: 버튼의 왼쪽 여백을 셀에 상대적인 픽셀 수로 가져오거나 설정합니다.
fileUpload.marginLeft(15);
fileUpload.marginTop(7);
fileUpload.marginRight(15);
fileUpload.marginBottom(7);

"maxSize" 메서드를 사용하여 업로드 가능한 파일의 크기 제한을 가져오고 설정할 수 있습니다. "accept" 메서드를 사용하여 업로드 가능한 파일의 유형 제한을 가져오고 설정할 수 있습니다. 예:

fileUpload.maxSize(3000); // The unit is KB.
fileUpload.accept('image/*');

셀에서 파일 업로드 버튼의 작업 목록을 제어하려면 다음 메서드를 사용합니다.

  • isPreviewEnabled: 파일 미리 보기 버튼을 표시할지 여부를 가져오거나 설정합니다.
  • isDownloadEnabled: 파일 다운로드 버튼을 표시할지 여부를 가져오거나 설정합니다.
  • isClearEnabled: 파일 지우기 버튼을 표시할지 여부를 가져오거나 설정합니다.
fileUpload.isPreviewEnabled(true);
fileUpload.isDownloadEnabled(true);
fileUpload.isClearEnabled(false);

previewCommand 속성을 사용하여 미리 보기 로직을 사용자 정의할 수 있습니다.

fileUpload.previewCommand = function (file) {
    // Custom preview logic
}

// or
fileUpload.previewCommand = 'commandName'; // You need to register the corresponding command on the workbook first.

마지막으로 builtInFileIcons 속성을 사용하여 다양한 파일 형식의 아이콘을 사용자 정의할 수 있습니다.

spread.options.builtInFileIcons = { txt: 'xxx.png' };
파일 업로드 셀을 만들려면 다음 예를 따르십시오. valuePath 속성을 사용하여 셀 값 경로를 사용자 정의할 수 있습니다. 기본값은 'dataUrl'입니다. 제공되는 많은 API를 사용하여 버튼을 사용자 정의할 수 있습니다. 셀의 버튼 위치를 제어하려면 다음 메서드를 사용합니다. marginTop: 버튼의 위쪽 여백을 셀에 상대적인 픽셀 수로 가져오거나 설정합니다. marginRight: 버튼의 오른쪽 여백을 셀에 상대적인 픽셀 수로 가져오거나 설정합니다. marginBottom: 버튼의 아래쪽 여백을 셀에 상대적인 픽셀 수로 가져오거나 설정합니다. marginLeft: 버튼의 왼쪽 여백을 셀에 상대적인 픽셀 수로 가져오거나 설정합니다. "maxSize" 메서드를 사용하여 업로드 가능한 파일의 크기 제한을 가져오고 설정할 수 있습니다. "accept" 메서드를 사용하여 업로드 가능한 파일의 유형 제한을 가져오고 설정할 수 있습니다. 예: 셀에서 파일 업로드 버튼의 작업 목록을 제어하려면 다음 메서드를 사용합니다. isPreviewEnabled: 파일 미리 보기 버튼을 표시할지 여부를 가져오거나 설정합니다. isDownloadEnabled: 파일 다운로드 버튼을 표시할지 여부를 가져오거나 설정합니다. isClearEnabled: 파일 지우기 버튼을 표시할지 여부를 가져오거나 설정합니다. previewCommand 속성을 사용하여 미리 보기 로직을 사용자 정의할 수 있습니다. 마지막으로 builtInFileIcons 속성을 사용하여 다양한 파일 형식의 아이콘을 사용자 정의할 수 있습니다.
import { builtInFileIcons, demoFiles } from './utils.js'; var spreadNS = GC.Spread.Sheets; window.onload = function () { const spread = new spreadNS.Workbook(document.getElementById("ss"), { sheetCount: 1 }); initSpread(spread); }; function initSpread(spread) { spread.suspendPaint(); const sheet = spread.getActiveSheet(); initLayout(sheet); // set cell type const fileUpload1 = new spreadNS.CellTypes.FileUpload(); fileUpload1.accept('.jpg,.png,.gif'); fileUpload1.valuePath(undefined); sheet.getCell(1, 0).cellType(fileUpload1); const fileUpload2 = new spreadNS.CellTypes.FileUpload(); fileUpload2.isDownloadEnabled(false); fileUpload2.isClearEnabled(false); fileUpload2.valuePath(undefined); sheet.getCell(1, 1).cellType(fileUpload2); const fileUpload3 = new spreadNS.CellTypes.FileUpload(); sheet.getCell(1, 4).cellType(fileUpload3); fileUpload3.valuePath(undefined); sheet.getCell(2, 4).cellType(fileUpload3); const fileUpload4 = new spreadNS.CellTypes.FileUpload(); fileUpload4.isDownloadEnabled(false); fileUpload4.valuePath(undefined); sheet.getCell(1, 5).cellType(fileUpload4); const fileUpload5 = new spreadNS.CellTypes.FileUpload(); fileUpload5.isClearEnabled(false); fileUpload5.valuePath(undefined); sheet.getCell(2, 5).cellType(fileUpload5); // set cell value sheet.setValue(1, 0, demoFiles.image); sheet.setValue(1, 1, demoFiles.image); sheet.setValue(1, 4, demoFiles.ssjson); sheet.setValue(2, 4, demoFiles.json); sheet.setValue(1, 5, demoFiles.js); sheet.setValue(2, 5, demoFiles.xlsx); // set custom file icons spread.options.builtInFileIcons = builtInFileIcons; spread.resumePaint(); }; function initLayout(sheet) { // Description sheet.addSpan(0, 0, 1, 3, spreadNS.SheetArea.viewport); sheet.addSpan(0, 4, 1, 7, spreadNS.SheetArea.viewport); sheet.setColumnWidth(0, 70); sheet.setColumnWidth(1, 70); sheet.setColumnWidth(2, 200); sheet.setColumnWidth(4, 100); sheet.setColumnWidth(5, 100); sheet.setRowHeight(0, 50); sheet.setRowHeight(1, 70); sheet.setRowHeight(2, 70); sheet.setDefaultValue(0, 0, '1. Upload image files and customize file operations.'); sheet.setDefaultValue(0, 4, '2. Upload other non-image format files and customize the icons of related files.'); const style = new spreadNS.Style(); style.font = 'bold Calibri 14px'; style.vAlign = spreadNS.VerticalAlign.center; sheet.getRange(0, 0, 1, 11).setStyle(style); const style2 = new spreadNS.Style(); style2.vAlign = spreadNS.VerticalAlign.center; style2.hAlign = spreadNS.HorizontalAlign.center; sheet.getRange(1, 4, 2, 2).setStyle(style2); }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="spreadjs culture" content="ko-kr" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets-resources-ko/dist/gc.spread.sheets.resources.ko.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script> <script type="module" src="app.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <div class="sample-tutorial"> <div id="ss" style="width:100%; height: 100%"></div> </div> </body> </html>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }