public void ReadProductFromExcelTest() { string filePath = Environment.CurrentDirectory + @"\TestFiles\NTS 产品报价单 哈慈 20130306.xls"; ProductExcelReader importer = new ProductExcelReader(); IList<Product> products = importer.Read(new System.IO.FileStream(filePath, System.IO.FileMode.Open)); Assert.AreEqual(19,products.Count); }
public void ReadProductErpEnglishFromExcel() { string filePath = Environment.CurrentDirectory + @"\TestFiles\英文——2013-3-26家具(brighthome)数据表.XLS"; ProductExcelReader importer = new ProductExcelReader(); IList<Product> products = importer.Read(new System.IO.FileStream(filePath, System.IO.FileMode.Open)); Assert.AreEqual(153, products.Count); //Assert.AreEqual("01.001", products[0].CategoryCode); }
public void ReadProductFromErpExcelTest() { string filePath = Environment.CurrentDirectory + @" \TestFiles\吧台设备及用具.XLS"; ProductExcelReader importer = new ProductExcelReader(); IList<Product> products = importer.Read(new System.IO.FileStream(filePath, System.IO.FileMode.Open)); Assert.AreEqual(40, products.Count); Assert.AreEqual("01.001", products[0].CategoryCode); }
/// <summary> /// 图片命名 /// </summary> /// <param name="supplierName"></param> /// <param name="productType"></param> /// <param name="ntsCode"></param> public void Excute(string filePath,string savePath) { ProductExcelReader importer = new ProductExcelReader(); System.Collections.IList allPictures; IList<Product> products = importer.Read(new System.IO.FileStream(filePath, System.IO.FileMode.Open), out allPictures); if (products.Count != allPictures.Count) { throw new Exception(string.Format( "提取失败:产品和图片的数量不相等.产品:{0},图片:{1}",products.Count,allPictures.Count)); } for (int i = 0; i < products.Count; i++) { HSSFPictureData pic = (HSSFPictureData)allPictures[i]; var modelNumber =NLibrary.StringHelper.ReplaceInvalidChaInFileName(products[i].ModelNumber,"$")+".jpg"; string fileName=savePath+modelNumber; NLibrary.IOHelper.EnsureFileDirectory(fileName); File.WriteAllBytes(fileName, pic.Data); } }