EAS BOS 从Excel导入数据

1、制作导入模板

package com.kingdee.eas.ts.common.utils;

import java.util.Map;

import com.kingdee.bos.ctrl.kdf.table.IRow;
import com.kingdee.bos.ctrl.kdf.table.KDTable;
import com.kingdee.bos.dao.IObjectCollection;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.eas.ec.common.client.IExcelImpProcess;
import com.kingdee.eas.framework.client.CoreUI;

/**
 * 自定义导入模板
 * 实现com.kingdee.eas.ec.common.client.IExcelImpProcess接口
 */
public class CustomExcelImpProcess implements IExcelImpProcess {

	private CoreUI owner; //传入的界面
	private String strFullName; //Excel路径
	private String sheetName; //工作表名称
	private KDTable table; //表格
	
	public CustomExcelImpProcess(CoreUI owner, String strFullName, String sheetName, KDTable table){
		this.owner = owner;
		this.strFullName = strFullName;
		this.sheetName = sheetName;
		this.table = table;
	}
	
	/**
	 * 读取Excel每行数据
	 */
	@Override
	public void addRow(Object[] objArr) throws Exception {
		if(objArr == null || objArr.length == 0) return;
		IRow row = table.addRow();
		
		Object obj = null;
		String key = null;
		
		for(int i = 0; i

2、在界面上添加导入按钮并添加事件

protected void actionImportExcel_actionPerformed(ActionEvent e) throws Exception{
		String strFullPath = EcFileUtil.getSelectFile(this, false, "xls");
		if (strFullPath != null) {
			IExcelImpProcess process = new CustomExcelImpProcess(this, strFullPath, "物料", this.kdtEntry);
			ExcelUtil.impDataToExcel(process);
		}
	}

 

你可能感兴趣的:(EAS,BOS)