private ExcelFile Consolidate(Stream[] fileDatas, string[] fileNames, bool OnlyData) { ExcelFile XlsIn = new XlsFile(); ExcelFile XlsOut = new XlsFile(true); XlsOut.NewFile(1); if (fileNames.Length > 1 && cbOnlyData.Checked) { XlsOut.InsertAndCopySheets(1, 2, fileNames.Length - 1); } for (int i = 0; i < fileNames.Length; i++) { if (fileDatas != null) { XlsIn.Open(fileDatas[i]); } else { XlsIn.Open(fileNames[i]); } XlsIn.ConvertFormulasToValues(true); //If there is any formula referring to other sheet, convert it to value. //We could also call an overloaded version of InsertAndCopySheets() that //copies many sheets at the same time, so references are kept. XlsOut.ActiveSheet = i + 1; if (OnlyData) { XlsOut.InsertAndCopyRange(TXlsCellRange.FullRange(), 1, 1, 1, TFlxInsertMode.ShiftRangeDown, TRangeCopyMode.All, XlsIn, 1); } else { XlsOut.InsertAndCopySheets(1, XlsOut.ActiveSheet, 1, XlsIn); } //Change sheet name. string s = Path.GetFileName(fileNames[i]); if (s.Length > 32) { XlsOut.SheetName = s.Substring(0, 29) + "..."; } else { XlsOut.SheetName = s; } } if (!cbOnlyData.Checked) { XlsOut.ActiveSheet = XlsOut.SheetCount; XlsOut.DeleteSheet(1); //Remove the empty sheet that came with the workbook. } XlsOut.ActiveSheet = 1; return(XlsOut); }