Excel导入导出下拉选项实现


本示例是实现具有下拉选项的导入导出功能

并且是非常规模板 https://www.yesdotnet.com/archive/yesweb/624706263650309.html

 

 

导出

Excel导入导出下拉选项实现

HTML 全选
<el-dropdown :disabled="enableMultipleSelection" @command="handleButtonExport">
	<joc-button :disabled="enableMultipleSelection" type="default" iconfont="icon-excel-down"
		sync>导出Excel</joc-button>
	<template #dropdown>
		<el-dropdown-menu>
			<el-dropdown-item command="systemMaterCode">使用[系统]物料代码</el-dropdown-item>
			<el-dropdown-item command="supplierMaterCode">使用[供应商]物料代码</el-dropdown-item>
		</el-dropdown-menu>
	</template>
</el-dropdown>
JavaScript 全选
// 导出Excel
const handleButtonExport = (command: string | number | object) => {
	let row = tableRef.value?.getCurrentRecord()
	if (row) {
		let actions = ''
		switch (command) {
			case 'supplierMaterCode': {
				actions = '/PurchaseOrder/ExportOrderSupplierMapping'
			} break;
			default: {
				actions = '/PurchaseOrder/ExportOrder'
			} break;
		}

		ajax.postDownLoad(actions, { id: row.rowId }, {}, { timeout: 0 }).then(res => {
			ElMessage({
				message: '导出成功',
				type: 'success',
				plain: true
			})
		}).finally(() => {
		})
	} else {
		ElMessage({
			message: '没有选择数据',
			type: 'error',
			plain: true
		})
	}

}

导入

Excel导入导出下拉选项实现

C# 全选
<el-dropdown @command="handleButtonImport">
	<joc-button type="default" iconfont="icon-PC-Excel" sync>导入Excel数据</joc-button>
	<template #dropdown>
		<el-dropdown-menu>
			<el-dropdown-item command="systemMaterCode">使用[系统]物料代码</el-dropdown-item>
			<el-dropdown-item command="supplierMaterCode">使用[供应商]物料代码</el-dropdown-item>
		</el-dropdown-menu>
	</template>
</el-dropdown>

<excel-choose ref="excelChooseRef" style="display: none;" :showFilePath="false"
	:handleWorkBook="handleWorkBook">Excel单据导入</excel-choose>
JavaScript 全选
import ExcelChoose from '@/components/ExcelChoose/Index.vue'
const excelChooseRef = ref<InstanceType<typeof ExcelChoose>>()

const uploadUrl = ref('')
const handleButtonImport = (command: string | number | object) => {
	switch (command) {
		case 'supplierMaterCode': {
			uploadUrl.value = '/purchaseOrder/importExcelConvertSupplierMapping'
		} break;
		default: {
			uploadUrl.value = '/purchaseOrder/importExcelConvert'
		} break;
	}

	excelChooseRef.value?.doSelectFile()
}



/**
 * Excel单据导入
 */
const handleWorkBook = (workbook: XLSX.WorkBook) => {

	const worksheetName = workbook.SheetNames[0];
	const worksheet = workbook.Sheets[worksheetName];

	var jsonData: any[] = XLSX.utils.sheet_to_json(worksheet, { header: 'A' });

	const data: XLSDataMain = {
		docNo: jsonData[0]['B'],
		docType: jsonData[0]['D'],
		// docDate: jsonData[0]['F'],
		deliveryDate: jsonData[0]['H'],
		organization03Code: jsonData[1]['B'],
		organization03Name: jsonData[1]['D'],
		organization04Code: jsonData[1]['F'],
		organization04Name: jsonData[1]['H'],
		supplierCode: jsonData[2]['B'],
		supplierName: jsonData[2]['D'],
		purchaseGroup: jsonData[2]['F'],
		amount: jsonData[2]['H'],
		remark: jsonData[3]['B'],
		items: jsonData.slice(5).map(item => {
			return {
				organization04Code: item['B'],
				organization04Name: item['C'],
				materialCode: item['D'],
				materialName: item['E'],
				unit: item['F'],
				quantity: item['G'],
				price: item['H'],
				amount: item['I'],
				remark: item['J']
			}
		})

	}

	ajax.postEx<FormData>(uploadUrl.value, data).then(res => {
		formEditRef.value?.showCreateFromExcel(res.data)
	})
}

 

版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
张国生
评论列表

发表评论

评论内容
昵称:
关联文章

Excel导入导出选项实现
C# NPOI导出excel绑定列的数据源
Excel文件数据导入导出功能实现
非常规Excel模板导入导出
Excel数据导出导入 V3
.net防抖函数Debounce实现
excel2007直接打开文件空白,需要菜单打开
GIT Bash 简单讲解-git如何推/代码
Excel自定义格式千分符
EF EntityFramework.MappingAPI批量导入 模型属性顺序和数据库表不一致时导入错位
NPOI生成Excel文件时设置一整列为文本类型
【C#】C#中使用GDAL3(三):Windows编译插件驱动
使用.NET 6开发TodoList应用(27)——实现API的Swagger文档化
Python读取excel xlrd读取xlsx报错:Excel xlsx file; not supported
服务端实现
win11右键菜单恢复默认显示更多选项
.Net 高性能分表分库组件-连接模式原理
详解ElasticAPM实现微服务的链路追踪(NET)
windows配置安卓adb工具
[WPF] 用 Effect 实现线条光影效果