/// <summary> /// 循环获取Excel表格中所有列名 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnImportExcelFields_Click(object sender, EventArgs e) { try { //打开指定文件类型 OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "EXCEL文件(*.xls;*.xlsx)|*.xls;*.xlsx"; openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = true; openFileDialog.Title = "导入Excel配件信息文件"; if (openFileDialog.ShowDialog() == DialogResult.OK) { if (IsXlsOpen(openFileDialog.FileName)) { return; //判断要导入的Excel文件是否打开 } ExcelTable = ImportExportExcel.NPOIImportExcelFile(openFileDialog.FileName); //获取Excel表格数据 } else { return; } //获取所有Excel表格列名 foreach (DataGridViewRow dgRow in dgMatchList.Rows) { CommonFuncCall.BindExcelHeadText((DataGridViewComboBoxCell)dgRow.Cells["ExcelField"], ExcelTable, ExcelFieldDefVal); } }catch (Exception ex) { MessageBoxEx.Show(ex.Message, "异常提示", MessageBoxButtons.OK, MessageBoxIcon.Question); } }
/// <summary> /// 导出Excel文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ExcelExport_Click(object sender, EventArgs e) { try { if (gvCheckBillList.Rows.Count == 0) //判断gridview中是否有数据记录 { MessageBoxEx.Show("您要导出的单据列表不能为空!"); return; } else { DataTable XlsTable = new DataTable();//导出的数据表格 //创建表列项 XlsTable.Columns.Add("单据编号", typeof(string)); XlsTable.Columns.Add("单据日期", typeof(string)); XlsTable.Columns.Add("仓库", typeof(string)); XlsTable.Columns.Add("账面数量", typeof(string)); XlsTable.Columns.Add("实盘数量", typeof(string)); XlsTable.Columns.Add("盈亏数量", typeof(string)); XlsTable.Columns.Add("金额", typeof(string)); XlsTable.Columns.Add("部门", typeof(string)); XlsTable.Columns.Add("经办人", typeof(string)); XlsTable.Columns.Add("操作人", typeof(string)); XlsTable.Columns.Add("备注", typeof(string)); XlsTable.Columns.Add("单据状态", typeof(string)); foreach (DataGridViewRow dgRow in gvCheckBillList.Rows) { bool SelectFlag = (bool)((DataGridViewCheckBoxCell)dgRow.Cells["colCheck"]).EditedFormattedValue;//获取当前记录行的选择状态 if (SelectFlag == true) { DataRow TableRow = XlsTable.NewRow();//创建表行项 TableRow["单据编号"] = dgRow.Cells["BillNum"].Value.ToString(); TableRow["单据日期"] = dgRow.Cells["BillDate"].Value.ToString(); TableRow["仓库"] = dgRow.Cells["WHName"].Value.ToString(); TableRow["账面数量"] = dgRow.Cells["PapCount"].Value.ToString(); TableRow["实盘数量"] = dgRow.Cells["FirmCount"].Value.ToString(); TableRow["盈亏数量"] = dgRow.Cells["ProfitLosCount"].Value.ToString(); TableRow["金额"] = dgRow.Cells["TotalMoney"].Value.ToString(); TableRow["部门"] = dgRow.Cells["DepartName"].Value.ToString(); TableRow["经办人"] = dgRow.Cells["HandlerName"].Value.ToString(); TableRow["操作人"] = dgRow.Cells["OpeName"].Value.ToString(); TableRow["备注"] = dgRow.Cells["Remarks"].Value.ToString(); TableRow["单据状态"] = dgRow.Cells["OrderState"].Value.ToString(); XlsTable.Rows.Add(TableRow); } } if (XlsTable.Rows.Count == 0) { MessageBoxEx.Show("请您选择要导出的单据记录行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } ImportExportExcel.NPOIExportExcelFile(XlsTable, ExportXlsName);//生成Excel表格文件 } } catch (Exception ex) { MessageBoxEx.Show(ex.Message, "异常提示", MessageBoxButtons.OK, MessageBoxIcon.Question); } }
private void UCRequisitionQuery_ExportEvent(object sender, EventArgs e) { try { if (gvAllotQueryBillList.Rows.Count == 0) //判断gridview中是否有数据记录 { MessageBoxEx.Show("您要导出的单据列表不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { DataTable XlsTable = new DataTable();//导出的数据表格 //创建表列项 XlsTable.Columns.Add("单据类型", typeof(string)); XlsTable.Columns.Add("单据编号", typeof(string)); XlsTable.Columns.Add("单据日期", typeof(string)); XlsTable.Columns.Add("调出机构", typeof(string)); XlsTable.Columns.Add("调出仓库", typeof(string)); XlsTable.Columns.Add("调入机构", typeof(string)); XlsTable.Columns.Add("调入仓库", typeof(string)); XlsTable.Columns.Add("业务数量", typeof(string)); XlsTable.Columns.Add("金额", typeof(string)); XlsTable.Columns.Add("运输方式", typeof(string)); XlsTable.Columns.Add("送货地点", typeof(string)); XlsTable.Columns.Add("部门", typeof(string)); XlsTable.Columns.Add("经办人", typeof(string)); XlsTable.Columns.Add("操作人", typeof(string)); XlsTable.Columns.Add("备注", typeof(string)); XlsTable.Columns.Add("出入库状态", typeof(string)); foreach (DataGridViewRow dgRow in gvAllotQueryBillList.Rows) { DataRow TableRow = XlsTable.NewRow();//创建表行项 TableRow["单据类型"] = dgRow.Cells["OrderType"].Value.ToString(); TableRow["单据编号"] = dgRow.Cells["BillNum"].Value.ToString(); TableRow["单据日期"] = dgRow.Cells["BillDate"].Value.ToString(); TableRow["调出机构"] = dgRow.Cells["OutDepartment"].Value.ToString(); TableRow["调出仓库"] = dgRow.Cells["OutWareHouse"].Value.ToString(); TableRow["调入机构"] = dgRow.Cells["InDepartment"].Value.ToString(); TableRow["调入仓库"] = dgRow.Cells["InWareHouse"].Value.ToString(); TableRow["业务数量"] = dgRow.Cells["TotalCount"].Value.ToString(); TableRow["金额"] = dgRow.Cells["AmountMoney"].Value.ToString(); TableRow["运输方式"] = dgRow.Cells["DeliveryWays"].Value.ToString(); TableRow["送货地点"] = dgRow.Cells["ArrivePlace"].Value.ToString(); TableRow["部门"] = dgRow.Cells["DepartName"].Value.ToString(); TableRow["经办人"] = dgRow.Cells["HandlerName"].Value.ToString(); TableRow["操作人"] = dgRow.Cells["OpeName"].Value.ToString(); TableRow["备注"] = dgRow.Cells["Remarks"].Value.ToString(); TableRow["出入库状态"] = dgRow.Cells["InOutState"].Value.ToString(); XlsTable.Rows.Add(TableRow); } ImportExportExcel.NPOIExportExcelFile(XlsTable, ExportXlsName);//生成Excel表格文件 } } catch (Exception ex) { MessageBoxEx.Show(ex.Message, "异常提示", MessageBoxButtons.OK, MessageBoxIcon.Question); } }
/// <summary> /// 导出按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UCStockCheckQuery_ExportEvent(object sender, EventArgs e) { try { if (gvCheckQueryBillList.Rows.Count == 0) //判断gridview中是否有数据记录 { MessageBoxEx.Show("您要导出的单据列表不能为空!"); return; } else { DataTable XlsTable = new DataTable();//导出的数据表格 //创建表列项 XlsTable.Columns.Add("单据编号", typeof(string)); XlsTable.Columns.Add("单据日期", typeof(string)); XlsTable.Columns.Add("仓库", typeof(string)); XlsTable.Columns.Add("账面数量", typeof(string)); XlsTable.Columns.Add("实盘数量", typeof(string)); XlsTable.Columns.Add("盈亏数量", typeof(string)); XlsTable.Columns.Add("金额", typeof(string)); XlsTable.Columns.Add("部门", typeof(string)); XlsTable.Columns.Add("经办人", typeof(string)); XlsTable.Columns.Add("操作人", typeof(string)); XlsTable.Columns.Add("备注", typeof(string)); XlsTable.Columns.Add("出入库状态", typeof(string)); foreach (DataGridViewRow dgRow in gvCheckQueryBillList.Rows) { DataRow TableRow = XlsTable.NewRow();//创建表行项 TableRow["单据编号"] = dgRow.Cells["BillNum"].Value.ToString(); TableRow["单据日期"] = dgRow.Cells["BillDate"].Value.ToString(); TableRow["仓库"] = dgRow.Cells["WHName"].Value.ToString(); TableRow["账面数量"] = dgRow.Cells["PapCount"].Value.ToString(); TableRow["实盘数量"] = dgRow.Cells["FirmCount"].Value.ToString(); TableRow["盈亏数量"] = dgRow.Cells["ProfitLosCount"].Value.ToString(); TableRow["金额"] = dgRow.Cells["Calcmoney"].Value.ToString(); TableRow["部门"] = dgRow.Cells["DepartName"].Value.ToString(); TableRow["经办人"] = dgRow.Cells["HandlerName"].Value.ToString(); TableRow["操作人"] = dgRow.Cells["OpeName"].Value.ToString(); TableRow["备注"] = dgRow.Cells["Remarks"].Value.ToString(); TableRow["出入库状态"] = dgRow.Cells["InOutState"].Value.ToString(); XlsTable.Rows.Add(TableRow); } ImportExportExcel.NPOIExportExcelFile(XlsTable, ExportXlsName);//生成Excel表格文件 } } catch (Exception ex) { MessageBoxEx.Show(ex.Message, "异常提示", MessageBoxButtons.OK, MessageBoxIcon.Question); } }
/// <summary> /// 导出Excel文件操作 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ExcelExport_Click(object sender, EventArgs e) { try { if (gvLossQueryBillList.Rows.Count == 0) //判断gridview中是否有数据记录 { MessageBoxEx.Show("您要导出的单据列表不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { DataTable XlsTable = new DataTable();//导出的数据表格 //创建表列项 XlsTable.Columns.Add("单据编号", typeof(string)); XlsTable.Columns.Add("单据日期", typeof(string)); XlsTable.Columns.Add("仓库", typeof(string)); XlsTable.Columns.Add("出库类型", typeof(string)); XlsTable.Columns.Add("业务数量", typeof(string)); XlsTable.Columns.Add("金额", typeof(string)); XlsTable.Columns.Add("部门", typeof(string)); XlsTable.Columns.Add("经办人", typeof(string)); XlsTable.Columns.Add("操作人", typeof(string)); XlsTable.Columns.Add("备注", typeof(string)); XlsTable.Columns.Add("出库状态", typeof(string)); foreach (DataGridViewRow dgRow in gvLossQueryBillList.Rows) { DataRow TableRow = XlsTable.NewRow();//创建表行项 TableRow["单据编号"] = dgRow.Cells["BillNum"].Value.ToString(); TableRow["单据日期"] = dgRow.Cells["BillDate"].Value.ToString(); TableRow["仓库"] = dgRow.Cells["WHName"].Value.ToString(); TableRow["出库类型"] = dgRow.Cells["OutWhType"].Value.ToString(); TableRow["业务数量"] = dgRow.Cells["TotalCount"].Value.ToString(); TableRow["金额"] = dgRow.Cells["TotalMoney"].Value.ToString(); TableRow["部门"] = dgRow.Cells["DepartName"].Value.ToString(); TableRow["经办人"] = dgRow.Cells["HandlerName"].Value.ToString(); TableRow["操作人"] = dgRow.Cells["OpeName"].Value.ToString(); TableRow["备注"] = dgRow.Cells["Remarks"].Value.ToString(); TableRow["出库状态"] = dgRow.Cells["OutWhState"].Value.ToString(); XlsTable.Rows.Add(TableRow); } ImportExportExcel.NPOIExportExcelFile(XlsTable, ExportXlsName);//生成Excel表格文件 } } catch (Exception ex) { MessageBoxEx.Show(ex.Message, "异常提示", MessageBoxButtons.OK, MessageBoxIcon.Question); } }
/// <summary> /// 导出Excel文件操作 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ExcelExport_Click(object sender, EventArgs e) { try { if (gvStockList.Rows.Count == 0) //判断gridview中是否有数据记录 { MessageBoxEx.Show("您要导出的单据列表不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { DataTable XlsTable = new DataTable();//导出的数据表格 //创建表列项 XlsTable.Columns.Add("配件编码", typeof(string)); XlsTable.Columns.Add("配件名称", typeof(string)); XlsTable.Columns.Add("图号", typeof(string)); XlsTable.Columns.Add("规格", typeof(string)); XlsTable.Columns.Add("配件类别", typeof(string)); XlsTable.Columns.Add("账面库存", typeof(string)); XlsTable.Columns.Add("实际库存", typeof(string)); XlsTable.Columns.Add("占用库存", typeof(string)); XlsTable.Columns.Add("可用库存", typeof(string)); XlsTable.Columns.Add("参考进价", typeof(string)); XlsTable.Columns.Add("条码", typeof(string)); XlsTable.Columns.Add("重量", typeof(string)); XlsTable.Columns.Add("最高进价", typeof(string)); XlsTable.Columns.Add("最低售价", typeof(string)); XlsTable.Columns.Add("会员价", typeof(string)); XlsTable.Columns.Add("一级进价", typeof(string)); XlsTable.Columns.Add("二级进价", typeof(string)); XlsTable.Columns.Add("三级进价", typeof(string)); XlsTable.Columns.Add("一级销价", typeof(string)); XlsTable.Columns.Add("二级销价", typeof(string)); XlsTable.Columns.Add("三级销价", typeof(string)); XlsTable.Columns.Add("车型", typeof(string)); XlsTable.Columns.Add("产地", typeof(string)); XlsTable.Columns.Add("品牌", typeof(string)); XlsTable.Columns.Add("车厂编码", typeof(string)); XlsTable.Columns.Add("备注", typeof(string)); XlsTable.Columns.Add("启停用标志", typeof(string)); foreach (DataGridViewRow dgRow in gvStockList.Rows) { DataRow TableRow = XlsTable.NewRow();//创建表行项 TableRow["配件编码"] = dgRow.Cells["PartNum"].Value.ToString(); TableRow["配件名称"] = dgRow.Cells["PartName"].Value.ToString(); TableRow["图号"] = dgRow.Cells["DrawingNum"].Value.ToString(); TableRow["规格"] = dgRow.Cells["PartModel"].Value.ToString(); TableRow["配件类别"] = dgRow.Cells["PartCategory"].Value.ToString(); TableRow["账面库存"] = dgRow.Cells["PapCount"].Value.ToString(); TableRow["实际库存"] = dgRow.Cells["PhysicalCount"].Value.ToString(); TableRow["占用库存"] = dgRow.Cells["OccupyCount"].Value.ToString(); TableRow["可用库存"] = dgRow.Cells["AvailableCount"].Value.ToString(); TableRow["参考进价"] = dgRow.Cells["ReferInPrice"].Value.ToString(); TableRow["条码"] = dgRow.Cells["BarCode"].Value.ToString(); TableRow["重量"] = dgRow.Cells["Weight"].Value.ToString(); TableRow["最高进价"] = dgRow.Cells["HighestInPrice"].Value.ToString(); TableRow["最低售价"] = dgRow.Cells["LowestOutPrice"].Value.ToString(); TableRow["会员价"] = dgRow.Cells["VIPPrice"].Value.ToString(); TableRow["一级进价"] = dgRow.Cells["FirstInPrice"].Value.ToString(); TableRow["二级进价"] = dgRow.Cells["SecondInPrice"].Value.ToString(); TableRow["三级进价"] = dgRow.Cells["ThirdInPrice"].Value.ToString(); TableRow["一级销价"] = dgRow.Cells["FirstOutPrice"].Value.ToString(); TableRow["二级销价"] = dgRow.Cells["SecondOutPrice"].Value.ToString(); TableRow["三级销价"] = dgRow.Cells["ThirdOutPrice"].Value.ToString(); TableRow["车型"] = dgRow.Cells["VehicleType"].Value.ToString(); TableRow["产地"] = dgRow.Cells["ProductPlace"].Value.ToString(); TableRow["品牌"] = dgRow.Cells["PartBrand"].Value.ToString(); TableRow["车厂编码"] = dgRow.Cells["FactoryCode"].Value.ToString(); TableRow["备注"] = dgRow.Cells["PartRemark"].Value.ToString(); TableRow["启停用标志"] = dgRow.Cells["ApplyFlag"].Value.ToString(); XlsTable.Rows.Add(TableRow); } ImportExportExcel.NPOIExportExcelFile(XlsTable, ExportXlsName);//生成Excel表格文件 } } catch (Exception ex) { MessageBoxEx.Show(ex.Message, "异常提示", MessageBoxButtons.OK, MessageBoxIcon.Question); } }
/// <summary> /// 导出Excel表格数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ExcelExport_Click(object sender, EventArgs e) { try { DataTable XlsTable = null; //导出的数据表格 if (TabCtrlAllocationBill.SelectedTab == tabPgBill) { //导出按出入库单查询表格 if (gvAllocBillList.Rows.Count == 0) //判断gridview中是否有数据记录 { MessageBoxEx.Show("您要导出的单据列表不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } XlsTable = new DataTable();//导出的数据表格 //创建表列项 XlsTable.Columns.Add("单据类型", typeof(string)); XlsTable.Columns.Add("开单类型", typeof(string)); XlsTable.Columns.Add("单据编号", typeof(string)); XlsTable.Columns.Add("单据日期", typeof(string)); XlsTable.Columns.Add("仓库", typeof(string)); XlsTable.Columns.Add("往来单位", typeof(string)); XlsTable.Columns.Add("数量", typeof(string)); XlsTable.Columns.Add("到货地点", typeof(string)); XlsTable.Columns.Add("部门", typeof(string)); XlsTable.Columns.Add("经办人", typeof(string)); XlsTable.Columns.Add("操作人", typeof(string)); XlsTable.Columns.Add("备注", typeof(string)); foreach (DataGridViewRow dgRow in gvAllocBillList.Rows) { DataRow TableRow = XlsTable.NewRow();//创建表行项 TableRow["单据类型"] = dgRow.Cells["OrderType"].Value.ToString(); TableRow["开单类型"] = dgRow.Cells["BillType"].Value.ToString(); TableRow["单据编号"] = dgRow.Cells["BillNum"].Value.ToString(); TableRow["单据日期"] = dgRow.Cells["BillDate"].Value.ToString(); TableRow["仓库"] = dgRow.Cells["WHName"].Value.ToString(); TableRow["往来单位"] = dgRow.Cells["BusinessUnit"].Value.ToString(); TableRow["数量"] = dgRow.Cells["TotalCount"].Value.ToString(); TableRow["到货地点"] = dgRow.Cells["ArrivePlace"].Value.ToString(); TableRow["部门"] = dgRow.Cells["DepartName"].Value.ToString(); TableRow["经办人"] = dgRow.Cells["HandlerName"].Value.ToString(); TableRow["操作人"] = dgRow.Cells["OpeName"].Value.ToString(); TableRow["备注"] = dgRow.Cells["Remarks"].Value.ToString(); XlsTable.Rows.Add(TableRow); } ImportExportExcel.NPOIExportExcelFile(XlsTable, ExportXlsName);//生成Excel表格文件 } else if (TabCtrlAllocationBill.SelectedTab == tabPgPartBusUnt) {//导出按配件或往来单位查询表格 if (gvAllocPartList.Rows.Count == 0) { MessageBoxEx.Show("您要导出的单据列表不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } XlsTable = new DataTable();//导出的数据表格 //创建表列 XlsTable.Columns.Add("单据类型", typeof(string)); XlsTable.Columns.Add("开单类型", typeof(string)); XlsTable.Columns.Add("出入库单号", typeof(string)); XlsTable.Columns.Add("单据日期", typeof(string)); XlsTable.Columns.Add("配件编码", typeof(string)); XlsTable.Columns.Add("车厂编码", typeof(string)); XlsTable.Columns.Add("配件名称", typeof(string)); XlsTable.Columns.Add("图号", typeof(string)); XlsTable.Columns.Add("规格", typeof(string)); XlsTable.Columns.Add("单位", typeof(string)); XlsTable.Columns.Add("数量", typeof(string)); XlsTable.Columns.Add("车型", typeof(string)); XlsTable.Columns.Add("往来单位编码", typeof(string)); XlsTable.Columns.Add("往来单位名称", typeof(string)); XlsTable.Columns.Add("是否赠品", typeof(string)); XlsTable.Columns.Add("备注", typeof(string)); foreach (DataGridViewRow dgRow in gvAllocPartList.Rows) { DataRow TableRow = XlsTable.NewRow();//创建表行项 TableRow["单据类型"] = dgRow.Cells["OrderPartType"].Value.ToString(); TableRow["开单类型"] = dgRow.Cells["BillingType"].Value.ToString(); TableRow["出入库单号"] = dgRow.Cells["OrderNum"].Value.ToString(); TableRow["单据日期"] = dgRow.Cells["OrderDate"].Value.ToString(); TableRow["配件编码"] = dgRow.Cells["PartCode"].Value.ToString(); TableRow["车厂编码"] = dgRow.Cells["CarPartCode"].Value.ToString(); TableRow["配件名称"] = dgRow.Cells["PartName"].Value.ToString(); TableRow["图号"] = dgRow.Cells["DrawingNum"].Value.ToString(); TableRow["规格"] = dgRow.Cells["Spec"].Value.ToString(); TableRow["单位"] = dgRow.Cells["Unit"].Value.ToString(); TableRow["数量"] = dgRow.Cells["Count"].Value.ToString(); TableRow["车型"] = dgRow.Cells["VehicleModel"].Value.ToString(); TableRow["往来单位编码"] = dgRow.Cells["BusinessUnitCode"].Value.ToString(); TableRow["往来单位名称"] = dgRow.Cells["BussinessunitName"].Value.ToString(); if ((bool)((DataGridViewCheckBoxCell)dgRow.Cells["isgift"]).EditedFormattedValue) { TableRow["是否赠品"] = "是"; } else { TableRow["是否赠品"] = "否"; } TableRow["备注"] = dgRow.Cells["PartRemark"].Value.ToString(); XlsTable.Rows.Add(TableRow); } } } catch (Exception ex) { MessageBoxEx.Show(ex.Message, "异常提示", MessageBoxButtons.OK, MessageBoxIcon.Question); } }