I have the following code which pulls Excel files from a list of Workbooks:
- Code: Select all
workbook = new Workbook();
workbook.LoadFromStream(workbooks[0]); // load first document
// load all other documents into the original
for (int i = 1; i < workbooks.Count; i++)
{
Workbook b = new Workbook();
b.LoadFromStream(workbooks[i]);
workbook.Worksheets.AddCopy(b.Worksheets);
}
This gives me the following exception:
System.ArgumentOutOfRangeException: Index and length must refer to a location within the string.
Parameter name: length
at System.String.Substring(Int32 startIndex, Int32 length)
at spr⋥.ᜁ(String A_0, String A_1)
at Spire.Xls.Core.Spreadsheet.Collections.XlsFontsCollection.ᜀ(XlsFont A_0)
at Spire.Xls.Core.Spreadsheet.Collections.XlsFontsCollection.AddRange(XlsFontsCollection fonts)
at sprᡌ.ᜀ(IList`1 A_0, Dictionary`2& A_1)
at Spire.Xls.Core.Spreadsheet.Collections.XlsStylesCollection.ᜀ(IWorkbook A_0, StyleMergeType A_1, Dictionary`2& A_2, Dictionary`2& A_3)
at Spire.Xls.Core.Spreadsheet.Collections.XlsWorksheetsCollection.AddCopy(IWorksheets worksheets, WorksheetCopyType flags)
at Spire.Xls.Core.Spreadsheet.Collections.XlsWorksheetsCollection.AddCopy(IWorksheets worksheets)
at Spire.Xls.Collections.WorksheetsCollection.AddCopy(WorksheetsCollection sheets)
This was working at some point, but now I am at a loss as to what the problem is.
I tried the following but it did not help.
- Code: Select all
workbook.Worksheets.AddCopy(b.Worksheets, false);
Please advise.