Hi,
i wonder if there is a way to work with dynamic objects as a datasource. I need this in oder to add dynamically properties to the objects. now the data is not loaded, i presume that’s is caused by the reflection of the object instead of the object is represents.
private int TransformComplexDataType(object data, int parentId, ComplexType item)
{
IDictionary<string, object> dynamicData = ProcessPrimitiveProperties(item.PrimativeTypes, data);
var originalParentId = parentId;
if (item.IsParentElement)
{
parentId = GetUniqueNumber();
dynamicData.Add($"Id", parentId);
}
if(item.IsChildElement)
{
dynamicData.Add($"ParentId" , originalParentId);
}
AddToDataSourceResults(dynamicData, "DynamicData");
return parentId;
}
private void AddToDataSourceResults(object result, string datasourceName)
{
if (_dataSources.Keys.Contains(datasourceName) == false) { _dataSources.Add(datasourceName, new List<object>()); }
_dataSources[datasourceName].Add(result);
}
is there a way to work with an expandoobject or dynamic to load data into excel?
regards,
@Pietswieb
Thanks for using Aspose APIs.
It seems, you are using Aspose.Cells that deals with Microsoft Excel document. Could you please share with us runnable sample code (preferably console application project) which we could test at our end and replicate this issue.
It seems to be a New Feature and we will add feature request for it in our database after testing your code.
You may also like to see the following article (and its subsections) that explains the different ways of importing data into Excel.
- Import Data into Worksheet
1.1 Importing from Array
1.2 Importing from ArrayList
1.3 Importing from Custom Objects
1.4 Importing from DataTable
1.5 Importing from DataColumn (.NET)
1.6 Importing from DataView (.NET)
1.7 Importing from DataGrid (.NET)
1.8 Importing from GridView
1.9 Importing HTML formatted data
I’ve created an example…
see
AsposeDynamicSample.zip (268.7 KB)
i’ve created a workaround to do another conversion into a datatable, but i think i would be nice to be able to work with dynamics
Regards,
1 Like
@Pietswieb
Thanks for your sample application project and using Aspose APIs.
We were able to observe the issue in your output Excel files and logged this issue in our database as New Feature request so that we could investigate this issue further and support it in our future releases. Once, we will have some fix or other news for you, we will update you in this topic asap.
-
CELLSNET-46186 - Using List or List as DataSource for Importing Data into Worksheet
@Pietswieb,
This is to inform you that we have fixed your issue (logged earlier as “CELLSNET-46186”) now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.
Once the fix is available for public use, we will share the Download link here.
1 Like
@Pietswieb
Thanks for using Aspose APIs.
Please download and try the following fix and let us know your feedback.
HI
i might be doing something wrong here because i keep getting the error of missing system references.
like system.drawing.
@Pietswieb,
You may please give a try to the attached sample project which uses Aspose.Cells for .NET 4.0 - 18.6.1. This project compiles fine and no exception is raised. Your feedback will be appreciated in this regard.
AsposeDynamicSample.zip (3.9 MB)
Thanks for the response.
i’ve tested it and it works fine. But it will fail if the objects aren’t the same… as i add a property ID2 only to the first item… then it will fail on the others indicating that there is nog property ID2 idoesn’t exist.
The specified key ‘ID2’ does not exist in the ExpandoObject.
perhaps there should be an check on the key… .
but thanks so far…
@Pietswieb
Thanks for your feedback and using Aspose APIs.
We checked your code and found ID2 does not exist. If you are talking about some new case, then please provide us sample code (along with sample Excel files) that deals with your new case. We will execute it at our end and log it so that it can also be fixed in later versions. Thanks for your cooperation in this regard and have a good day.
Hi,
I was testing the solution and it worked fine… But in a test case i just added a property on one item in the collection. the first one… see code below. i used the project in this thread…
it will fail now because it expect this property to be on the next items as well. I guess aspose does a check on the first item and assumse the collection is all the same… so the discovery of items is not done for each item which would cause a performance penalty…
But it will fail if the collection of items differs…
var modifiedData = new Converter().GetModifiedData(data);
// modified data is still an object but is is a dynamic one now.
modifiedData.First().Id = 200;
modifiedData.First().Id2 = 100; // only present due to this line on the first item in the list.....
// make workbook and fill it with the data
// expecting it to fill the smartmarkers
@Pietswieb
Thanks for your posting and using Aspose APIs.
I have added your code change in the existing project shared in the previous post as shown in the following screenshot. But no exception is occurring nor I see any errors in the output Excel files.
Please submit your project (that replicates the issue) so that we could investigate this issue further.
Screenshot:
@Pietswieb
Yes, you are right. We only check the first item and we think all items in the collection should be same.
The issues you have found earlier (filed as CELLSNET-46186) have been fixed in Aspose.Cells for .NET v18.7. Please also check the document/article for your reference: Install Aspose Cells through NuGet|Documentation