Class WorksheetDataExtensions
Extension methods for data import and export operations on worksheets.
public static class WorksheetDataExtensions
- Inheritance
-
WorksheetDataExtensions
- Inherited Members
Methods
ExportToCsv(Worksheet, string, string, CsvOptions)
Exports worksheet data to a CSV file.
public static int ExportToCsv(this Worksheet worksheet, string filePath, string range = null, CsvOptions options = null)
Parameters
worksheet
WorksheetThe worksheet to export data from.
filePath
stringPath where the CSV file will be saved.
range
stringRange to export (e.g., "A1:E10"). If null, exports all used range.
options
CsvOptionsCSV export options. If null, default options will be used.
Returns
- int
The number of rows exported.
ExportToCsvString(Worksheet, string, CsvOptions)
Exports worksheet data to a CSV string.
public static string ExportToCsvString(this Worksheet worksheet, string range = null, CsvOptions options = null)
Parameters
worksheet
WorksheetThe worksheet to export data from.
range
stringRange to export (e.g., "A1:E10"). If null, exports all used range.
options
CsvOptionsCSV export options. If null, default options will be used.
Returns
- string
The CSV string containing the exported data.
ExportToJson(Worksheet, string, string, JsonOptions)
Exports worksheet data to a JSON file.
public static int ExportToJson(this Worksheet worksheet, string filePath, string range = null, JsonOptions options = null)
Parameters
worksheet
WorksheetThe worksheet to export data from.
filePath
stringPath where the JSON file will be saved.
range
stringRange to export (e.g., "A1:E10"). If null, exports all used range.
options
JsonOptionsJSON export options. If null, default options will be used.
Returns
- int
The number of records exported.
ExportToJsonString(Worksheet, string, JsonOptions)
Exports worksheet data to a JSON string.
public static string ExportToJsonString(this Worksheet worksheet, string range = null, JsonOptions options = null)
Parameters
worksheet
WorksheetThe worksheet to export data from.
range
stringRange to export (e.g., "A1:E10"). If null, exports all used range.
options
JsonOptionsJSON export options. If null, default options will be used.
Returns
- string
The JSON string containing the exported data.
ImportFromCsv(Worksheet, string, string, CsvOptions)
Imports data from a CSV file into the worksheet starting at the specified cell.
public static int ImportFromCsv(this Worksheet worksheet, string filePath, string startCellReference = "A1", CsvOptions options = null)
Parameters
worksheet
WorksheetThe worksheet to import data into.
filePath
stringPath to the CSV file.
startCellReference
stringStarting cell reference (e.g., "A1").
options
CsvOptionsCSV import options. If null, default options will be used.
Returns
- int
The number of rows imported.
Exceptions
- FileNotFoundException
Thrown when the CSV file is not found.
- ArgumentException
Thrown when parameters are invalid.
ImportFromJson(Worksheet, string, string, JsonOptions)
Imports data from a JSON file into the worksheet starting at the specified cell. Supports both JSON arrays and single JSON objects.
public static int ImportFromJson(this Worksheet worksheet, string filePath, string startCellReference = "A1", JsonOptions options = null)
Parameters
worksheet
WorksheetThe worksheet to import data into.
filePath
stringPath to the JSON file.
startCellReference
stringStarting cell reference (e.g., "A1").
options
JsonOptionsJSON import options. If null, default options will be used.
Returns
- int
The number of rows imported.
Exceptions
- FileNotFoundException
Thrown when the JSON file is not found.
- ArgumentException
Thrown when parameters are invalid.
- JsonException
Thrown when JSON parsing fails.
ImportFromJsonString(Worksheet, string, string, JsonOptions)
Imports data from a JSON string into the worksheet starting at the specified cell.
public static int ImportFromJsonString(this Worksheet worksheet, string jsonString, string startCellReference = "A1", JsonOptions options = null)
Parameters
worksheet
WorksheetThe worksheet to import data into.
jsonString
stringThe JSON string containing the data.
startCellReference
stringStarting cell reference (e.g., "A1").
options
JsonOptionsJSON import options. If null, default options will be used.
Returns
- int
The number of rows imported.