using System;
using System.Linq;
using Aspose.Cells;
using Aspose.Cells.Tables;
class Program
{
    static void Main(string[] args) // Table creation in C#
    {
        new License().SetLicense("License.lic");

        // Create a workbook.
        Workbook wb = new Workbook();

        // Optionally call this function if the workbook has no data
        CreateSampleData(ref wb);
        
        // Obtain the first sheet
        Worksheet sheet = wb.Worksheets[0];

        // Add a new list object with 20 rows and 5 columns
        ListObject listObject = sheet.ListObjects[sheet.ListObjects.Add("A1", "E20", true)];

        // Set table style
        listObject.TableStyleType = TableStyleType.TableStyleMedium10;

        // Show the flag to display the Total for all numbers
        listObject.ShowTotals = true;

        // Set the second column calculation type
        listObject.ListColumns[1].TotalsCalculation = TotalsCalculation.Count;

        // Saving the Excel file
        wb.Save("output.xlsx");

        Console.WriteLine("Table created successfully");
    }
    static void CreateSampleData(ref Workbook wb)
    {
        // Fill workbook with some dummy data
        string[] titles = new string[] {"Employee", "Quarter", "Product", "Country","Sale"};
        string[] employees = new string[] {"David", "James","Miya" };
        string[] products = new string[] { "Chai", "Chang", "Geitost", "Maxilaku" };
        string[] countries = new string[] { "Brazil", "China", "France", "Germany", "India", "Italy" };
        foreach (var (item, idx) in titles.Select((value, index) => (value, index)))
            wb.Worksheets[0].Cells[0, idx].Value = item;
        Random random = new Random();
        for(int i = 1; i < 20; i++)
        {
            wb.Worksheets[0].Cells[i, 0].Value = employees[random.Next() % employees.Count()];
            wb.Worksheets[0].Cells[i, 1].Value = (random.Next() % 4) + 1;
            wb.Worksheets[0].Cells[i, 2].Value = products[random.Next() % products.Count()];
            wb.Worksheets[0].Cells[i, 3].Value = countries[random.Next() % countries.Count()];
            wb.Worksheets[0].Cells[i, 4].Value = random.Next() % 2000;
        }

    }
}