C# Spire.Xls set list of workbooks

Asked

Viewed 31 times

-1

How can I create a list of workbooks

Example of workbooks created to add the list:

        private static void Merge()
        { 
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"merge1.xlsx");

            Workbook workbook2 = new Workbook();
            workbook2.LoadFromFile(@"merge2.xlsx");
        }

1 answer

1


You can believe a list as follows:

Using the namespace System.Collections.Generic has the List<>, in it is possible to define a list of some kind, in your case Workbook. Finally, to add items in the list use the Add()

Obs: I modified the method to return the list.

private static List<Workbook> Merge()
{
    List<Workbook> workbooks = new List<Workbook>();

    Workbook workbook = new Workbook();
    workbook.LoadFromFile(@"merge1.xlsx");
    workbooks.Add(workbook);

    Workbook workbook2 = new Workbook();
    workbook2.LoadFromFile(@"merge2.xlsx");
    workbooks.Add(workbook2);

    return workbooks;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.