C# Example
Each of the C# code listings illustrated below represents the Program.cs file in a standard .NET Framework console application. Before attempting to run the program code, make sure that you have added the required assembly references to the Visual Studio project, as described in Access API.
Export XBRL from Excel
The code listing below shows how to create a new Excel workbook using a specific XBRL entry point, populate a few properties and data cells, and save data to an XBRL file on the disk. The code will help you save both the Excel workbook and the XBRL file to the C:\XBRL_Examples directory.
using System;
using Excel = Microsoft.Office.Interop.Excel;
namespace SolvencyAddInClient
{
class Program
{
static void Main(string[] args)
{
var app = new Excel.Application();
try
{
// Suppress Excel alerts and create a new workbook
Console.WriteLine("Creating a new workbook...");
app.DisplayAlerts = false;
var wb = (Excel._Workbook)(app.Workbooks.Add());
// Get the Automation API object
Console.WriteLine("Getting the COM automation object...");
dynamic addIn = app.COMAddIns.Item("Altova.SolvencyIIAddIn");
dynamic automationObject = addIn.Object;
// Create a new report using taxonomy entry point
Console.WriteLine("Creating the new report...");
automationObject.InsertNewReport("http://eiopa.europa.eu/eu/xbrl/s2md/fws/solvency/solvency2/2020-07-15/mod/tep.xsd");
// Set the report properties
Console.WriteLine("Setting the report properties...");
var rp = automationObject.GetReportProperties(wb);
rp.ReportingEntityScheme = "http://standards.iso.org/iso/17442";
rp.ReportingEntityIdentifier = "123456";
// Get the table by its code and ensure it is included in this report
var tab = automationObject.GetTableTree(wb);
var tableNode = tab.FindTableByRCCode("S.01.01.10.01");
tableNode.IncludeInFiling = true;
// Populate cells
Console.WriteLine("Populating cells...");
tableNode.Forms.Item(0).DataRange.Item(1).Value = "1 - Reported";
tableNode.Forms.Item(0).DataRange.Item(2).Value = "2 - Not reported as no life and health SLT business";
tableNode.Forms.Item(0).DataRange.Item(3).Value = "1 - Reported";
tableNode.Forms.Item(0).DataRange.Item(4).Value = "1 - Reported";
// Export data to XBRL
Console.WriteLine("Exporting the XBRL instance...");
automationObject.ExportXBRL(wb, @"C:\XBRL_Examples\Example.xbrl");
// Save and close the .xlsx workbook
Console.WriteLine("Saving the .xlsx file...");
wb.SaveAs(@"C:\XBRL_Examples\Example.xlsx");
wb.Close();
Console.WriteLine("Task completed.");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
app.DisplayAlerts = true;
app.Quit();
}
}
}
}
Import XBRL to Excel
The code listing below shows how to convert an XBRL file to an Excel file. To run this example successfully, an XBRL instance file must exist at C:\XBRL_Examples\Example.xbrl. Otherwise, change the path accordingly. You can create an XBRL file by running the previous code listing or manually from Excel by using the Export command. For more information, see Export Data to XBRL.
using System;
using Excel = Microsoft.Office.Interop.Excel;
namespace SolvencyAddInClient
{
class Program
{
static void Main(string[] args)
{
var app = new Excel.Application();
try
{
// Suppress Excel alerts and create a new workbook
Console.WriteLine("Creating a new workbook...");
app.DisplayAlerts = false;
var wb = (Excel._Workbook)(app.Workbooks.Add());
// Get the Automation API object
Console.WriteLine("Getting the COM automation object...");
dynamic addIn = app.COMAddIns.Item("Altova.SolvencyIIAddIn");
dynamic automationObject = addIn.Object;
// Import EBA report eba_example.xbrl
Console.WriteLine("Importing XBRL...");
automationObject.ImportXBRL(@"C:\XBRL_Examples\Example.xbrl");
// Save as xlsx
Console.WriteLine("Saving the .xlsx file...");
wb.SaveAs(@"C:\XBRL_Examples\Example.xlsx");
wb.Close();
Console.WriteLine("Task complete.");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
app.DisplayAlerts = true;
app.Quit();
}
}
}
}