Skip to content

Commit b39da97

Browse files
authored
Merge pull request #26 from fahadadeel/main
Add CSV and JSON Import/Export Functionality
2 parents ad1df93 + 7095080 commit b39da97

File tree

3 files changed

+991
-0
lines changed

3 files changed

+991
-0
lines changed

Excel/CsvOptions.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.Text;
3+
4+
namespace Openize.Cells
5+
{
6+
/// <summary>
7+
/// Configuration options for CSV import and export operations.
8+
/// </summary>
9+
public class CsvOptions
10+
{
11+
/// <summary>
12+
/// Gets or sets whether the first row contains headers.
13+
/// </summary>
14+
public bool HasHeaders { get; set; } = true;
15+
16+
/// <summary>
17+
/// Gets or sets the delimiter character used to separate values.
18+
/// </summary>
19+
public string Delimiter { get; set; } = ",";
20+
21+
/// <summary>
22+
/// Gets or sets the text qualifier character (e.g., quote character).
23+
/// </summary>
24+
public string TextQualifier { get; set; } = "\"";
25+
26+
/// <summary>
27+
/// Gets or sets the date format for parsing date values.
28+
/// </summary>
29+
public string DateFormat { get; set; } = "yyyy-MM-dd";
30+
31+
/// <summary>
32+
/// Gets or sets the number format culture (e.g., "en-US", "de-DE").
33+
/// </summary>
34+
public string Culture { get; set; } = "en-US";
35+
36+
/// <summary>
37+
/// Gets or sets whether to skip empty lines during import.
38+
/// </summary>
39+
public bool SkipEmptyLines { get; set; } = true;
40+
41+
/// <summary>
42+
/// Gets or sets whether to trim whitespace from values.
43+
/// </summary>
44+
public bool TrimWhitespace { get; set; } = true;
45+
46+
/// <summary>
47+
/// Gets or sets the encoding for reading/writing the CSV file.
48+
/// </summary>
49+
public Encoding Encoding { get; set; } = Encoding.UTF8;
50+
51+
/// <summary>
52+
/// Gets or sets the maximum number of rows to import (0 = no limit).
53+
/// </summary>
54+
public int MaxRows { get; set; } = 0;
55+
56+
/// <summary>
57+
/// Gets or sets whether to auto-detect data types.
58+
/// </summary>
59+
public bool AutoDetectDataTypes { get; set; } = true;
60+
}
61+
}

Excel/JsonOptions.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System;
2+
3+
namespace Openize.Cells
4+
{
5+
/// <summary>
6+
/// Configuration options for JSON import and export operations.
7+
/// </summary>
8+
public class JsonOptions
9+
{
10+
/// <summary>
11+
/// Gets or sets whether to include property names as headers in the first row.
12+
/// </summary>
13+
public bool IncludeHeaders { get; set; } = true;
14+
15+
/// <summary>
16+
/// Gets or sets the date format for parsing and formatting date values.
17+
/// </summary>
18+
public string DateFormat { get; set; } = "yyyy-MM-dd";
19+
20+
/// <summary>
21+
/// Gets or sets the date-time format for parsing and formatting datetime values.
22+
/// </summary>
23+
public string DateTimeFormat { get; set; } = "yyyy-MM-dd HH:mm:ss";
24+
25+
/// <summary>
26+
/// Gets or sets whether to auto-detect data types during import.
27+
/// </summary>
28+
public bool AutoDetectDataTypes { get; set; } = true;
29+
30+
/// <summary>
31+
/// Gets or sets the number format culture (e.g., "en-US", "de-DE").
32+
/// </summary>
33+
public string Culture { get; set; } = "en-US";
34+
35+
/// <summary>
36+
/// Gets or sets whether to ignore null or empty values during import.
37+
/// </summary>
38+
public bool IgnoreNullValues { get; set; } = false;
39+
40+
/// <summary>
41+
/// Gets or sets the maximum number of records to import (0 = no limit).
42+
/// </summary>
43+
public int MaxRecords { get; set; } = 0;
44+
45+
/// <summary>
46+
/// Gets or sets whether to flatten nested objects into columns with dot notation.
47+
/// Example: {"user": {"name": "John"}} becomes "user.name" column.
48+
/// </summary>
49+
public bool FlattenNestedObjects { get; set; } = false;
50+
51+
/// <summary>
52+
/// Gets or sets the separator for flattened nested object property names.
53+
/// </summary>
54+
public string NestedPropertySeparator { get; set; } = ".";
55+
56+
/// <summary>
57+
/// Gets or sets whether to handle arrays by converting them to comma-separated strings.
58+
/// </summary>
59+
public bool ConvertArraysToStrings { get; set; } = true;
60+
61+
/// <summary>
62+
/// Gets or sets the separator for array values when converting to strings.
63+
/// </summary>
64+
public string ArrayValueSeparator { get; set; } = ", ";
65+
}
66+
}

0 commit comments

Comments
 (0)