函数代码如下:看看有没有优化空间- checkBoxUpload() {
- const spread = this.designer.getWorkbook();
- queryHeadConfig({
- taskId: this.params.taskId,
- }).then((res) => {
- if (!res.data.length) {
- return;
- }
- spread.suspendPaint();
- res.data.forEach((item) => {
- const sheet = spread.getSheetFromName(item.sheetName);
- // 添加多选框
- if (!sheet) {
- return;
- }
- const range = sheet.getRange(
- `${item.columnLocate}${item.headerRows + 1}:${item.columnLocate}${sheet.getRowCount()}`,
- );
- if (item.columnType === 'CHECKBOX' && item.checkboxList.length) {
- // 添加多选项
- const radio = new GC.Spread.Sheets.CellTypes.CheckBoxList();
- radio.items(
- item.checkboxList.map((checkItem) => {
- return {
- text: checkItem,
- value: checkItem,
- };
- }),
- );
- range.cellType(radio);
- for (let i = item.headerRows + 1; i < sheet.getRowCount(); i++) {
- const value = sheet.getValue(i, item.columnIndex);
- if (value && typeof value === 'string' && value.split(',').length > 1) {
- console.log(value);
- sheet.setValue(i, item.columnIndex, value.split(','));
- }
- }
- // 列宽自适应
- sheet.autoFitColumn(range.col);
- }
- if (item.columnType === 'FILE_UPLOAD') {
- // 添加上传文件入口
- const style2 = new GC.Spread.Sheets.Style();
- style2.vAlign = GC.Spread.Sheets.VerticalAlign.center;
- style2.hAlign = GC.Spread.Sheets.HorizontalAlign.center;
- range.setStyle(style2);
- const fileUpload = new GC.Spread.Sheets.CellTypes.FileUpload();
- fileUpload.accept('.xlsx');
- fileUpload.maxSize(item.maxFileSize * 1024);
- fileUpload.valuePath('dataUrl');
- range.cellType(fileUpload);
- sheet.setColumnWidth(range.col, 200);
- const rowCount = sheet.getRowCount();
- for (let i = item.headerRows + 1; i < rowCount; i++) {
- sheet.setRowHeight(i, 70);
- }
- }
- });
- spread.resumePaint();
- });
- },
复制代码
|