shah Momin

shah Momin

  • NA
  • 176
  • 22.3k

MsoTriState' is a type, which is not valid in the given context Fix It

May 27 2022 11:44 AM
 private void ExportMonthlyPresentation(object sender, DoWorkEventArgs e)
    {
      BackgroundWorker backgroundWorker = sender as BackgroundWorker;
      Dictionary<string, object> dictionary = e.Argument as Dictionary<string, object>;
      DataSet dataSet = (DataSet) dictionary["DataTable"];
      string path = (string) dictionary["fileName"];
      string str1 = (string) dictionary["monthYear"];
      DataRow[] dataRowArray = (DataRow[]) dictionary["AppSettings"];
      string str2 = "";
      int num1 = 3;
      int num2 = 15;
      for (int index = 0; index < dataRowArray.Length; ++index)
      {
        if (dataRowArray[index]["settingname"].ToString() == "SlideSize")
          str2 = dataRowArray[index]["settingvalue"].ToString();
        else if (dataRowArray[index]["settingname"].ToString() == "VolunteerPerSlide")
          num1 = int.Parse(dataRowArray[index]["settingvalue"].ToString()) + 1;
        else if (dataRowArray[index]["settingname"].ToString() == "VideoTimePerSlide")
          num2 = int.Parse(dataRowArray[index]["settingvalue"].ToString());
      }
      DataTable table = dataSet.Tables[0];
      Microsoft.Office.Interop.PowerPoint.Application application = (Microsoft.Office.Interop.PowerPoint.Application) new ApplicationClass();
      Presentation presentation = ((_Application) application).Presentations.Add((MsoTriState) -1);
      CustomLayout customLayout = ((_Master) ((_Presentation) presentation).SlideMaster).CustomLayouts[(object) (PpSlideLayout) 4];
      if (str2 == "16 x 9")
        ((_Presentation) ((_Application) application).ActivePresentation).PageSetup.SlideSize = (PpSlideSizeType) 15;
      else if (str2 == "16 x 10")
        ((_Presentation) ((_Application) application).ActivePresentation).PageSetup.SlideSize = (PpSlideSizeType) 16;
      else
        ((_Presentation) ((_Application) application).ActivePresentation).PageSetup.SlideSize = (PpSlideSizeType) 1;
      ((_Presentation) ((_Application) application).ActivePresentation).PageSetup.SlideOrientation = (MsoOrientation) 1;
      int num3 = 1;
      int num4 = num1;
      Slides slides = ((_Presentation) presentation).Slides;
      _Slide slide1 = (_Slide) slides.AddSlide(num3, customLayout);
      int count1 = dataSet.Tables[0].Rows.Count;
      int count2 = dataSet.Tables[0].Columns.Count;
      Microsoft.Office.Interop.PowerPoint.Shape shape1 = slide1.Shapes.AddTable(1, 4, 0.0f, 0.0f, 720f, 10f);
      shape1.Table.Columns[1].Width = 345f;
      shape1.Table.Cell(1, 1).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = (PpParagraphAlignment) 2;
      shape1.Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = "MONTH: " + str1;
      shape1.Table.Columns[2].Width = 157f;
      shape1.Table.Cell(1, 2).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = (PpParagraphAlignment) 2;
      shape1.Table.Cell(1, 2).Shape.TextFrame.TextRange.Text = "Point";
      shape1.Table.Columns[3].Width = 157f;
      shape1.Table.Cell(1, 3).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = (PpParagraphAlignment) 2;
      shape1.Table.Cell(1, 3).Shape.TextFrame.TextRange.Text = "Days";
      shape1.Table.Columns[4].Width = 60f;
      shape1.Table.Cell(1, 4).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = (PpParagraphAlignment) 2;
      shape1.Table.Cell(1, 4).Shape.TextFrame.TextRange.Text = "Hour";
      Microsoft.Office.Interop.PowerPoint.Shape shape2 = slide1.Shapes.AddTable(num4, count2, 0.0f, 30f, 720f, 160f);
      shape2.Table.Columns[1].Width = 35f;
      shape2.Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = "S#";
      shape2.Table.Columns[2].Width = 80f;
      shape2.Table.Cell(1, 2).Shape.TextFrame.TextRange.Text = "Position";
      shape2.Table.Columns[3].Width = 230f;
      shape2.Table.Cell(1, 3).Shape.TextFrame.TextRange.Text = "Volunteer Name";
      shape2.Table.Columns[4].Width = 35f;
      shape2.Table.Columns[5].Width = 35f;
      shape2.Table.Columns[6].Width = 35f;
      shape2.Table.Columns[7].Width = 52f;
      shape2.Table.Columns[8].Width = 35f;
      shape2.Table.Columns[9].Width = 35f;
      shape2.Table.Columns[10].Width = 35f;
      shape2.Table.Columns[11].Width = 52f;
      shape2.Table.Columns[12].Width = 60f;
      shape2.Table.Cell(1, 4).Shape.TextFrame.TextRange.Text = "M";
      shape2.Table.Cell(1, 5).Shape.TextFrame.TextRange.Text = "E";
      shape2.Table.Cell(1, 6).Shape.TextFrame.TextRange.Text = "Ex";
      shape2.Table.Cell(1, 7).Shape.TextFrame.TextRange.Text = "Total";
      shape2.Table.Cell(1, 8).Shape.TextFrame.TextRange.Text = "M";
      shape2.Table.Cell(1, 9).Shape.TextFrame.TextRange.Text = "E";
      shape2.Table.Cell(1, 10).Shape.TextFrame.TextRange.Text = "Ex";
      shape2.Table.Cell(1, 11).Shape.TextFrame.TextRange.Text = "Total";
      shape2.Table.Cell(1, 12).Shape.TextFrame.TextRange.Text = "Total";
      int num5 = 2;
      for (int index = 0; index < count1; ++index)
      {
        if (backgroundWorker.CancellationPending)
        {
          e.Cancel = true;
          return;
        }
        int num6 = int.Parse(table.Rows[index][10].ToString());
        int num7 = 1;
        for (int columnIndex = 0; columnIndex < count2; ++columnIndex)
        {
          shape2.Table.Cell(num5, num7).Shape.TextFrame.TextRange.Text = table.Rows[index][columnIndex].ToString();
          if (num6 < 15)
          {
            shape2.Table.Cell(num5, num7).Shape.Fill.ForeColor.RGB = (int) byte.MaxValue;
            shape2.Table.Cell(num5, num7).Shape.TextFrame.TextRange.Font.Color.RGB = 16777215;
          }
          ++num7;
        }
        shape2.Table.Cell(num5, 1).Shape.TextFrame.TextRange.Font.Bold = (MsoTriState) -1;
        shape2.Table.Cell(num5, 7).Shape.TextFrame.TextRange.Font.Bold = (MsoTriState) -1;
        shape2.Table.Cell(num5, 11).Shape.TextFrame.TextRange.Font.Bold = (MsoTriState) -1;
        shape2.Table.Cell(num5, 12).Shape.TextFrame.TextRange.Font.Bold = (MsoTriState) -1;
        shape2.Table.Cell(num5, 12).Shape.TextFrame.TextRange.Font.Size = 16f;
        backgroundWorker.ReportProgress((index + 1) * 100 / count1, (object) ((index + 1).ToString() + " of " + (object) count1 + " records processed..."));
        if (num5 == num4)
        {
          ++num3;
          _Slide slide2 = (_Slide) slides.AddSlide(num3, customLayout);
          Microsoft.Office.Interop.PowerPoint.Shape shape3 = slide2.Shapes.AddTable(1, 4, 0.0f, 0.0f, 720f, 10f);
          shape3.Table.Columns[1].Width = 345f;
          shape3.Table.Cell(1, 1).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = (PpParagraphAlignment) 2;
          shape3.Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = "MONTH: " + str1;
          shape3.Table.Columns[2].Width = 157f;
          shape3.Table.Cell(1, 2).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = (PpParagraphAlignment) 2;
          shape3.Table.Cell(1, 2).Shape.TextFrame.TextRange.Text = "Point";
          shape3.Table.Columns[3].Width = 157f;
          shape3.Table.Cell(1, 3).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = (PpParagraphAlignment) 2;
          shape3.Table.Cell(1, 3).Shape.TextFrame.TextRange.Text = "Days";
          shape3.Table.Columns[4].Width = 60f;
          shape3.Table.Cell(1, 4).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = (PpParagraphAlignment) 2;
          shape3.Table.Cell(1, 4).Shape.TextFrame.TextRange.Text = "Hour";
          shape2 = count1 - index + 1 > num4 - 1 ? slide2.Shapes.AddTable(num4, count2, 0.0f, 30f, 720f, 160f) : slide2.Shapes.AddTable(count1 - index, count2, 0.0f, 30f, 720f, 160f);
          shape2.Table.Columns[1].Width = 35f;
          shape2.Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = "S#";
          shape2.Table.Columns[2].Width = 80f;
          shape2.Table.Cell(1, 2).Shape.TextFrame.TextRange.Text = "Position";
          shape2.Table.Columns[3].Width = 230f;
          shape2.Table.Cell(1, 3).Shape.TextFrame.TextRange.Text = "Volunteer Name";
          shape2.Table.Columns[4].Width = 35f;
          shape2.Table.Columns[5].Width = 35f;
          shape2.Table.Columns[6].Width = 35f;
          shape2.Table.Columns[7].Width = 52f;
          shape2.Table.Columns[8].Width = 35f;
          shape2.Table.Columns[9].Width = 35f;
          shape2.Table.Columns[10].Width = 35f;
          shape2.Table.Columns[11].Width = 52f;
          shape2.Table.Columns[12].Width = 60f;
          shape2.Table.Cell(1, 4).Shape.TextFrame.TextRange.Text = "M";
          shape2.Table.Cell(1, 5).Shape.TextFrame.TextRange.Text = "E";
          shape2.Table.Cell(1, 6).Shape.TextFrame.TextRange.Text = "Ex";
          shape2.Table.Cell(1, 7).Shape.TextFrame.TextRange.Text = "Total";
          shape2.Table.Cell(1, 8).Shape.TextFrame.TextRange.Text = "M";
          shape2.Table.Cell(1, 9).Shape.TextFrame.TextRange.Text = "E";
          shape2.Table.Cell(1, 10).Shape.TextFrame.TextRange.Text = "Ex";
          shape2.Table.Cell(1, 11).Shape.TextFrame.TextRange.Text = "Total";
          shape2.Table.Cell(1, 12).Shape.TextFrame.TextRange.Text = "Total";
          num5 = 1;
        }
        ++num5;
      }
      foreach (_Slide slide3 in slides)
      {
        slide3.SlideShowTransition.AdvanceTime = (float) num2;
        slide3.SlideShowTransition.AdvanceOnTime = (MsoTriState) -1;
      }
      ((_Presentation) presentation).SaveAs(path, (PpSaveAsFileType) 11, (MsoTriState) -1);
      backgroundWorker.ReportProgress(-1, (object) "Creating video report...");
      string str3 = Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + ".wmv";
      ((_Presentation) presentation).SaveAs(str3, (PpSaveAsFileType) 37, (MsoTriState) -1);
      while (((_Presentation) ((_Application) application).ActivePresentation).CreateVideoStatus == 1 || ((_Presentation) ((_Application) application).ActivePresentation).CreateVideoStatus == 2)
      {
       System.Windows.Forms.Application.DoEvents();
        Thread.Sleep(1000);
      }
      backgroundWorker.ReportProgress(100, (object) "Video creation completed");
      Thread.Sleep(1000);
      ((_Presentation) presentation).Close();
      ((_Application) application).Quit();
    }

this Line Show Me Error :-      Presentation presentation = ((_Application) application).Presentations.Add((MsoTriState) -1);

i Will High Light Error

MsoTriState' is a type, which is not valid in the given context