/// <summary> /// Otwarcie okna dialogowego do wybrania pliku XLS /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OpenFile_Click(object sender, RoutedEventArgs e) { //otwarcie okna dialogowego Service.FileDialog dialog = new Service.FileDialog(); string FileName = dialog.OpenDialog(); //otwarcie pliku XLS FileStream fileStream = new FileStream(FileName, FileMode.Open, FileAccess.Read); ExcelParser xlsManager = new ExcelParser(fileStream); //parsowanie pliku xls List <ExcelContent> fileContent = new List <ExcelContent>(); fileContent = xlsManager.ParseExcel(); //dodanie wyniku parsowania do kolekcji ExcelFiles.Add(new ExcelFile() { FileName = FileName, Content = fileContent }); excelContent.ItemsSource = rows; FileList.Items.Refresh(); }
public IHttpActionResult SaveFile(int id) { Survey survey = surveyService.GetWithResult(id); if (survey == null) { return(NotFound()); } survey.Questions.ToList().ForEach(q => { q.QuestionAnswers = q.QuestionAnswers.OrderBy(qa => qa.OrdinalNumber).ToList(); }); var users = surveyService.UsersWhoFilledSurvey(survey.Users.Select(u => u.UserId).ToList()); SurveyResultViewModel surveyVM = AutoMapper.Mapper.Map <Survey, SurveyResultViewModel>(survey); this.SetSurveyResultVMValues(surveyVM, survey, users, 0, true); using (var xlPackage = new ExcelPackage()) { var ws = xlPackage.Workbook.Worksheets.Add("Anketa: " + survey.Name); CreateExcelFile createEF = new CreateExcelFile(surveyService); if (!survey.Anonymous) { createEF.CreateSurveyWorksheet(ws, surveyVM); } createEF.CreateQuestionsOnSurveyWorksheet(ws, surveyVM); surveyVM.Questions.ToList().ForEach(q => { createEF.CreateQuestionWorksheet(xlPackage, q, surveyVM, survey); }); users.ForEach(u => { var answers = surveyService.GetAnswersForUser(u.Id).ToList(); createEF.CreateUserWorksheet(xlPackage, u, survey, answers, users.IndexOf(u)); }); ExcelFiles obj = new ExcelFiles() { Bytes = xlPackage.GetAsByteArray(), SurveyId = survey.Id, CreationDate = DateTime.Now, Name = survey.Name + DateTime.Now.ToString() + ".xlsx" }; surveyService.AddExcel(obj); unitOfWork.Commit(); } return(Ok()); }
public void AddFile(string[] files) { if (ExcelFiles == null) { ExcelFiles = new List <string>(); } ExcelFiles.Clear(); for (int i = 0; i < files.Length; i++) { if (!ExcelFiles.Contains(files[i])) { ExcelFiles.Add(files[i]); } ExcelCache.AddExcaleCache(files[i]); } }
public void AddExcel(ExcelFiles obj) { this.excelFilesRepository.Add(obj); }