예제 #1
0
        //public void ExcelWrite(string file)
        //{
        //    try
        //    {
        //        using (ExcelHelper excelHelper = new ExcelHelper(file))
        //        {
        //            DataTable data = GenerateData();
        //            deptBLL getdataDept = new deptBLL();    //写一个从数据库查出来的表

        //            DataTable data = getdataDept.GetdatagetdataDept();
        //            int count = excelHelper.DataTableToExcel(data, "MySheet", true);
        //            if (count > 0)
        //                Console.WriteLine("Number of imported data is {0} ", count);
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        Console.WriteLine("Exception: " + ex.Message);
        //    }
        //}

        //读EXCEL   导入EXCEL表
        public tradingComanyPO[] ExcelRead(string file, string sheetname, int headno)
        {
            try
            {
                using (ExcelHelper excelHelper = new ExcelHelper(file))
                {
                    DataTable dt = excelHelper.ExcelToDataTable(sheetname, headno);
                    if (dt.Rows.Count <= 0)
                    {
                        return(null);
                    }
                    else
                    {
                        //要显示的文件的model 例emp
                        tradingComanyPO[] gtnPOS = new tradingComanyPO[dt.Rows.Count];
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            gtnPOS[i] = ToModel(dt.Rows[i]);//这里转换过来
                        }
                        return(gtnPOS);
                        //InterBoxLableWind IExcel = new InterBoxLableWind();
                        // IExcel.dvgInnerBox.ItemsSource = InnerBoxs;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message);
                return(null);
            }
        }
예제 #2
0
            private tradingComanyPO EmpToModel(DataRow row)//建立要导入的文件的model
            {
                tradingComanyPO emps = new tradingComanyPO();

                for (int i = 0; i < row.ItemArray.Length; i++)
                {
                    if (row.ItemArray.Length > 0)
                    {
                        emps.id = Convert.ToInt32(row.ItemArray[0].ToString());
                    }
                    if (row.ItemArray.Length > 1)
                    {
                        emps.PO = Convert.ToString(row.ItemArray[1].ToString());
                    }
                    if (row.ItemArray.Length > 2)
                    {
                        emps.GTN_PO = Convert.ToString(row.ItemArray[2].ToString());
                    }
                    if (row.ItemArray.Length > 3)
                    {
                        emps.create_pc = Convert.ToString(row.ItemArray[3].ToString());
                    }
                    if (row.ItemArray.Length > 4)
                    {
                        emps.update_date = Convert.ToString(row.ItemArray[4].ToString());
                    }
                }
                return(emps);
            }
예제 #3
0
        private tradingComanyPO ToModel(DataRow row)//建立要导入的文件的model
        {
            tradingComanyPO gtnPO = new tradingComanyPO();

            /*
             * if (row.ItemArray.Length > 0)
             * {
             *  gtnPO.id = Convert.ToInt32( row.ItemArray[0].ToString());
             * }
             */

            if (row.ItemArray.Length > 0)
            {
                gtnPO.PO = Convert.ToString(row.ItemArray[0].ToString());
            }

            if (row.ItemArray.Length > 1)
            {
                gtnPO.GTN_PO = Convert.ToString(row.ItemArray[1].ToString());
            }
            if (row.ItemArray.Length > 2)
            {
                gtnPO.fCreate_Date = Convert.ToString(row.ItemArray[2].ToString());
            }

            if (row.ItemArray.Length > 3)
            {
                gtnPO.fIssue_Date = Convert.ToString(row.ItemArray[3].ToString());
            }
            if (row.ItemArray.Length > 4)
            {
                gtnPO.fOrder_Status = Convert.ToString(row.ItemArray[4].ToString());
            }
            if (row.ItemArray.Length > 5)
            {
                gtnPO.fOrder_Total_Qty = Convert.ToString(row.ItemArray[5].ToString());
            }
            if (row.ItemArray.Length > 6)
            {
                gtnPO.fInvoiced_Item_Qty = Convert.ToString(row.ItemArray[6].ToString());
            }
            return(gtnPO);
        }