excelumbracoumbraco7umbraco-contourvba

Export Umbraco fields to Excel


I have 3 Umbraco Items I would like to export to an excel sheet.

    Alias         Type
jibberishNumber textstring
jibberishName   textstring
jiberishBody    Richtext editor

I would like to place them in an excel sheet like this :

     Number      |       Name      |    Content 
jibberishNumber  |  jibberishName  |  jiberishBody
jibberishNumber  |  jibberishName  |  jiberishBody

My site is structured like this

Root
-Content Folder
--Chapter 1 
---Section 1.1
----Story 1.1.1
----Story 1.1.2
--Chapter 2
---Section 2.1
----Story 2.1.1
----Story 2.1.2
--Chapter 3
---Section 3.1
-Content Folder
--Chapter 4
---Section 4.1
----Story 4.1.1
----Story 4.1.2

I want to only display stories which are a certain a document type in my site. For this particular website, it would display the results:

1.1.1
1.1.2
2.1.1
2.1.2
4.1.1
4.1.2

Solution

  • Use the uQuery GetNodesByType(string or int) method, example:

    IEnumerable<Node> nodes = uQuery.GetNodesByType("Story");
    foreach (var node in nodes)
    {
        var cell1 = node.GetProperty("jibberishNumber").ToString();
        var cell2 = node.GetProperty("jibberishName").ToString();
        var cell3 = node.GetProperty("jiberishBody").ToString();
    }
    

    As for the writing to the Excel sheet, there should be numerous topics on StackOverflow to assist with this. Example: How to write some data to Excel file(.xlsx)