当前位置: 首页>>代码示例>>C#>>正文


C# ExcelAccess.Close方法代码示例

本文整理汇总了C#中ExcelAccess.Close方法的典型用法代码示例。如果您正苦于以下问题:C# ExcelAccess.Close方法的具体用法?C# ExcelAccess.Close怎么用?C# ExcelAccess.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ExcelAccess的用法示例。


在下文中一共展示了ExcelAccess.Close方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExcelReports


//.........这里部分代码省略.........
                        try
                        {
                            sqlCon.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            //Console.WriteLine(e.InnerException.InnerException.Message);
                        }
                    }
                }
            }

            // get the info from the unzipped folder
            string unzippedFolderName = "Paradise-Sample-Reports";
            string unzippedFolderPath = String.Format(@"../../../{0}", unzippedFolderName);

            foreach (var dir in Directory.GetDirectories(archive.ExtractPath))
            {
                foreach (var file in Directory.GetFiles(dir, "*.xls"))
                {
                    string currentFolderName = Path.GetFileName(dir);
                    DateTime currentDate = DateTime.Parse(currentFolderName);
                    string fileName = Path.GetFileName(file);

                    using (var db = new ParadiseSupermarketChainEntities())
                    {
                        var excelComs = new ExcelAccess(file);
                        string supermarketName = null;
                        int rowIndex = 0;

                        excelComs.Open();

                        excelComs.ReadSheetActionRow("Sales", (row) =>
                        {
                            rowIndex++;
                            if (rowIndex <= 2)
                            {
                                if (row.Count == 1 && row[0].ToString().IndexOf("Supermarket") != -1)
                                {
                                    // this is the supermarket Name
                                    supermarketName = row[0] + "";
                                }
                                // skip the first 2 rows
                                return;
                            }

                            if (row.Count == 4)
                            {
                                // add a product
                                int productId = int.Parse((row[0] + ""));
                                double quantity = double.Parse((row[1] + ""));
                                decimal unitPrice = decimal.Parse((row[2] + ""));
                                decimal sum = decimal.Parse((row[3] + ""));

                                Sales productSales = new Sales();
                                productSales.ProductId = productId;
                                productSales.Quantity = quantity;
                                productSales.UnitPrice = unitPrice;
                                productSales.Sum = sum;

                                // find out if the supermarket exists

                                Supermarkets supermarket =
                                        db.Supermarkets.Where(s =>
                                            s.Name == supermarketName).FirstOrDefault();
                                if (supermarket == null)
                                {
                                    supermarket = new Supermarkets();
                                    supermarket.Name = supermarketName;
                                    db.Supermarkets.Add(supermarket);
                                }

                                productSales.Supermarkets = supermarket;

                                // find out if the date exists
                                Dates date =
                                    db.Dates.Where(d => d.Date == currentDate).FirstOrDefault();
                                if (date == null)
                                {
                                    date = new Dates();
                                    date.Date = currentDate;
                                    db.Dates.Add(date);
                                }

                                productSales.Dates = date;

                                db.Sales.Add(productSales);
                                db.SaveChanges();
                            }
                            else
                            {
                                // the final line: the sum of the products
                            }
                        });
                        excelComs.Close();
                    }
                }
            }
            Directory.Delete(archive.ExtractPath, true);
        }
开发者ID:kaloyan-gospodinov,项目名称:ParadiseSuperMarket,代码行数:101,代码来源:Program.cs


注:本文中的ExcelAccess.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。