/// <summary> /// Creates a new neural cell that is added to this network. /// </summary> /// <returns>Reference to the newly created cell.</returns> public TCellType CreateCell <TCellType>() where TCellType : BaseCell, new() { TCellType newCell = new TCellType(); newCell.PositionCell(NetworkVolume); Cells.Add(newCell); return(newCell); }
public static THFlxAlignment GetDataAlign(TCellType CellType, TFlxFormat Fm) { switch (Fm.HAlignment) { case THFlxAlignment.general: return(GetGeneralAlign(CellType)); case THFlxAlignment.center_across_selection: case THFlxAlignment.center: return(THFlxAlignment.center); case THFlxAlignment.right: return(THFlxAlignment.right); } return(THFlxAlignment.left); }
private static THFlxAlignment GetGeneralAlign(TCellType CellType) { switch (CellType) { case TCellType.Bool: case TCellType.Error: return(THFlxAlignment.center); case TCellType.String: case TCellType.Unknown: return(THFlxAlignment.left); case TCellType.Number: return(THFlxAlignment.right); default: return(THFlxAlignment.right); } }
internal static void Write(TextWriter OutString, ExcelFile Workbook, TXlsCellRange Range, int[] ColumnWidths, int CharactersForFirstColumn, bool ExportHiddenRowsOrColumns, bool ExportTextOutsideCells) { if (Range == null) { Range = new TXlsCellRange(1, 1, Workbook.RowCount, Workbook.GetColCount(Workbook.ActiveSheet, false)); } for (int r = Range.Top; r <= Range.Bottom; r++) { if (!ExportHiddenRowsOrColumns && Workbook.GetRowHidden(r)) { continue; } int cIndex = 0; double FirstColWidth = Workbook.GetColWidth(Range.Left); string Remaining = string.Empty; int AcumColLen = 0; bool InMergedCell = false; THFlxAlignment MergedAlign = THFlxAlignment.general; TCellType MergedType = TCellType.Unknown; int OrigColLen = 0; for (int c = Range.Left; c <= Range.Right; c++) { if (!ExportHiddenRowsOrColumns && Workbook.GetColHidden(c)) { continue; } string s = Workbook.GetStringFromCell(r, c).ToString(); TFlxFormat fmt = null; if (ExportTextOutsideCells) { fmt = Workbook.GetCellVisibleFormatDef(r, c); } if (string.IsNullOrEmpty(s)) { s = Remaining; } int ColLen = 0; if (ColumnWidths == null) { if (CharactersForFirstColumn <= 0) { ColLen = s.Length; } else if (FirstColWidth <= 0) { ColLen = 0; } else { ColLen = (int)Math.Round((double)CharactersForFirstColumn * Workbook.GetColWidth(c) / FirstColWidth); } } else { if (cIndex >= ColumnWidths.Length) { break; } ColLen = ColumnWidths[cIndex]; } cIndex++; if (InMergedCell) { OrigColLen += ColLen; } else { OrigColLen = ColLen; } if (s.Length == 0) { AcumColLen += ColLen; continue; } THFlxAlignment HAlign = THFlxAlignment.left; TCellType CellType; if (InMergedCell) { HAlign = MergedAlign; CellType = MergedType; } else { Object CellVal = Workbook.GetCellValue(r, c); TFormula fmla = CellVal as TFormula; if (fmla != null) { CellVal = fmla.Result; } CellType = TExcelTypes.ObjectToCellType(CellVal); if (ExportTextOutsideCells && fmt != null && Remaining.Length == 0) { HAlign = GetDataAlign(CellType, fmt); } } if (HAlign == THFlxAlignment.left) { OutString.Write(new string(' ', AcumColLen)); } else { TXlsCellRange mr = Workbook.CellMergedBounds(r, c); InMergedCell = mr.Right > c; if (mr.Right > c) { AcumColLen += ColLen; if (c == mr.Left) { Remaining = s; MergedAlign = HAlign; MergedType = CellType; } continue; } if (mr.Right > mr.Left) { s = Remaining; Remaining = string.Empty; } MergedAlign = THFlxAlignment.left; MergedType = TCellType.Unknown; InMergedCell = false; ColLen += AcumColLen; } AcumColLen = 0; if (s.Length > ColLen) { if (ExportTextOutsideCells && HAlign == THFlxAlignment.right) { if (CellType == TCellType.Number) { OutString.Write(new string('#', ColLen)); } else { OutString.Write(s.Substring(s.Length - ColLen)); } } else { OutString.Write(s.Substring(0, ColLen)); } if (ExportTextOutsideCells && HAlign != THFlxAlignment.right) { Remaining = s.Substring(ColLen); } } else { int Pad = ColLen - s.Length; if (ExportTextOutsideCells && Remaining.Length == 0) { Pad = TextAlign(OutString, HAlign, s.Length, ColLen, OrigColLen); } OutString.Write(s); OutString.Write(new string(' ', Pad)); Remaining = string.Empty; } } if (ExportTextOutsideCells && Remaining.Length > 0) { OutString.Write(Remaining); } Remaining = string.Empty; OutString.Write(TCompactFramework.NewLine); } }