本文整理汇总了C#中ExcelAccess.ReadSheetActionRow方法的典型用法代码示例。如果您正苦于以下问题:C# ExcelAccess.ReadSheetActionRow方法的具体用法?C# ExcelAccess.ReadSheetActionRow怎么用?C# ExcelAccess.ReadSheetActionRow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExcelAccess
的用法示例。
在下文中一共展示了ExcelAccess.ReadSheetActionRow方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExcelReports
static void ExcelReports()
{
//Console.WriteLine("Input zip file path: ");
//string zipFilePath = Console.ReadLine();
ArchiveAccess archive = new ArchiveAccess(@"E:\newTeamwork\project\Sample-Reports.zip");
archive.Extract();
OpenAccessMySQL mysqlCon = new OpenAccessMySQL();
ParadiseSupermarketChainEntities sqlCon = new ParadiseSupermarketChainEntities();
using (mysqlCon)
{
using (sqlCon)
{
foreach (var product in mysqlCon.Products)
{
var efProduct = new EntityFramework.Data.Products();
efProduct.Id = product.Id;
efProduct.Name = product.ProductName;
efProduct.BasePrice = (decimal)product.BasePrice;
var measure = sqlCon.Measurements.Where(m => m.Name == product.Measure.MeasureName).FirstOrDefault();
if (measure == null)
{
measure = new EntityFramework.Data.Measurements();
measure.Name = product.Measure.MeasureName;
sqlCon.Measurements.Add(measure);
}
efProduct.Measurements = measure;
var vendor = sqlCon.Vendors.Where(v => v.Name == product.Vendor.VendorName).FirstOrDefault();
if (vendor == null)
{
vendor = new EntityFramework.Data.Vendors();
vendor.Name = product.Vendor.VendorName;
sqlCon.Vendors.Add(vendor);
}
efProduct.Vendors = vendor;
sqlCon.Products.Add(efProduct);
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;
//.........这里部分代码省略.........