ConfigSupport 1.0.6
See the version list below for details.
dotnet add package ConfigSupport --version 1.0.6
NuGet\Install-Package ConfigSupport -Version 1.0.6
<PackageReference Include="ConfigSupport" Version="1.0.6" />
paket add ConfigSupport --version 1.0.6
#r "nuget: ConfigSupport, 1.0.6"
// Install ConfigSupport as a Cake Addin #addin nuget:?package=ConfigSupport&version=1.0.6 // Install ConfigSupport as a Cake Tool #tool nuget:?package=ConfigSupport&version=1.0.6
Excel Data Importer
The Excel Data Importer is a simple library for importing data from Excel files (.xlsx) into a .NET application. It provides a class ProcessExcel, which contains a method ImportExcelData for importing Excel data and ExcelToJSONConvertMethod for converting Excel data into formatted JSON string.
Installation
To use the Excel Data Importer in your .NET project, follow these steps:
Ensure you have all this library installed in your project. You can install it via NuGet using the following command:
Install-Package EPPlus
Install-Package Newtonsoft.Json
Install-Package ConfigSupport
Usage
using ConfigSupport;
OpcUaExcelJsonConverter Class:
The OpcUaExcelJsonConverter
class provides a two methods
ConvertExcelToJson
-- Convert Excel to JSON structure stringConvertJsonToExcel
-- Convert JSON to Excel / Json data with respect to the JSON
ConvertExcelToJson Method
The ConvertExcelToJson
method import Excel data and converting it to JSON. Here's how you can use it:
Parameters:
filePath
: Specify the path of your Excel file location with name.subProcess
: An array of string with all sub-Process.dataType
: An array of string with all Data Types.descriptionPattern
: Regex patter to check the description pattern.
Request:
CSharp:
class Program
{
static void Main(string[] args)
{
OpcUaExcelJsonConverter yourClassInstance = new OpcUaExcelJsonConverter();
string filePath = "example.xlsx"; // Specify the Excel file path
string[] subProcess = new string[] { "SubProcess1", "SubProcess2", "SubProcess3" };
string[] dataType = new string[] { "DataType1", "DataType2", "DataType3" };
string descriptionPattern = "YourRegexPattern";
string response = yourClassInstance.ConvertExcelToJson(string filePath, string[] subProcess, string[] dataType, string descriptionPattern);
// Use the response as needed in your application
}
}
Response:
The return as a JSON
formatted string.
Example Response:
Type1: With Xml string
{
"name": "string",
"version": "string",
"comment": "string",
"instanceNamespaceUri": "string",
"opcGatewayOptions": {
"additionalProp1": "string",
"additionalProp2": "string",
"additionalProp3": "string"
},
"opcNodeConfig": [
{
"description": "string",
"version": "string",
"nameSpaceUri": "string",
"opcNodes": [
{
"name": "string",
"type": "string",
"description": "string",
"template": "string",
"childTypes": [
"string"
]
}
],
"xmlConfig": "string"
}
]
}
Type:2 Without Xml string
{
"name": "string",
"version": "string",
"comment": "string",
"instanceNamespaceUri": "string",
"opcGatewayOptions": {
"additionalProp1": "string",
"additionalProp2": "string",
"additionalProp3": "string"
},
"opcNodeConfig": [
{
"description": "string",
"version": "string",
"nameSpaceUri": "string",
"opcNodes": [
{
"name": "string",
"type": "string",
"description": "string",
"template": "string",
"childTypes": [
"string"
]
}
]
}
]
}
ConvertJsonToExcel Method:
The ConvertJsonToExcel
method import JSON data and converting it to Excel / JSON files with respect to the JSON request. Here's how you can use it:
Parameters:
opcNode
: OPCNodeConfig Type data.filePath
: folder path to save the extracted files.columnData
: It refers to Excel column header information.attributes
: It refers to the list of attributes used in the files.
Example:
class Program
{
public class OPCNodeConfig
{
public string description { get; set; }
public string version { get; set; }
public string nameSpaceUri { get; set; }
public string xmlConfig { get; set; }
public List<OPCNode> opcNodes { get; set; }
}
public class OPCNode
{
public string name { get; set; }
public string type { get; set; }
public string template { get; set; }
public string description { get; set; }
public List<OPCNode> childTypes { get; set; }
public List<string> ObjectLevels { get; set; } = new List<string>();
}
static void Main(string[] args)
{
// Create an instance of your class
OpcUaExcelJsonConverter yourClassInstance = new OpcUaExcelJsonConverter();
// Prepare sample data
OPCNodeConfig opcNode = new OPCNodeConfig();
// Add sample data to opcNode
string filePath = yourFilePath.json;
List<string> columnData = new List<string> { "ColumnData1", "ColumnData2", "ColumnData3" };
string[] attributes = new string[] { "Attributes1", "Attributes2", "Attributes3" };
// Call the ExcelToJSONConvertMethod
yourClassInstance.ConvertJsonToExcel(OPCNodeConfig opcNode, string filePath, List<string> columnData, string[] attributes)
}
}
Return Value:
No return, it will save the file as Excel or Json in the give file path location
Example Response:
Type:1 JSON contains XML type configuration
File saved as
- HeaderJson.json
- xmlFile1.json
- xmlFile2.json ...
Type:2 JSON does not contains XML in the configuration
File saved as
- HeaderJson.json
- excelFile1.xlsx
- excelFile2.xlsx ...
Contributing
Contributions to the Excel Data Importer library are welcome!
License
This project is licensed under the MIT License
Author Information
SIVA SHANMUGA VADIVEL
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- EPPlus (>= 7.1.3)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Updated Catch statement to catch the Excel File type