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
textstringThe text containing tabular data
Returns
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
textstringThe text containing rows of numbers
isRequiringAllNumbersboolIf true, all values must be valid numbers
calculateFunctionFunc<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
textstringThe text containing two rows of data
calculateFunctionFunc<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
countintThe number of column identifiers to generate
Returns
DataTableToString(DataTable)
Converts a DataTable to Google Sheets formatted text (tab-delimited)
public static string DataTableToString(DataTable dataTable)
Parameters
dataTableDataTableThe 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
cellContentstringThe 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
textstringThe row text from clipboard
Returns
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
cellsIEnumerable<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
cellsobject[]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
stringBuilderStringBuilderStringBuilder to append the result to
cellsobject[]Array of objects to join
Rows(string)
Splits the input text into rows by newline character
public static List<string> Rows(string text)
Parameters
textstringThe text to split into rows
Returns
SplitFromGoogleSheets(string)
Splits text by tab or space characters (for splitting by \r\n use SplitFromGoogleSheets2)
public static List<string> SplitFromGoogleSheets(string text)
Parameters
textstringThe text to split
Returns
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
textstringThe text to split
Returns
SplitFromGoogleSheetsRow(string)
Splits a Google Sheets row into cells and removes empty elements from the end
public static List<string> SplitFromGoogleSheetsRow(string text)
Parameters
textstringThe row text to split
Returns
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
captionsList<string>Column names (not letter sorted like A,B,C but actual names like Name, Rating, etc.)
dataColumnsList<List<string>>Data columns
isThrowingExceptionIfDifferentCountOfCaptionsAndExistsboolIf 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
textstringThe text containing tabular data with rows and columns
isKeepingInSizeOfSmallestboolIf true, keeps only columns up to the size of the smallest row
Returns
- string
The transposed data as text