/// <summary> /// Export the files to CSV format from the file menu. /// </summary> /// <param name="sender">A reference to the control/object that raised the event.</param> /// <param name="e">State information and event data associated with a routed event.</param> private void Export_Click(object sender, RoutedEventArgs e) { if (ViewModel.Conflicts.Count != 0) { string message = "Exporting to Excel while there are conflicts may result in incorrect output. Do you wish to continue with the export?"; string caption = "Export to Excel"; MessageBoxImage icon = MessageBoxImage.Warning; MessageBoxButton button = MessageBoxButton.YesNo; MessageBoxResult result = System.Windows.MessageBox.Show(message, caption, button, icon); if (result == MessageBoxResult.No) { return; } } Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog(); saveFileDialog.Filter = "Excel Worksheets|*.xls"; if (saveFileDialog.ShowDialog() == true) { var fileName = saveFileDialog.FileName; var templateFile = System.IO.Path.Combine(Environment.CurrentDirectory, "ClassroomGridTemplate.xls"); using (var fileStream = File.OpenRead(templateFile)) { IWorkbook workbook = new HSSFWorkbook(fileStream); workbook.RemoveSheetAt(workbook.GetSheetIndex("Sheet1")); workbook.MissingCellPolicy = MissingCellPolicy.CREATE_NULL_AS_BLANK; ExcelSchedulePrinter printer = new ExcelSchedulePrinter(fileName, workbook); ICourseRepository courseRepository = CourseRepository.GetInstance(); new ScheduleVisualization(courseRepository, null, printer, "", null).PrintSchedule(); } } }
private void Menu_Export(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Excel Worksheets|*.xls"; if (saveFileDialog.ShowDialog() == true) { var fileName = saveFileDialog.FileName; var templateFile = Path.Combine(Environment.CurrentDirectory, "ClassroomGridTemplate.xls"); using (var fileStream = File.OpenRead(templateFile)) { IWorkbook workbook = new HSSFWorkbook(fileStream); workbook.RemoveSheetAt(workbook.GetSheetIndex("Sheet1")); workbook.MissingCellPolicy = MissingCellPolicy.CREATE_NULL_AS_BLANK; ExcelSchedulePrinter printer = new ExcelSchedulePrinter(fileName, workbook); ICourseRepository courseRepository = InMemoryCourseRepository.getInstance(); //IRoomRepository roomRepository = InMemoryRoomRepository.getInstance(); new ScheduleVisualization(courseRepository, null, printer).PrintSchedule(); } } }