/// <summary> /// Exporte les solutions. /// </summary> /// <param name="scenario">Le scénario.</param> /// <param name="cellReference">La référence de la cellule.</param> /// <param name="file">Le fichier.</param> /// <param name="sheet">La feuille.</param> private void ExportSolutions(Scenario scenario, CellReference cellReference, WorksheetPart sheet) { ITimeTicksFormatService timeFormatService = IoC.Resolve <IServiceBus>().Get <ITimeTicksFormatService>(); long timeScale = _data.Project.TimeScale; List <SolutionWrapper> solutions = new List <SolutionWrapper>(); foreach (var solution in scenario.Solutions.OrderBy(s => s.SolutionDescription)) { var w = CreateSolutionWrapper(scenario.Actions, solution); solutions.Add(w); } var originalScenario = scenario.Original; while (originalScenario != null) { // Déterminer les actions qui sont concernées var originalActions = originalScenario.Actions.Where(originalAction => scenario.Actions.Any(currentScenarioAction => ScenarioActionHierarchyHelper.IsAncestor(originalAction, currentScenarioAction))); foreach (var solution in originalScenario.Solutions.OrderBy(s => s.SolutionDescription)) { var wrapper = CreateSolutionWrapper(originalActions, solution); // Ignorer les solutions qui n'apportent pas de gain. C'est un surplus d'infos inutile if (wrapper.Saving != 0) { solutions.Add(wrapper); } } originalScenario = originalScenario.Original; } // Définir l'index int i = 1; foreach (var wrapper in solutions) { wrapper.Index = i++; } var solutionsFormats = new ColumnFormat[] { #region Format pour les solutions // Index new ColumnFormat() { Header = "" }, // Scénario new ColumnFormat() { Header = LocalizationManager.GetString("View_RestitutionSolutions_Columns_Scenario") }, // Solution new ColumnFormat() { Header = LocalizationManager.GetString("View_RestitutionSolutions_Columns_Solution") }, // Tâches liées new ColumnFormat() { Header = LocalizationManager.GetString("View_RestitutionSolutions_Columns_RelatedActions") }, // Gain new ColumnFormat() { Header = LocalizationManager.GetString("View_RestitutionSolutions_Columns_Saving") }, // Investissement new ColumnFormat() { Header = LocalizationManager.GetString("View_RestitutionSolutions_Columns_Investment") }, // I/G new ColumnFormat() { Header = LocalizationManager.GetString("View_RestitutionSolutions_Columns_IG") }, // Difficulté new ColumnFormat() { Header = LocalizationManager.GetString("View_RestitutionSolutions_Columns_Diffculty") }, // Coûts new ColumnFormat() { Header = LocalizationManager.GetString("View_RestitutionSolutions_Columns_Cost") }, // DC/G new ColumnFormat() { Header = LocalizationManager.GetString("View_RestitutionSolutions_Columns_DCG") }, // OK new ColumnFormat() { Header = LocalizationManager.GetString("View_RestitutionSolutions_Columns_OK") }, // Comments new ColumnFormat() { Header = LocalizationManager.GetString("View_RestitutionSolutions_Columns_Comments") }, #endregion }; CellContent[][] data = new CellContent[solutions.Count][]; i = 0; foreach (var solution in solutions) { CellContent[] row = new CellContent[solutionsFormats.Length]; int j = 0; #region Data // Index row[j++] = solution.Index; // Scénario row[j++] = solution.Solution.Scenario.Label; // Solution row[j++] = solution.Solution.SolutionDescription; // Tâches liées row[j++] = solution.RelatedActions; // Gain row[j++] = CellContent.TimeSpan(timeFormatService.RoundTime(solution.Saving, timeScale)); // Investissement if (solution.Solution.Investment.HasValue) { row[j++] = solution.Solution.Investment; } else { row[j++] = null; } // I/G if (solution.IG.HasValue) { row[j++] = solution.IG; } else { row[j++] = null; } // Difficulté if (solution.Solution.Difficulty.HasValue) { row[j++] = solution.Solution.Difficulty; } else { row[j++] = null; } // Coûts if (solution.Solution.Cost.HasValue) { row[j++] = solution.Solution.Cost; } else { row[j++] = null; } // DC/G if (solution.DCG.HasValue) { row[j++] = solution.DCG; } else { row[j++] = null; } // OK row[j++] = solution.Solution.Approved.ToString(); // Comments row[j++] = solution.Solution.Comments; #endregion data[i] = row; i++; } _file.AddTable(sheet, solutionsFormats, data, cellReference); }
/// <summary> /// Exporte la vidéo spécifiée. /// </summary> /// <param name="video">La vidéo.</param> /// <param name="sheet">La feuille.</param> /// <param name="cellReference">La référence de la cellule où commencer l'export.</param> private void ExportVideo(Video video, WorksheetPart sheet, CellReference cellReference) { // Nom SetLabelValue(sheet, cellReference, "View_PrepareVideos_Name", video.Filename); // Fichier SetLabelValue(sheet, cellReference, "View_PrepareVideos_File", video.FilePath); // Durée SetLabelValue(sheet, cellReference, "ViewModel_AnalyzeRestitution_Export_Video_Duration", CellContent.TimeSpan((long)video.Duration)); // Date de prise de vue SetLabelValue(sheet, cellReference, "View_PrepareVideos_ShootingDate", video.ShootingDate); // Description //SetLabelValue(sheet, cellReference, "View_PrepareVideos_Description", video.Description); // POV/VSM _file.SetCellValue(sheet, cellReference, LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Video_POV")); cellReference.MoveRight(); if (video.ResourceView != null) { _file.SetCellValue(sheet, cellReference, LocalizationManager.GetString("VideoNaure_POV_Short")); cellReference.NewLine(); // Opérateur/Equipement + Nom _file.SetCellValue(sheet, cellReference, LocalizationManager.GetString("View_PrepareVideos_DefaultResource")); cellReference.MoveRight(); _file.SetCellValue(sheet, cellReference, video.DefaultResource.Label); cellReference.NewLine(); } else { _file.SetCellValue(sheet, cellReference, LocalizationManager.GetString("VideoNaure_VSM_Short")); cellReference.NewLine(); } cellReference.NewLine(); }
/// <summary> /// Exporte les actions spécifiées. /// </summary> /// <param name="actions">Les actions.</param> /// <param name="cellReference">La référence de la cellule.</param> /// <param name="sheet">La feuille.</param> private void ExportActions(ICollection <KAction> actions, WorksheetPart sheet, ref CellReference cellReference) { var timeFormatService = IoC.Resolve <IServiceBus>().Get <ITimeTicksFormatService>(); var timeScale = _data.Project.TimeScale; #region Format pour les actions // Actions var actionsFormats = new List <ColumnFormat>() { // Thumbnail new ColumnFormat() { Header = string.Empty }, // Label new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_Task") }, // Start new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_Start") }, // Duration new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_Duration") }, // Finish new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_Finish") }, // BuildStart new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_BuildStart") }, // BuildDuration new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_BuildDuration") }, // BuildFinish new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_BuildFinish") }, // WBS new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_WBS") }, // Category new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_Category") }, // Resource new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_Resource") }, // Video new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_Video") }, // Predecessors new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_Predecessors") }, // Original new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_Original") }, }; // Ref1 if (_referentialsUse[ProcessReferentialIdentifier.Ref1].IsEnabled) { actionsFormats.Add(new ColumnFormat() { Header = IoC.Resolve <IReferentialsUseService>().GetLabel(ProcessReferentialIdentifier.Ref1) }); } // Ref2 if (_referentialsUse[ProcessReferentialIdentifier.Ref2].IsEnabled) { actionsFormats.Add(new ColumnFormat() { Header = IoC.Resolve <IReferentialsUseService>().GetLabel(ProcessReferentialIdentifier.Ref2) }); } // Ref3 if (_referentialsUse[ProcessReferentialIdentifier.Ref3].IsEnabled) { actionsFormats.Add(new ColumnFormat() { Header = IoC.Resolve <IReferentialsUseService>().GetLabel(ProcessReferentialIdentifier.Ref3) }); } // Ref4 if (_referentialsUse[ProcessReferentialIdentifier.Ref4].IsEnabled) { actionsFormats.Add(new ColumnFormat() { Header = IoC.Resolve <IReferentialsUseService>().GetLabel(ProcessReferentialIdentifier.Ref4) }); } // Ref5 if (_referentialsUse[ProcessReferentialIdentifier.Ref5].IsEnabled) { actionsFormats.Add(new ColumnFormat() { Header = IoC.Resolve <IReferentialsUseService>().GetLabel(ProcessReferentialIdentifier.Ref5) }); } // Ref6 if (_referentialsUse[ProcessReferentialIdentifier.Ref6].IsEnabled) { actionsFormats.Add(new ColumnFormat() { Header = IoC.Resolve <IReferentialsUseService>().GetLabel(ProcessReferentialIdentifier.Ref6) }); } // Ref7 if (_referentialsUse[ProcessReferentialIdentifier.Ref7].IsEnabled) { actionsFormats.Add(new ColumnFormat() { Header = IoC.Resolve <IReferentialsUseService>().GetLabel(ProcessReferentialIdentifier.Ref7) }); } // IsRandom actionsFormats.Add(new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_IsRandom") }); // Custom Text actionsFormats.Add(new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_CustomValue_Text1") }); actionsFormats.Add(new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_CustomValue_Text2") }); actionsFormats.Add(new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_CustomValue_Text3") }); actionsFormats.Add(new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_CustomValue_Text4") }); // Custom Numeric actionsFormats.Add(new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_CustomValue_Numeric1") }); actionsFormats.Add(new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_CustomValue_Numeric2") }); actionsFormats.Add(new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_CustomValue_Numeric3") }); actionsFormats.Add(new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_CustomValue_Numeric4") }); // DifferenceReason actionsFormats.Add(new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_DifferenceReason") }); // Amélioration I/E/S actionsFormats.Add(new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_Reduced_IES") }); // Solution actionsFormats.Add(new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_Reduced_Solution") }); // Reduction ratio actionsFormats.Add(new ColumnFormat() { Header = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_Reduced_ReductionRatio") }); #endregion CellContent[][] data = new CellContent[actions.Count][]; uint tableRowIndex = cellReference.RowIndex; int i = 0; foreach (var action in actions) { CellContent[] row = new CellContent[actionsFormats.Count]; // Mettre à jour IsGroup action.IsGroup = WBSHelper.HasChildren(action, actions); int j = 0; #region Data pour les actions // Thumbnail j++; // Label row[j++] = action.Label; if (!action.IsGroup) { // Start row[j++] = CellContent.TimeSpan(timeFormatService.RoundTime(action.Start, timeScale)); // Duration row[j++] = CellContent.TimeSpan(timeFormatService.RoundTime(action.Duration, timeScale)); // Finish row[j++] = CellContent.TimeSpan(timeFormatService.RoundTime(action.Finish, timeScale)); } else { j += 3; // Nombre de colonnes précédentes } // BuildStart row[j++] = CellContent.TimeSpan(timeFormatService.RoundTime(action.BuildStart, timeScale)); // BuildDuration row[j++] = CellContent.TimeSpan(timeFormatService.RoundTime(action.BuildDuration, timeScale)); // BuildFinish row[j++] = CellContent.TimeSpan(timeFormatService.RoundTime(action.BuildFinish, timeScale)); // WBS row[j++] = action.WBS; if (!action.IsGroup) { // Category if (action.Category != null) { row[j++] = action.Category.Label; } else { row[j++] = null; } // Resource if (action.Resource != null) { row[j++] = action.Resource.Label; } else { row[j++] = null; } // Video if (action.Video != null) { row[j++] = action.Video.Filename; } else { row[j++] = null; } // Predecessors row[j++] = FormatPredecessorsString(action); // Original if (action.Original != null) { row[j++] = action.Original.Label; } else { row[j++] = null; } // Ref1 if (_referentialsUse[ProcessReferentialIdentifier.Ref1].IsEnabled) { row[j++] = GetMultiReferentialLabels(action.Ref1, ProcessReferentialIdentifier.Ref1); } // Ref2 if (_referentialsUse[ProcessReferentialIdentifier.Ref2].IsEnabled) { row[j++] = GetMultiReferentialLabels(action.Ref2, ProcessReferentialIdentifier.Ref2); } // Ref3 if (_referentialsUse[ProcessReferentialIdentifier.Ref3].IsEnabled) { row[j++] = GetMultiReferentialLabels(action.Ref3, ProcessReferentialIdentifier.Ref3); } // Ref4 if (_referentialsUse[ProcessReferentialIdentifier.Ref4].IsEnabled) { row[j++] = GetMultiReferentialLabels(action.Ref4, ProcessReferentialIdentifier.Ref4); } // Ref5 if (_referentialsUse[ProcessReferentialIdentifier.Ref5].IsEnabled) { row[j++] = GetMultiReferentialLabels(action.Ref5, ProcessReferentialIdentifier.Ref5); } // Ref6 if (_referentialsUse[ProcessReferentialIdentifier.Ref6].IsEnabled) { row[j++] = GetMultiReferentialLabels(action.Ref6, ProcessReferentialIdentifier.Ref6); } // Ref7 if (_referentialsUse[ProcessReferentialIdentifier.Ref7].IsEnabled) { row[j++] = GetMultiReferentialLabels(action.Ref7, ProcessReferentialIdentifier.Ref7); } // IsRandom row[j++] = action.IsRandom.ToString(); // Custom Text row[j++] = action.CustomTextValue; row[j++] = action.CustomTextValue2; row[j++] = action.CustomTextValue3; row[j++] = action.CustomTextValue4; // Custom Numeric row[j++] = action.CustomNumericValue; row[j++] = action.CustomNumericValue2; row[j++] = action.CustomNumericValue3; row[j++] = action.CustomNumericValue4; // DifferenceReason row[j++] = action.DifferenceReason; // Amélioration if (action.Reduced != null) { // Amélioration I/E/S string label; if (ActionsTimingsMoveManagement.IsActionInternal(action)) { label = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_Reduced_Internal"); } else if (ActionsTimingsMoveManagement.IsActionExternal(action)) { label = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_Reduced_External"); } else if (ActionsTimingsMoveManagement.IsActionDeleted(action)) { label = LocalizationManager.GetString("ViewModel_AnalyzeRestitution_Export_Action_Reduced_Deleted"); } else { throw new ArgumentOutOfRangeException(); } row[j++] = label; row[j++] = action.Reduced.Solution; row[j++] = CellContent.Percentage(action.Reduced.ReductionRatio); } else { row[j++] = null; row[j++] = null; row[j++] = null; } } #endregion data[i] = row; i++; } _file.AddTable(sheet, actionsFormats.ToArray(), data, cellReference); // Ajouter une image cellReference.NewLine(); i = 0; foreach (var action in actions) { if (action.Thumbnail != null) { // Ajout du libellé du lien var tableCellRef = new CellReference(1, tableRowIndex + (uint)i + 1); _file.SetCellValue(sheet, tableCellRef, new CellContent(action.ActionId.ToString(), CellDataType.Hyperlink)); // Ajout du lien string definedName = string.Format("Action.{0}", action.ActionId); _file.CreateDefinedName(sheet, cellReference, definedName); _file.AddHyperlinkToDefinedName(sheet, tableCellRef, definedName, ""); // Ajout du libellé _file.SetCellValue(sheet, cellReference, string.Format("{0} {1}", action.WBS, action.Label ?? string.Empty)); cellReference.MoveRight(); // Ajout de l'image using (var ms = new System.IO.MemoryStream(action.Thumbnail.Data)) { var decoder = System.Windows.Media.Imaging.BitmapDecoder.Create(ms, System.Windows.Media.Imaging.BitmapCreateOptions.PreservePixelFormat, System.Windows.Media.Imaging.BitmapCacheOption.OnLoad); var size = new System.Windows.Size(decoder.Frames[0].PixelWidth, decoder.Frames[0].PixelHeight); var mimeTypes = decoder.CodecInfo.MimeTypes; ImagePartType imageType; if (mimeTypes.Contains("image/jpeg")) { imageType = ImagePartType.Jpeg; } else if (mimeTypes.Contains("image/bmp")) { imageType = ImagePartType.Bmp; } else if (mimeTypes.Contains("image/png")) { imageType = ImagePartType.Png; } else { continue; } string pictureName = string.Format("Thumbnail.{0}", action.ActionId); uint rowsLength = _file.AddImage(sheet, action.Thumbnail.Data, imageType, action.ActionId.ToString(), pictureName, size, cellReference); // On déplace la cellule active à après l'image cellReference = new CellReference(1, cellReference.RowIndex + rowsLength); } } i++; } }
public void CreateTest() { string outFile = Path.Combine(TestContext.DeploymentDirectory, ExcelExporter.GetFileNameWithExtension("test")); CellContent[][] data = new CellContent[1][]; ExcelExporter file = null; try { file = ExcelExporter.Create(outFile); } catch (ExcelExporter.FileAlreadyInUseExeption) { return; // Une notification a déjà été levée dans ce cas } var sheet = file.CreateSheet("Test"); var cellRef = new CellReference(); // String file.SetCellValue(sheet, cellRef, "string"); cellRef.MoveRight(); file.SetCellValue(sheet, cellRef, ""); cellRef.MoveRight(); file.SetCellValue(sheet, cellRef, new CellContent(null, CellDataType.String)); cellRef.MoveRight(); cellRef.NewLine(); // Number file.SetCellValue(sheet, cellRef, 4); cellRef.MoveRight(); file.SetCellValue(sheet, cellRef, 1.02); cellRef.MoveRight(); file.SetCellValue(sheet, cellRef, 1.54E-12); cellRef.MoveRight(); file.SetCellValue(sheet, cellRef, -12544.561681); cellRef.MoveRight(); cellRef.NewLine(); // Percentage file.SetCellValue(sheet, cellRef, CellContent.Percentage(.1)); cellRef.MoveRight(); file.SetCellValue(sheet, cellRef, CellContent.Percentage(.4656848468)); cellRef.MoveRight(); file.SetCellValue(sheet, cellRef, CellContent.Percentage(3)); cellRef.MoveRight(); file.SetCellValue(sheet, cellRef, CellContent.Percentage(-2)); cellRef.MoveRight(); cellRef.NewLine(); // Timespan file.SetCellValue(sheet, cellRef, TimeSpan.FromMinutes(34.652155648)); cellRef.MoveRight(); file.SetCellValue(sheet, cellRef, TimeSpan.FromDays(42.656)); cellRef.MoveRight(); file.SetCellValue(sheet, cellRef, TimeSpan.FromHours(-1.6548)); cellRef.MoveRight(); file.SetCellValue(sheet, cellRef, CellContent.TimeSpan(TimeSpan.FromHours(5.6586).Ticks)); cellRef.MoveRight(); cellRef.NewLine(); // Date file.SetCellValue(sheet, cellRef, new DateTime(1970, 1, 1)); cellRef.MoveRight(); file.SetCellValue(sheet, cellRef, new DateTime(2013, 4, 5, 6, 52, 34, 658)); cellRef.MoveRight(); file.SetCellValue(sheet, cellRef, new DateTime(1900, 10, 10)); cellRef.MoveRight(); cellRef.NewLine(); // Hyperlink file.SetCellValue(sheet, cellRef, new CellContent("hyperlink", CellDataType.Hyperlink)); cellRef.MoveRight(); file.SetCellValue(sheet, cellRef, new CellContent("", CellDataType.Hyperlink)); cellRef.MoveRight(); file.SetCellValue(sheet, cellRef, new CellContent(null, CellDataType.Hyperlink)); cellRef.MoveRight(); cellRef.NewLine(); file.SaveAndClose(); Assert.IsTrue(File.Exists(outFile)); //System.Diagnostics.Process.Start(outFile); TestContext.AddResultFile(outFile); }