private static string PrintContent(VirtualSpreadsheet spreadsheet) { var columnsLength = Enumerable.Range(1, spreadsheet.ColumnsCount) .Select(columnIndex => GetColumn(spreadsheet, columnIndex).Max(value => value.Length) ).ToArray(); // create the string format with padding var format = Enumerable.Range(0, spreadsheet.ColumnsCount) .Select(i => " | {" + i + ",-" + columnsLength[i] + "}") .Aggregate((s, a) => s + a) + " |" + Environment.NewLine; // create the divider var divider = " " + new string('-', columnsLength.Sum() + columnsLength.Length * 3 + 1) + " "; var builder = new StringBuilder(); builder.AppendLine(divider); for (var rowIndex = 1; rowIndex <= spreadsheet.RowsCount; rowIndex++) { // ReSharper disable once CoVariantArrayConversion object[] row = GetRow(spreadsheet, rowIndex).ToArray(); builder.AppendFormat(format, row); builder.AppendLine(divider); } return(builder.ToString()); }
private static IEnumerable <string> GetColumn(VirtualSpreadsheet spreadsheet, int columnIndex) { return(Enumerable .Range(1, spreadsheet.RowsCount) .Select(rowIndex => spreadsheet.GetValue(columnIndex, rowIndex))); }
public static string PrintSpreadsheet(IViewSpreadsheet spreadsheet, bool original = false) { var view = new VirtualSpreadsheet(spreadsheet, original); return(PrintContent(view)); }