Ejemplo n.º 1
0
		public StringBuilder DelimitedRow(StringBuilder sb, List<Field> datacols, string delim, SpreadSheetLayout ssl)
		{
			bool isFirst = true;
			datacols.OrderBy(d => d.OutputOrder).ToList().ForEach(d =>
			{
				try
				{
					string val = null;

					switch (d.fldType)
					{
						case FieldType.column:
							val = Cells.ContainsKey(d.OutputOrder) ? Cells[d.OutputOrder].Value ?? "" : "";
							break;
						case FieldType.cell:
						case FieldType.fileName:
						case FieldType.filePath:
							var df = this.Sheet.sLayout.matchData.fldCellMap.fldmaps.FirstOrDefault(fm => fm.field.OutputOrder == d.OutputOrder);
							val = (df != null ? df.Value ?? "" : "");
							break;
					}

					sb.Append((isFirst ? "" : delim) + val);
					isFirst = false;
				}
				catch (Exception ex)
				{
					Log.New.Msg(ex);
				}
			});

			ssl.sLayouts.Where(sl => sl.sheetType == SheetType.CommonData).ToList().ForEach(sl =>
			{
				sl.matchData.fldCellMap.fldmaps.OrderBy(fm => fm.field.OutputOrder).ToList().ForEach(fm =>
				{
					sb.Append(delim);
					sb.Append(fm.Value ?? "");
				});
			});

			Cells.Clear();
			return sb;
		}
Ejemplo n.º 2
0
		public string GetColumnHeaders(StringBuilder sb, string fldDelimiter, string rowDelimieter, SpreadSheetLayout ssl)
		{
			bool isFirst = true;
			foreach (var c in sLayout.wsLayout.fields)
			{
				if (!isFirst)
					sb.Append(fldDelimiter);

				sb.Append(c.Name);
				
				isFirst = false;
			}

			var fldtypes = new List<FieldType> { FieldType.cell, FieldType.fileName, FieldType.filePath };
			ssl.sLayouts.Where(sl => sl.sheetType == SheetType.CommonData).ToList().ForEach(sl =>
			{
				sl.wsLayout.fields.OrderBy(f => f.OutputOrder).Where(f => fldtypes.Contains(f.fldType)).ToList().ForEach(f =>
				{
					sb.Append(fldDelimiter);
					sb.Append(f.Name);
				});
			});

			sb.Append(rowDelimieter);
			return sb.ToString();
		}
Ejemplo n.º 3
0
		public void Write(SpreadSheetLayout ssl)
		{
			if (Rows == null) return;

			string fn = $"{sLayout.wsLayout.OutputFileName}_{sLayout.wsLayout.dst.timeStamp.ToString("yyyyMMdd_HHmmss")}.txt";

			string fp = Path.Combine(sLayout.wsLayout.dst.RootFolder, fn);
			StringBuilder sb = new StringBuilder();

			if (!File.Exists(fp))
				this.GetColumnHeaders(sb, sLayout.wsLayout.fldDelim, sLayout.wsLayout.recDelim, ssl);

			this.GetDelimitedRows(sb, sLayout.wsLayout.fldDelim, sLayout.wsLayout.recDelim, ssl);

			File.AppendAllText(fp, sb.ToString());
		}
Ejemplo n.º 4
0
		public StringBuilder GetDelimitedRows(StringBuilder sb, string fldDelimiter, string rowDelimiter, SpreadSheetLayout ssl)
		{
			Rows.ToList().ForEach(r => 
			{
				r.Value.DelimitedRow(sb, sLayout.wsLayout.fields, fldDelimiter, ssl);
				sb.Append(rowDelimiter);
			});

			Rows.Clear();
			return sb;
		}