Table of Contents

Class SheetsHelper

Namespace
SunamoGoogleSheets.Clipboard
Assembly
SunamoGoogleSheets.dll

Helper class for parsing and formatting data from Google Sheets clipboard format

public class SheetsHelper
Inheritance
SheetsHelper
Inherited Members
Extension Methods

Methods

AllLines(string)

Parses all lines from text into a 2D list of cells

public static List<List<string>> AllLines(string text)

Parameters

text string

The text containing tabular data

Returns

List<List<string>>

2D list where each inner list represents cells in a row

CalculateMedianAverage(string, bool, Func<List<double>, string>)

Calculates median or average for each row in the input text

public static string CalculateMedianAverage(string text, bool isRequiringAllNumbers, Func<List<double>, string> calculateFunction)

Parameters

text string

The text containing rows of numbers

isRequiringAllNumbers bool

If true, all values must be valid numbers

calculateFunction Func<List<double>, string>

Function to calculate median or average from a list of numbers

Returns

string

Text with calculated values for each row

CalculateMedianFromTwoRows(string, Func<List<double>, string>)

Calculates median or average for data organized in two rows

public static string CalculateMedianFromTwoRows(string text, Func<List<double>, string> calculateFunction)

Parameters

text string

The text containing two rows of data

calculateFunction Func<List<double>, string>

Function to calculate median or average from a list of numbers

Returns

string

Text with calculated values

ColumnsIds(int)

Generates Excel/Google Sheets style column identifiers (A, B, C, ..., Z, AA, AB, AC, ...)

public static List<string> ColumnsIds(int count)

Parameters

count int

The number of column identifiers to generate

Returns

List<string>

List of column identifiers

DataTableToString(DataTable)

Converts a DataTable to Google Sheets formatted text (tab-delimited)

public static string DataTableToString(DataTable dataTable)

Parameters

dataTable DataTable

The DataTable to convert

Returns

string

Tab-delimited text representation of the DataTable

FirstLetterFromSheet(string)

Gets the first letter from a Google Sheets cell if it is followed by a space

public static char? FirstLetterFromSheet(string cellContent)

Parameters

cellContent string

The cell content to examine

Returns

char?

The first character if followed by a space, otherwise null

GetRowCells(string)

Splits a row from Google Sheets into individual cell values

public static List<string> GetRowCells(string text)

Parameters

text string

The row text from clipboard

Returns

List<string>

List of cell values

JoinForGoogleSheetRow(IEnumerable<string>)

Joins string enumerable with tab delimiter for Google Sheets row format (overload for List<string> and other IEnumerable types) EN: CRITICAL - Sanitizes cell values by removing newlines, tabs, and carriage returns that would break TSV format CZ: KRITICKÉ - Sanitizuje hodnoty buněk odstraněním newline, tab a carriage return znaků které by rozbily TSV formát

public static string JoinForGoogleSheetRow(IEnumerable<string> cells)

Parameters

cells IEnumerable<string>

String enumerable to join

Returns

string

Tab-delimited string

JoinForGoogleSheetRow(object[])

Joins array elements with tab delimiter for Google Sheets row format EN: CRITICAL - Sanitizes cell values by removing newlines, tabs, and carriage returns that would break TSV format CZ: KRITICKÉ - Sanitizuje hodnoty buněk odstraněním newline, tab a carriage return znaků které by rozbily TSV formát

public static string JoinForGoogleSheetRow(object[] cells)

Parameters

cells object[]

Array of objects to join

Returns

string

Tab-delimited string

JoinForGoogleSheetRow(StringBuilder, object[])

Joins array elements with tab delimiter and appends to StringBuilder (previously was IList but string.Join doesn't support that overload)

public static void JoinForGoogleSheetRow(StringBuilder stringBuilder, object[] cells)

Parameters

stringBuilder StringBuilder

StringBuilder to append the result to

cells object[]

Array of objects to join

Rows(string)

Splits the input text into rows by newline character

public static List<string> Rows(string text)

Parameters

text string

The text to split into rows

Returns

List<string>

List of row strings

SplitFromGoogleSheets(string)

Splits text by tab or space characters (for splitting by \r\n use SplitFromGoogleSheets2)

public static List<string> SplitFromGoogleSheets(string text)

Parameters

text string

The text to split

Returns

List<string>

List of cell values

SplitFromGoogleSheets2(string)

Splits text by line breaks (alternative method that splits by \r\n instead of tabs)

public static List<string> SplitFromGoogleSheets2(string text)

Parameters

text string

The text to split

Returns

List<string>

List of lines

SplitFromGoogleSheetsRow(string)

Splits a Google Sheets row into cells and removes empty elements from the end

public static List<string> SplitFromGoogleSheetsRow(string text)

Parameters

text string

The row text to split

Returns

List<string>

List of cell values with trailing empty elements removed

SwitchForGoogleSheets(List<string>, List<List<string>>, bool)

Switches rows and columns for Google Sheets format, using first column as captions

public static string SwitchForGoogleSheets(List<string> captions, List<List<string>> dataColumns, bool isThrowingExceptionIfDifferentCountOfCaptionsAndExists = false)

Parameters

captions List<string>

Column names (not letter sorted like A,B,C but actual names like Name, Rating, etc.)

dataColumns List<List<string>>

Data columns

isThrowingExceptionIfDifferentCountOfCaptionsAndExists bool

If true, throws exception when caption count differs from data count

Returns

string

Transposed data formatted for Google Sheets

SwitchRowsAndColumn(string, bool)

Switches rows and columns in tabular text data (transposes the data)

public static string SwitchRowsAndColumn(string text, bool isKeepingInSizeOfSmallest = true)

Parameters

text string

The text containing tabular data with rows and columns

isKeepingInSizeOfSmallest bool

If true, keeps only columns up to the size of the smallest row

Returns

string

The transposed data as text