1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| Outlook.TaskItem Tache = (Outlook.TaskItem)
this.Application.CreateItem(Outlook.OlItemType.olTaskItem);
try
{
Outlook.Folders folders = this.Application.ActiveExplorer().Session.Folders;
Outlook.Folder DossiersPublics = (Outlook.Folder)folders["Dossiers Publics"];
Outlook.Folder tous = (Outlook.Folder)DossiersPublics.Folders["Tous les dossiers publics"];
Outlook.Folder RSI = (Outlook.Folder)tous.Folders["RSI"]; //sous dossier
Outlook.Folder Incidents = (Outlook.Folder)RSI.Folders["Incidents"];//dossier publics taches
Outlook.Items searchFolder = Incidents.Items;
#region ouverture EXCEL
Excel._Worksheet xlFeuill;
Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
excel.Visible = true;
Excel.Workbook classeur;
string chemin = @"C:\Taches.xltx";
object Omissing = Type.Missing;
object Otrue = true;
// Ouvrir le doc à partir du modèle
classeur = excel.Workbooks.Open(chemin, Omissing, Omissing, Omissing, Omissing, Omissing, Omissing, Omissing, Omissing, Omissing, Omissing, Omissing, Omissing, Omissing, Omissing);
Microsoft.Office.Interop.Excel.Sheets xlFeuilles = classeur.Sheets;
xlFeuill = (Microsoft.Office.Interop.Excel._Worksheet)xlFeuilles["Feuil1"];
xlFeuill.Select(Type.Missing);
#endregion
Int counter = 0;
foreach (Outlook.TaskItem Taches in searchFolder) //transfert dans Excel
{
if (Taches.Status != Microsoft.Office.Interop.Outlook.OlTaskStatus.olTaskComplete)
{
xlFeuill.Cells[counter + 3, "a"] = Taches.Subject;
#region test ETAT
string TachesStatus = "ee";
switch (Taches.Status.ToString())
{
case "olTaskComplete":
TachesStatus = "Terminée";
break;
case "olTaskDeferred":
TachesStatus = "Différée";
break;
case "olTaskInProgress":
TachesStatus = "En cours de réalisation";
break;
case "olTaskNotStarted":
TachesStatus = "Non commencée";
break;
case "olTaskWaiting":
TachesStatus = "Attente de quelqu'un d'autre";
break;
default:
break;
}
#endregion
xlFeuill.Cells[counter + 3, "b"] = TachesStatus.ToString();
#region Gestion des dates (pas de date d'échéance)
DateTime datetest = new DateTime(4501, 01, 01);
if (Taches.DueDate == datetest)
{
xlFeuill.Cells[counter + 3, "c"] = "";
}
else
{
xlFeuill.Cells[counter + 3, "c"] = Taches.DueDate.ToShortDateString();
}
#endregion
xlFeuill.Cells[counter + 3, "d"] = Taches.PercentComplete;
counter = counter + 1;
}
}
MessageBox.Show("Il y a " + counter + " Tâches.");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message );
} |
Partager