public bool SaveToExcel(string FileName) { try { using (ExcelFileWriter file = ExcelFileWriter.OpenExcelApplication()) { if (file == null) { throw new NullReferenceException("Failed to open the Excel application."); } using (WorkbookWriter book = file.CreateNewWorkbook()) { if (book == null) { throw new NullReferenceException("Failed to create a new Excel workbook."); } WorksheetWriter sheet = book.GetActiveWorksheet(); if (sheet == null) { throw new NullReferenceException("Failed to find the active worksheet."); } sheet.Name = "Data Acquisition"; int col = WorksheetWriter.MinColumn; int row; foreach (string cat in orderedCategories) { row = WorksheetWriter.MinRow; sheet[row, col] = cat; sheet.Bold(row, col); foreach (object data in allData[cat]) { sheet[++row, col] = data.ToString(); } col++; } sheet.AutoFitAllColumns(); return(book.Save(FileName + WorkbookWriter.DEFAULT_FILE_EXTENSION)); } } } catch (Exception) { Console.WriteLine("Unable to save data."); return(false); } }