protected bool IsSheetNumberParameter(Parameter parameter) { try { if (parameter == null) { return(false); } if (Sheets.Length == 0) { return(false); } var sheetNumberParameter = Sheets.First().get_Parameter(BuiltInParameter.SHEET_NUMBER); if (parameter?.Id == sheetNumberParameter.Id) { return(true); } } catch (Exception ex) { Logger.Log("Error", ex.Message); } return(false); }
public List <T> GetRowsDataFromFile <T>(string filePath, bool fileHasHeader = false) where T : new() { try { List <T> result = new List <T>(); //open the excel using openxml sdk using (SpreadsheetDocument doc = SpreadsheetDocument.Open(filePath, false)) { //create the object for workbook part WorkbookPart workbookPart = doc.WorkbookPart; Sheets thesheetcollection = workbookPart.Workbook.GetFirstChild <Sheets>(); //using for each loop to get the sheet from the sheetcollection Sheet thesheet = (Sheet)thesheetcollection.First(); //statement to get the worksheet object by using the sheet id Worksheet theWorksheet = ((WorksheetPart)workbookPart.GetPartById(thesheet.Id)).Worksheet; SheetData thesheetdata = (SheetData)theWorksheet.GetFirstChild <SheetData>(); foreach (Row thecurrentrow in thesheetdata) { if (!fileHasHeader) { bool valueObtained = false; int cont = 0; T entity = new T(); PropertyInfo[] propertyInfo = entity.GetType().GetProperties(); foreach (Cell thecurrentcell in thecurrentrow) { if (propertyInfo.Count() > cont) { if (SetValueToProperty(entity, propertyInfo[cont], thecurrentcell, workbookPart)) { valueObtained = true; } cont++; } } // If no value was obtained, then no entity will be added to the list as this could be an empty row if (valueObtained) { result.Add(entity); } } else { fileHasHeader = false; } } } return(result); } catch (Exception) { throw new CAMSExcelLibraryException("Hubo un problema al leer el Excel de ingreso. Aseguresé que la carpeta es accesible y el archivo de Excel no esté abierto.\nEl archivo es: " + filePath); } }
public void AssignPlacement(SheetPlacement plcpr) { current = plcpr; double totalSheetsArea = 0; double totalPartsArea = 0; PlacedPartsCount = 0; List <NFP> placed = new List <NFP>(); foreach (var item in Polygons) { item.sheet = null; } List <int> sheetsIds = new List <int>(); foreach (var item in plcpr.placements) { foreach (var zitem in item) { var sheetid = zitem.sheetId; if (!sheetsIds.Contains(sheetid)) { sheetsIds.Add(sheetid); } var sheet = Sheets.First(z => z.id == sheetid); totalSheetsArea += Math.Abs(GeometryUtil.polygonArea(sheet)); foreach (var ssitem in zitem.sheetplacements) { PlacedPartsCount++; var poly = Polygons.First(z => z.id == ssitem.id); totalPartsArea += Math.Abs(GeometryUtil.polygonArea(poly)); placed.Add(poly); poly.sheet = sheet; poly.x = ssitem.x + sheet.x; poly.y = ssitem.y + sheet.y; poly.rotation = ssitem.rotation; } } } var emptySheets = Sheets.Where(z => !sheetsIds.Contains(z.id)).ToArray(); UsedSheetsCount = Sheets.Count - emptySheets.Length; MaterialUtilization = Math.Abs(totalPartsArea / totalSheetsArea); var ppps = Polygons.Where(z => !placed.Contains(z)); foreach (var item in ppps) { item.x = -1000; item.y = 0; } }
GetFirstWorksheetPart(SpreadsheetDocument document) { Sheets sheets = document.WorkbookPart.Workbook.GetFirstChild <Sheets>(); Sheet s = ((Sheet)sheets.First()); if (s == null) { // The specified worksheet does not exist. throw new ApplicationException(String.Format("No WorkSheet in the file : {0}", document.ToString())); } return((WorksheetPart)document.WorkbookPart.GetPartById(s.Id)); }