static void GetIDList() { List <string> temp = XLSXReader.GetIDList("Data1"); for (int i = 0; i < temp.Count; i++) { Debug.Log(">>>GetFirstRowList: [" + i + "] " + temp[i]); } }
static void GetExcelSheetList() { List <string> temp = XLSXReader.GetExcelSheetList(); for (int i = 0; i < temp.Count; i++) { Debug.Log(">>>GetExcelSheetList: [" + i + "] " + temp[i]); } }
public static InvoiceItemCollection GetInvoiceItems(FileInfo file) { InvoiceItemCollection items = new InvoiceItemCollection(); List <string> worksheets = null; IExcelReader _excelReader = new XLSXReader(file); try { worksheets = _excelReader.GetWorksheetNames(); } catch (Exception exc) { return(items); } foreach (var worksheet in worksheets) { var datasource = _excelReader.GetWorksheet(worksheet); if (datasource != null) { var rows = datasource.Skip(2).Take(7); foreach (IDictionary row in rows) { // uncomment to loop over each cell in the row and print out it's data //foreach (DictionaryEntry cell in row) //{ // System.Diagnostics.Debug.WriteLine(" {0} | {1}", cell.Key, cell.Value); //} //System.Diagnostics.Debug.WriteLine(""); var item = CreateInvoiceItem(row); if (item.Hours > 0) { var foundItem = items.Where(x => x.Description == item.Description).FirstOrDefault(); if (foundItem != null) { foundItem.Hours += item.Hours; } else { items.Add(item); } } } } } return(items); }
public List <TModel> GetModelFromExel <TModel>(Stream fileStream) where TModel : class { ExelModelService exelModelService = new ExelModelService(); var model = Activator.CreateInstance(typeof(TModel)); List <ExelPropertyModel> exelPropertyModels; exelPropertyModels = exelModelService.getClassProperties <TModel>((TModel)model); XLSXReader reader = new XLSXReader(exelPropertyModels); var bookValues = reader.ReadAllCellValues(fileStream); fileStream.Dispose(); return(MapBookValueToModel <TModel>(bookValues, exelPropertyModels)); }
void OnGUI() { if (GUI.Button(new Rect(0, 0, 200, 100), "LoadXlsxOnLine")) { StartCoroutine(XLSXReader.LoadXlsxOnLine()); } if (GUI.Button(new Rect(0, 100, 200, 100), "GetExcelSheetList")) { GetExcelSheetList(); } if (GUI.Button(new Rect(0, 200, 200, 100), "GetHeadList")) { GetHeadList(); } if (GUI.Button(new Rect(0, 300, 200, 100), "GetIDList")) { GetIDList(); } if (GUI.Button(new Rect(0, 400, 200, 100), "GetRowColData")) { GetRowColData(); } }
static void ReadTestExcel() { string path = Path.GetFullPath(Path.Combine(Application.dataPath, TEST_DATA_PATH)); Debug.Log(path); if (File.Exists(path)) { Debug.Log("Excel is existed"); XLSX.ExcelFile ef = XLSXReader.ReadXLSX(path); if (ef != null) { Debug.Log(">>> Find Excel File: " + ef); Debug.Log(">>> Sheet Count: " + ef.SheetCount); } else { Debug.Log("<color=red>Read Excel from " + path + " Failed!</color>"); } } }
/// <summary> /// 导入借款单 /// Creator:安凯航 /// 日期:2011年5月30日 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void btnImportBorrowData_Click(object sender, RoutedEventArgs e) { //导入时间 DateTime createTime = DateTime.Now; OpenFileDialog dialog = new OpenFileDialog() { Multiselect = false, Filter = "Excel 2007-2010 File(*.xlsx)|*.xlsx" }; bool? userClickedOK = dialog.ShowDialog(); // Process input if the user clicked OK. if (userClickedOK != true) { return; } try { //待保存数据列表 List<OrderEntity> orders = new List<OrderEntity>(); #region 读取Excel文件 XLSXReader reader = new XLSXReader(dialog.File); List<string> subItems = reader.GetListSubItems(); var maseters = reader.GetData(subItems[0]); var listm = maseters.ToDataSource(); var details = reader.GetData(subItems[1]); var listd = details.ToDataSource(); List<dynamic> masterList = new List<dynamic>(); foreach (var item in listm) { dynamic d = item; masterList.Add(d); } //排除第一行信息 masterList.Remove(masterList.First()); List<dynamic> detailList = new List<dynamic>(); foreach (var item in listd) { dynamic d = item; detailList.Add(d); } //排除第一行信息 detailList.Remove(detailList.First()); #endregion #region 添加主表 List<T_FB_BORROWAPPLYMASTER> import = new List<T_FB_BORROWAPPLYMASTER>(); foreach (var item in masterList) { //构造OrderEntity数据 OrderEntity oe = new OrderEntity(typeof(T_FB_BORROWAPPLYMASTER)); orders.Add(oe); T_FB_BORROWAPPLYMASTER t = oe.FBEntity.Entity as T_FB_BORROWAPPLYMASTER; t.BORROWAPPLYMASTERID = Guid.NewGuid().ToString(); t.BORROWAPPLYMASTERCODE = item.单据号; if (item.借款类型 == "普通借款") { t.REPAYTYPE = 1; } else if (item.借款类型 == "备用金借款") { t.REPAYTYPE = 2; } else if (item.借款类型 == "专项借款") { t.REPAYTYPE = 3; } else { continue; } t.REMARK = item.备注; import.Add(t); } #endregion #region 添加子表 foreach (var item in detailList) { OrderEntity oe = orders.FirstOrDefault(oen => { T_FB_BORROWAPPLYMASTER bm = oen.FBEntity.Entity as T_FB_BORROWAPPLYMASTER; if (bm.BORROWAPPLYMASTERCODE == item.单据号) { return true; } else { return false; } }); if (oe == null) { string message = "导入的借款单明细借款单号为\"" + item.单据号 + "\"的明细,没有相应的借款单对应.请检查借款Excel中是否有此借款单的数据"; throw new InvalidOperationException(message); } FBEntity fbdetail = oe.CreateFBEntity<T_FB_BORROWAPPLYDETAIL>(); T_FB_BORROWAPPLYDETAIL d = fbdetail.Entity as T_FB_BORROWAPPLYDETAIL; d.BORROWAPPLYDETAILID = Guid.NewGuid().ToString(); d.REMARK = item.摘要; d.BORROWMONEY = Convert.ToDecimal(item.借款金额); d.UNREPAYMONEY = Convert.ToDecimal(item.未还款金额); d.T_FB_SUBJECT = d.T_FB_SUBJECT ?? new T_FB_SUBJECT(); d.T_FB_SUBJECT.SUBJECTID = item.借款科目; d.CREATEDATE = createTime; d.CREATEUSERID = SMT.SAAS.Main.CurrentContext.Common.CurrentLoginUserInfo.EmployeeID; d.UPDATEDATE = createTime; d.UPDATEUSERID = SMT.SAAS.Main.CurrentContext.Common.CurrentLoginUserInfo.EmployeeID; } #endregion //服务 OrderEntityService service = new OrderEntityService(); #region 得到科目信息 QueryExpression reExp = QueryExpressionHelper.Equal("OWNERID", SMT.SAAS.Main.CurrentContext.Common.CurrentLoginUserInfo.EmployeeID); QueryExpression exp = QueryExpressionHelper.Equal("OWNERPOSTID", SMT.SAAS.Main.CurrentContext.Common.CurrentLoginUserInfo.UserPosts[0].PostID); exp.QueryType = "T_FB_BORROWAPPLYDETAIL"; exp.RelatedExpression = reExp; exp.IsUnCheckRight = true; #endregion #region 获取申请人信息 ObservableCollection<string> numbers = new ObservableCollection<string>(); masterList.ForEach(item => numbers.Add(item.申请人身份证号));//拿到所有身份证号 SMT.Saas.Tools.PersonnelWS.PersonnelServiceClient client = new Saas.Tools.PersonnelWS.PersonnelServiceClient(); client.GetEmployeesByIdnumberAsync(numbers); #endregion #region 先获取申请人信息,待申请人信息填充完毕之后进行下一步操作 client.GetEmployeesByIdnumberCompleted += new EventHandler<Saas.Tools.PersonnelWS.GetEmployeesByIdnumberCompletedEventArgs>((oo, ee) => { if (ee.Error == null) { string message = null; try { masterList.ForEach(m => { //添加owner和creator SMT.Saas.Tools.PersonnelWS.V_EMPLOYEEVIEW userview = null; try { userview = ee.Result.First(t => t.IDNUMBER == m.申请人身份证号); } catch (InvalidOperationException ex) { message = ex.Message + "\n" + "在系统中找不到身份证号为\"" + m.申请人身份证号 + "\"的,员工信息.也可能是您没有相应的权限."; throw new InvalidOperationException(message); } T_FB_BORROWAPPLYMASTER master = null; try { master = import.First(t => t.BORROWAPPLYMASTERCODE == m.单据号); } catch (InvalidOperationException ex) { message = ex.Message + "\n" + "导入的借款单明细借款单号为\"" + m.单据号 + "\"的明细,没有相应的借款单对应.请检查借款Excel中是否有此借款单的数据"; throw new InvalidOperationException(message); } master.OWNERCOMPANYID = userview.OWNERCOMPANYID; master.OWNERCOMPANYNAME = userview.OWNERCOMPANYID; master.OWNERDEPARTMENTID = userview.OWNERDEPARTMENTID; master.OWNERID = userview.EMPLOYEEID; master.OWNERPOSTID = userview.OWNERPOSTID; master.CREATECOMPANYID = SMT.SAAS.Main.CurrentContext.Common.CurrentLoginUserInfo.UserPosts[0].CompanyID; master.CREATECOMPANYNAME = SMT.SAAS.Main.CurrentContext.Common.CurrentLoginUserInfo.UserPosts[0].CompanyName; master.CREATEDEPARTMENTID = SMT.SAAS.Main.CurrentContext.Common.CurrentLoginUserInfo.UserPosts[0].DepartmentID; master.CREATEDEPARTMENTNAME = SMT.SAAS.Main.CurrentContext.Common.CurrentLoginUserInfo.UserPosts[0].DepartmentName; master.CREATEPOSTID = SMT.SAAS.Main.CurrentContext.Common.CurrentLoginUserInfo.UserPosts[0].PostID; master.CREATEPOSTNAME = SMT.SAAS.Main.CurrentContext.Common.CurrentLoginUserInfo.UserPosts[0].PostName; master.CREATEUSERID = SMT.SAAS.Main.CurrentContext.Common.CurrentLoginUserInfo.EmployeeID; master.CREATEUSERNAME = SMT.SAAS.Main.CurrentContext.Common.CurrentLoginUserInfo.EmployeeName; master.CREATEDATE = createTime; master.UPDATEUSERID = SMT.SAAS.Main.CurrentContext.Common.CurrentLoginUserInfo.EmployeeID; master.UPDATEUSERNAME = SMT.SAAS.Main.CurrentContext.Common.CurrentLoginUserInfo.EmployeeName; master.UPDATEDATE = createTime; }); //填充完申请人信息之后开始填充科目信息 service.QueryFBEntities(exp); } catch (Exception ex) { SMT.SaaS.FrameworkUI.ChildWidow.ComfirmWindow.ConfirmationBoxs("导入出错", ex.Message, "确定", MessageIcon.Exclamation); } } }); #endregion #region 填充完申请人信息之后开始填充科目信息 service.QueryFBEntitiesCompleted += new EventHandler<QueryFBEntitiesCompletedEventArgs>((o, args) => { if (args.Error == null) { //构造明细科目及账务信息 string message = null; try { import.ForEach(m => { OrderEntity oe = orders.FirstOrDefault(oen => { T_FB_BORROWAPPLYMASTER bm = oen.FBEntity.Entity as T_FB_BORROWAPPLYMASTER; if (bm.BORROWAPPLYMASTERCODE == m.BORROWAPPLYMASTERCODE) { return true; } else { return false; } }); var dlist = oe.GetRelationFBEntities("T_FB_BORROWAPPLYDETAIL"); List<T_FB_BORROWAPPLYDETAIL> detailslist = new List<T_FB_BORROWAPPLYDETAIL>(); dlist.ForEach(ddd => { detailslist.Add(ddd.Entity as T_FB_BORROWAPPLYDETAIL); }); detailslist.ForEach(d => { FBEntity en = null; try { en = args.Result.First(a => ((T_FB_BORROWAPPLYDETAIL)a.Entity).T_FB_SUBJECT.SUBJECTCODE == d.T_FB_SUBJECT.SUBJECTID); } catch (InvalidOperationException ex) { message = ex.Message + "\n" + "导入的借款单明细中,在系统中找不到ID为\"" + d.T_FB_SUBJECT.SUBJECTID + "\"的科目,也可能是您没有相应的权限"; throw new InvalidOperationException(message); } T_FB_BORROWAPPLYDETAIL t = en.Entity as T_FB_BORROWAPPLYDETAIL; if (t != null) { t.T_FB_SUBJECT.T_FB_BORROWAPPLYDETAIL.Clear(); d.T_FB_SUBJECT = t.T_FB_SUBJECT; d.CHARGETYPE = t.CHARGETYPE; d.USABLEMONEY = t.USABLEMONEY; #region 清理科目信息中的无用数据 t.T_FB_SUBJECT.T_FB_BORROWAPPLYDETAIL.Clear(); t.T_FB_SUBJECT.T_FB_BUDGETACCOUNT.Clear(); t.T_FB_SUBJECT.T_FB_BUDGETCHECK.Clear(); t.T_FB_SUBJECT.T_FB_CHARGEAPPLYDETAIL.Clear(); t.T_FB_SUBJECT.T_FB_COMPANYBUDGETAPPLYDETAIL.Clear(); t.T_FB_SUBJECT.T_FB_COMPANYBUDGETMODDETAIL.Clear(); t.T_FB_SUBJECT.T_FB_COMPANYBUDGETMODDETAIL.Clear(); t.T_FB_SUBJECT.T_FB_COMPANYTRANSFERDETAIL.Clear(); t.T_FB_SUBJECT.T_FB_DEPTBUDGETADDDETAIL.Clear(); t.T_FB_SUBJECT.T_FB_DEPTBUDGETAPPLYDETAIL.Clear(); t.T_FB_SUBJECT.T_FB_DEPTTRANSFERDETAIL.Clear(); t.T_FB_SUBJECT.T_FB_EXTENSIONORDERDETAIL.Clear(); t.T_FB_SUBJECT.T_FB_PERSONBUDGETADDDETAIL.Clear(); t.T_FB_SUBJECT.T_FB_PERSONBUDGETAPPLYDETAIL.Clear(); t.T_FB_SUBJECT.T_FB_PERSONMONEYASSIGNDETAIL.Clear(); t.T_FB_SUBJECT.T_FB_REPAYAPPLYDETAIL.Clear(); t.T_FB_SUBJECT.T_FB_SUBJECTCOMPANY.Clear(); t.T_FB_SUBJECT.T_FB_SUBJECTDEPTMENT.Clear(); t.T_FB_SUBJECT.T_FB_SUBJECTPOST.Clear(); t.T_FB_SUBJECT.T_FB_TRAVELEXPAPPLYDETAIL.Clear(); #endregion } }); }); //保存 service.SaveList(orders); } catch (Exception ex) { SMT.SaaS.FrameworkUI.ChildWidow.ComfirmWindow.ConfirmationBoxs("导入出错", ex.Message, "确定", MessageIcon.Exclamation); } } }); #endregion #region 所有信息构造完成之后保存数据 service.SaveListCompleted += new EventHandler<ActionCompletedEventArgs<bool>>((s, evgs) => { if (evgs.Result) { SMT.SaaS.FrameworkUI.ChildWidow.ComfirmWindow.ConfirmationBox("导入成功", "导入成功", "确定"); } else { SMT.SaaS.FrameworkUI.ChildWidow.ComfirmWindow.ConfirmationBox("导入失败", "导入失败", "确定"); } }); #endregion } catch (Exception ex) { SMT.SaaS.FrameworkUI.ChildWidow.ComfirmWindow.ConfirmationBoxs("导入出错", ex.Message, "确定", MessageIcon.Exclamation); } }
public IEnumerable insertFromExcel(PXAdapter adapter) { if (this.MatrixItems4Creation.AskExt() == WebDialogResult.OK) { int num1 = 1; FileInfo fileInfo = PXContext.SessionTyped <PXSessionStatePXData>().FileInfo["ImportMatrixFile"]; //HttpContext.Current.Session.Remove("ImportMatrixFile"); using (XLSXReader xlsxReader = new XLSXReader(fileInfo.BinData)) { xlsxReader.Reset(); xlsxReader.IndexKeyPairs.ToDictionary <KeyValuePair <int, string>, int, string>((Func <KeyValuePair <int, string>, int>)(p => p.Key), (Func <KeyValuePair <int, string>, string>)(p => p.Value)); xlsxReader.MoveNext(); while (xlsxReader.MoveNext()) { try { InventoryItem template = InventoryItem.PK.Find((PXGraph)this.Base, this.Base1.Header.Current.TemplateItemID); CreateMatrixItemsHelper matrixItemsHelper = new CreateMatrixItemsHelper((PXGraph)this.Base); System.Collections.Generic.List <INMatrixGenerationRule> idGenerationRules; System.Collections.Generic.List <INMatrixGenerationRule> descrGenerationRules; matrixItemsHelper.GetGenerationRules(this.Base1.Header.Current.TemplateItemID, out idGenerationRules, out descrGenerationRules); foreach (EntryMatrix row in this.Base1.Matrix.Cache.Cached.Cast <EntryMatrix>().Where <EntryMatrix>((Func <EntryMatrix, bool>)(entry => { bool?isPreliminary = entry.IsPreliminary; bool flag = true; return(!(isPreliminary.GetValueOrDefault() == flag & isPreliminary.HasValue)); }))) { for (int attributeNumber = 0; attributeNumber < row.InventoryIDs.Length; ++attributeNumber) { MatrixInventoryItem newItem = matrixItemsHelper.CreateMatrixItemFromTemplate(row, attributeNumber, template, idGenerationRules, descrGenerationRules); if (newItem != null) { newItem.InventoryCD = xlsxReader.GetValue(2); newItem.Descr = xlsxReader.GetValue(3); newItem.InventoryID = new int?(++num1); newItem.Duplicate = new bool?(this.Base.Caches[typeof(MatrixInventoryItem)].Cached.RowCast <MatrixInventoryItem>().Any <MatrixInventoryItem>((Func <MatrixInventoryItem, bool>)(mi => mi.InventoryCD == newItem.InventoryCD))); MatrixInventoryItem matrixInventoryItem = newItem; bool?exists = newItem.Exists; bool flag1 = true; int num2; if (!(exists.GetValueOrDefault() == flag1 & exists.HasValue)) { bool?duplicate = newItem.Duplicate; bool flag2 = true; num2 = !(duplicate.GetValueOrDefault() == flag2 & duplicate.HasValue) ? 1 : 0; } else { num2 = 0; } bool?nullable = new bool?(num2 != 0); matrixInventoryItem.Selected = nullable; System.Collections.Generic.List <string> stringList = new System.Collections.Generic.List <string>(); for (int index = 15; index <= xlsxReader.IndexKeyPairs.Count; ++index) { stringList.Add(xlsxReader.GetValue(index)); } newItem.AttributeValues = stringList.ToArray(); this.Base1.MatrixItemsForCreation.Cache.Hold((object)newItem); } } } } catch (Exception ex) { throw ex; } finally { xlsxReader.Dispose(); } } } } return(adapter.Get()); }
static void GetRowColData() { Debug.Log("GetData :Data1, 10, data " + XLSXReader.GetRowColData("Data1", "10", "data")); }