public void CreateSlide(string slideTitle, string slideBody) { if (slideBody.Contains("\r\n\r\n") || String.IsNullOrEmpty(slideBody) || slideBody == "\r\n") { return; } float slideWidth = m_pptPres.PageSetup.SlideWidth; float lyricsShapeWidth = 900; float lyricsShapeLeft = slideWidth * 0.5f - lyricsShapeWidth * 0.5f; int textBoxHeight = 0; PowerPoint.Slide pptSlide = m_pptSlides.Add(m_pptSlides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutBlank); PowerPoint.Shapes pptShapes = pptSlide.Shapes; pptShapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal, /*left*/ 50, /*top*/ 50, /*width*/ 700, /*height*/ textBoxHeight); PowerPoint.Shape titleTextbox = pptShapes[1]; WriteToTextbox(slideTitle, titleTextbox, 50); pptShapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal, lyricsShapeLeft, 150, lyricsShapeWidth, textBoxHeight); PowerPoint.Shape lyricsTextbox = pptShapes[2]; WriteToLyricsTextbox(slideBody, lyricsTextbox, 35); }
static void Main(string[] args) { //Creating an Application Application myApplication = new Application(); //Creating a Presentation - opening a existing PowerPoint you need to put the @ Presentation myPresentation = myApplication.Presentations.Open(@"C:\Users\lucaslemos\Desktop\Github\PowerPoint-CSharp\tutorial_slide.pptx"); //Dealing with slides PowerPoint.Slides slides; //will be used as the whole collection of my presentation PowerPoint._Slide slide; //will be used as my current slide being edited slides = myPresentation.Slides; // (big S) PowerPoint.CustomLayout customLayout = myPresentation.SlideMaster.CustomLayouts[PowerPoint.PpSlideLayout.ppLayoutText]; slide = slides.AddSlide(2, customLayout); //Creating a new slide, which will be second slide of my presentation //CustomLayout is a mandatory input //Dealing with shapes PowerPoint.Shapes shapes = slide.Shapes; //taking all the shapes collection from my current slide //Deleting all shapes //delete_shapes(shapes); //calling a new function to delete the shapes from the current slide //Add pictures addPictures(slide); //Add TextBox add_textbox(slide); }
void ppt2ContentImages(Presentation pptPresentation, string exportPath) { //slide extract image content // https://stackoverflow.com/questions/4990825/export-movies-from-powerpoint-to-file-in-c-sharp //https://stackoverflow.com/questions/42442659/c-sharp-save-ppt-shape-msopicture-as-image-w-office-interop foreach (PowerPoint.Slide slide in pptPresentation.Slides) { PowerPoint.Shapes slideShapes = slide.Shapes; int count = 0; try { foreach (PowerPoint.Shape shape in slideShapes) { if (shape.Type == MsoShapeType.msoPicture) { //LinkFormat.SourceFullName contains the movie path //get the path like this shape.Export(exportPath + @"\" + "content" + slide.SlideNumber + "_" + count++ + ".png", Microsoft.Office.Interop.PowerPoint.PpShapeFormat.ppShapeFormatPNG); Console.WriteLine("Exported" + exportPath + @"\" + "content" + slide.SlideNumber + "_" + count++ + ".png"); //System.IO.File.Copy(shape.LinkFormat.SourceFullName, path + imageBase + @"\" + "content" + slide.SlideNumber + "_"+ count++ + ".png"); } } } catch (Exception e) { // TODO } } }
private static void MakeShapesInvisible(PowerPoint.Shapes shapes) { foreach (PowerPoint.Shape shape in shapes) { shape.Visible = Microsoft.Office.Core.MsoTriState.msoFalse; } }
/************************** FINAL PPT- Content Images - Extract ***************************** * //slide extract image content * // https://stackoverflow.com/questions/4990825/export-movies-from-powerpoint-to-file-in-c-sharp * //https://stackoverflow.com/questions/42442659/c-sharp-save-ppt-shape-msopicture-as-image-w-office-interop */ public void pptContentExtract(string src_pptfilePath, string exportPath, string prefix) { Console.WriteLine("PPT File Location:" + src_pptfilePath); Microsoft.Office.Interop.PowerPoint.Application pptApplication = new Microsoft.Office.Interop.PowerPoint.Application(); Presentation pptPresentation = pptApplication.Presentations .Open(src_pptfilePath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); foreach (PowerPoint.Slide slide in pptPresentation.Slides) { PowerPoint.Shapes slideShapes = slide.Shapes; int count = 0; foreach (PowerPoint.Shape shape in slideShapes) { if (shape.Type == MsoShapeType.msoPicture) { //LinkFormat.SourceFullName contains the movie path //get the path like this shape.Export(exportPath + @"\" + "content" + slide.SlideNumber + "_" + count++ + ".png", Microsoft.Office.Interop.PowerPoint.PpShapeFormat.ppShapeFormatPNG); Console.WriteLine("Exported" + exportPath + @"\" + "content" + slide.SlideNumber + "_" + count++ + ".png"); //System.IO.File.Copy(shape.LinkFormat.SourceFullName, path + imageBase + @"\" + "content" + slide.SlideNumber + "_"+ count++ + ".png"); } } } pptPresentation.Close(); }
private static string GetSlideTitle(Slide s) { // If the slide has a Title shape, use that text if (s.Shapes.HasTitle == Microsoft.Office.Core.MsoTriState.msoTrue) { return(CleanString(s.Shapes.Title.TextFrame.TextRange.Text)); } else { if (s.Shapes.Count > 0) { Microsoft.Office.Interop.PowerPoint.Shapes shapes = s.Shapes; IEnumerator iEN = shapes.GetEnumerator(); // Return the first shape that has a TextFrame while (iEN.MoveNext()) { Microsoft.Office.Interop.PowerPoint.Shape shape = (Microsoft.Office.Interop.PowerPoint.Shape)iEN.Current; if (shape.HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue) { if (shape.TextFrame.TextRange.Text != string.Empty) { return(CleanString(shape.TextFrame.TextRange.Text)); } } } // If none of the shapes has a text frame, return the Slide Name return(s.Name); } else { // If there are no Shapes in the Slide, return the Slide Name return(s.Name); } } }
private string GetStringSummary(PP.Shapes shapes) { string text = ""; foreach (PP.Shape shape in shapes) { if (shape.Name.Contains("Slide Number Placeholder") || shape.Name == "source" || shape.HasTextFrame != Core.MsoTriState.msoTrue) { continue; } try { //remove slide numbers if (text == "" && Util.Parse <int?>(shape.TextFrame.TextRange.Text).HasValue) { continue; } text += " " + shape.TextFrame.TextRange.Text.Replace("\r", " ").Replace("\n", " ").Replace("\v", " ").Trim(); } catch (Exception) { } } return(text.Trim()); }
private static void replaceVariable(Microsoft.Office.Interop.PowerPoint.Shapes shapes, System.Data.DataTable dt) { foreach (Microsoft.Office.Interop.PowerPoint.Shape shape in shapes) { if (shape.HasTextFrame == MsoTriState.msoTrue) { string text = shape.TextFrame.TextRange.Text; string index = Regex.Match(text, @"\d+").Value; if (text.Contains("<<") && text.Contains(">>")) { text = text.Replace("<<", ""); text = text.Replace(">>", ""); if (dt.Columns.Contains(text)) { shape.TextFrame.TextRange.Text = shape.TextFrame.TextRange.Text.Replace("<<" + text + ">>", dt.Rows[0][text].ToString()); } else if (index != "") { string field = text.Replace(index, ""); shape.TextFrame.TextRange.Text = shape.TextFrame.TextRange.Text.Replace("<<" + text + ">>", dt.Rows[Int32.Parse(index) - 1][field].ToString()); } } } } }
private void awardHeadingMasterCombo_SelectedIndexChanged(object sender, EventArgs e) { int comboIndex = awardHeadingMasterCombo.SelectedIndex; mGenInfo.awardHeadingLayoutIndex = comboIndex + 1; PowerPoint.CustomLayout selectedLayout = mPresentation.SlideMaster.CustomLayouts[comboIndex + 1]; mPresentation.Slides.AddSlide(mPresentation.Slides.Count + 1, selectedLayout); string workingDirectory = Directory.GetCurrentDirectory(); awardHeadingTextBoxCombo.Items.Clear(); // Load the placeholder combo boxes and such PowerPoint.Shapes shapes = selectedLayout.Shapes; PowerPoint.Placeholders placeholders = shapes.Placeholders; foreach (PowerPoint.Shape placeholder in placeholders) { awardHeadingTextBoxCombo.Items.Add(placeholder.TextFrame.TextRange.Text); } if (File.Exists(workingDirectory + "/AwardHeadingRender.png")) { if (headingPictureBox.Image != null) { headingPictureBox.Image.Dispose(); } File.Delete(workingDirectory + "/AwardHeadingRender.png"); } mPresentation.Slides[mPresentation.Slides.Count].Export(workingDirectory + "/AwardHeadingRender.png", "png", headingPictureBox.Width, headingPictureBox.Height); headingPictureBox.Image = Image.FromFile(workingDirectory + "/AwardHeadingRender.png"); }
private Bitmap[] ShapeTypesToBitmaps(Array types, string shapeType) { Shapes shapes = SyncFormatUtil.GetTemplateShapes(); Bitmap[] bitmaps = new Bitmap[types.Length]; for (int i = 0; i < types.Length; i++) { if (!((MsoAutoShapeType)types.GetValue(i)).ToString().Contains(shapeType)) { continue; } try { Shape shape = shapes.AddShape( (MsoAutoShapeType)types.GetValue(i), 0, 0, TooltipsLabConstants.DisplayImageSize.Width, TooltipsLabConstants.DisplayImageSize.Height); ShapeUtil.FormatCalloutToDefaultStyle(shape); bitmaps[i] = new Bitmap(GraphicsUtil.ShapeToBitmap(shape)); shape.SafeDelete(); } catch { } } return(bitmaps); }
private void RemoveAllShapes(Microsoft.Office.Interop.PowerPoint.Shapes shapes) { if (shapes.Count > 0) { shapes[1].Delete(); RemoveAllShapes(shapes); } }
private static void LoopPageShape(Shapes shps) { foreach (Shape shp in shps) { RenameShape(shp); DeleteTag(shp); DeleteText(shp); } }
private void GetUsedShapeLanguage(Shapes slideShapes, HashSet <MsoLanguageID> usedLanguages) { for (int j = 1; j <= slideShapes.Count; j++) { if (slideShapes[j].HasTextFrame == MsoTriState.msoTrue) { usedLanguages.Add(slideShapes[j].TextFrame.TextRange.LanguageID); } } }
private void SetShapeLanguage(Shapes slideShapes) { for (int j = 1; j <= slideShapes.Count; j++) { if (slideShapes[j].HasTextFrame == MsoTriState.msoTrue) { slideShapes[j].TextFrame.TextRange.LanguageID = (MsoLanguageID)dropDownLanguage.SelectedItem.Tag; } } }
private List <Shape> sortShapesByZIndex(PowerPoint.Shapes shapes) { List <Shape> ordered = new List <Shape>(); foreach (PowerPoint.Shape shape in shapes) { ordered.Add(shape); } ordered.Sort(new ZIndexShapeComparer()); return(ordered); }
public static bool CanCopyMsoPlaceHolder(Shape placeholder, Shapes shapesSource) { var emptyArray = new Format[0]; Shape copyAttempt = CopyMsoPlaceHolder(emptyArray, placeholder, shapesSource); if (copyAttempt == null) { return(false); } copyAttempt.Delete(); return(true); }
public Shape GetShape(string shapeKey) { Shapes shapes = Slides[0].Shapes; for (int i = 1; i <= shapes.Count; i++) { if (shapes[i].Name.Equals(shapeKey)) { return(shapes[i]); } } return(null); }
public ShapeRange SelectShapesByPrefix(string prefix) { List <string> nameList = new List <String>(); Microsoft.Office.Interop.PowerPoint.Shapes shapes = FunctionalTestExtensions.GetCurrentSlide().Shapes; foreach (Shape sh in shapes) { if (sh.Name.StartsWith(prefix)) { nameList.Add(sh.Name); } } return(SelectShapes(nameList)); }
private void button5_Click(object sender, EventArgs e) { comboBox1.Items.Clear(); if (radioButton1.Checked) { PowerPoint.Slide slide = app.ActiveWindow.View.Slide; PowerPoint.Shapes shapes = slide.Shapes; foreach (PowerPoint.Shape item in shapes) { if (item.ThreeD.Visible == Microsoft.Office.Core.MsoTriState.msoTrue || (item.Type == Microsoft.Office.Core.MsoShapeType.msoGroup && (item.GroupItems[1].ThreeD.Visible == Microsoft.Office.Core.MsoTriState.msoTrue || item.GroupItems[2].ThreeD.Visible == Microsoft.Office.Core.MsoTriState.msoTrue))) { comboBox1.Items.Add(item.Name); } } } if (radioButton2.Checked) { PowerPoint.Shapes shapes = app.SlideShowWindows[1].View.Slide.Shapes; foreach (PowerPoint.Shape item in shapes) { if (item.ThreeD.Visible == Microsoft.Office.Core.MsoTriState.msoTrue || (item.Type == Microsoft.Office.Core.MsoShapeType.msoGroup && (item.GroupItems[1].ThreeD.Visible == Microsoft.Office.Core.MsoTriState.msoTrue || item.GroupItems[2].ThreeD.Visible == Microsoft.Office.Core.MsoTriState.msoTrue))) { comboBox1.Items.Add(item.Name); } } } if (comboBox1.Items.Count == 0) { MessageBox.Show("没有在当前页面中找到三维形状,请确认后再刷新"); comboBox1.Enabled = false; textBox1.Enabled = false; button1.Enabled = false; button2.Enabled = false; button3.Enabled = false; checkBox1.Enabled = false; checkBox2.Enabled = false; checkBox3.Enabled = false; checkBox4.Enabled = false; textBox2.Enabled = false; button6.Enabled = false; label3.Enabled = false; comboBox1.Text = ""; } else { comboBox1.Enabled = true; comboBox1.Text = ""; } }
private static void replaceVariable(Microsoft.Office.Interop.PowerPoint.Shapes shapes, string varName, string value) { foreach (Microsoft.Office.Interop.PowerPoint.Shape shape in shapes) { Type t = shape.GetType(); PropertyInfo p = t.GetProperty("GroupItems"); if (shape.HasTextFrame == MsoTriState.msoTrue) { if (shape.TextFrame.TextRange.Text.Contains("<<" + varName + ">>")) { shape.TextFrame.TextRange.Text = shape.TextFrame.TextRange.Text.Replace("<<" + varName + ">>", value); } } } }
private void button1_Click(object sender, EventArgs e) { if (radioButton1.Checked) { PowerPoint.Slide slide = app.ActiveWindow.View.Slide; PowerPoint.Shapes shapes = slide.Shapes; foreach (PowerPoint.Shape item in shapes) { if (item.Name == comboBox1.SelectedItem.ToString()) { float n = float.Parse(textBox1.Text.Trim()); if (item.Type == Microsoft.Office.Core.MsoShapeType.msoGroup) { foreach (PowerPoint.Shape item2 in item.GroupItems) { item2.ThreeD.IncrementRotationX(n); } } else { item.ThreeD.IncrementRotationX(n); } } } } if (radioButton2.Checked) { PowerPoint.Shapes shapes = app.SlideShowWindows[1].View.Slide.Shapes; foreach (PowerPoint.Shape item in shapes) { if (item.Name == comboBox1.SelectedItem.ToString()) { float n = float.Parse(textBox1.Text.Trim()); if (item.Type == Microsoft.Office.Core.MsoShapeType.msoGroup) { foreach (PowerPoint.Shape item2 in item.GroupItems) { item2.ThreeD.IncrementRotationX(n); } } else { item.ThreeD.IncrementRotationX(n); } } } } }
/// <summary> /// Shapes를 <see cref="List{}"/>로 변환해줍니다. /// </summary> /// <param name="pptshapes"></param> /// <param name="GetAllShapes"></param> /// <returns></returns> public static List <ppt.Shape> ShapesToList(ppt.Shapes pptshapes, bool GetAllShapes) { List <ppt.Shape> shapes = new List <ppt.Shape>(); foreach (ppt.Shape shape in pptshapes) { shapes.Add(shape); if (GetAllShapes && shape.Type == MsoShapeType.msoGroup) { shapes.AddRange(ShapesToList((ppt.Shapes)shape.GroupItems, true)); } } return(shapes); }
public async Task <bool> WriteDataFor100(String strID) { try { JObject jsonData = await RequestData.GetWxPPTData("164"); if (jsonData.Value <String>("code").Equals("200") && jsonData.Value <JObject>("data") != null) { JObject dataObj = jsonData["data"].ToObject <JObject>(); string pptdata = dataObj.Value <String>("pptdata"); JArray pptdataArr = JsonConvert.DeserializeObject <JArray>(pptdata); foreach (JObject jObject in pptdataArr) { string picUrl = jObject.Value <String>("picurl"); string content = jObject.Value <String>("content"); int index = (int)decimal.Parse(jObject.Value <string>("index")); PowerPoint.Shapes shapes = Globals.ThisAddIn.Application.ActivePresentation.Slides[index].Shapes; PowerPoint.Shape shape = PPTAPI.getShape(shapes, "pic_1"); if (shape != null) { if (!String.IsNullOrEmpty(picUrl)) { string strPath = Request.HttpDownload(picUrl).Result; shapes.AddPicture(strPath, Microsoft.Office.Core.MsoTriState.msoCTrue, Microsoft.Office.Core.MsoTriState.msoCTrue, shape.Left, shape.Top, shape.Width, shape.Height); shape.Delete(); } } shape = PPTAPI.getShape(shapes, "text_1"); if (shape != null) { shape.TextFrame.TextRange.Text = jObject.Value <String>("content"); } } } else { return(false); } } catch { } return(true); }
public void RemoveShape(string shapeKey) { int index = 1; Shapes shapes = Slides[0].Shapes; while (index <= shapes.Count) { if (shapes[index].Name.Equals(shapeKey)) { shapes[index].Delete(); } else { index++; } } }
/// <summary> /// allShapes에 모든 <see cref="ppt.Shape"/>를 추가합니다. /// </summary> /// <param name="shapes"></param> /// <param name="allShapes"></param> public void GetAllShapes(ppt.Shapes shapes, ref List <ppt.Shape> allShapes) { foreach (ppt.Shape shape in shapes) { allShapes.Add(shape); //shape.TextFrame.TextRange.Text = "!"; //shape.Child == MsoTriState.msoTrue && if (shape.Type == MsoShapeType.msoGroup) { if (shape.GroupItems.Count > 0) { GetChildShapes(shape.GroupItems, ref allShapes); } } } }
public ShapeRange ToShapeRange(IEnumerable <Shape> shapes) { var shapeList = shapes.ToList(); var oldNames = shapeList.Select(shape => shape.Name).ToList(); var currentShapeNames = Shapes.Cast <Shape>().Select(shape => shape.Name); var unusedNames = Common.GetUnusedStrings(currentShapeNames, shapeList.Count); shapeList.Zip(unusedNames, (shape, name) => shape.Name = name).ToList(); var shapeRange = Shapes.Range(unusedNames); shapeList.Zip(oldNames, (shape, name) => shape.Name = name).ToList(); return(shapeRange); }
/// <summary> /// PowerPointのオブジェクトを削除 /// </summary> /// <param name="powerPoint">対象のPowerPoint</param> /// <param name="shapeName">オブジェクト名</param> private void DeletePowerPointShapes(ref PowerPoint.Application powerPoint, string shapeName) { // すべてのスライドからスタンプを削除 foreach (PowerPoint._Slide slide in powerPoint.ActivePresentation.Slides) { PowerPoint.Shapes shapes = (PowerPoint.Shapes)slide.Shapes; // スタンプ画像かオブジェクト名で判定して削除 foreach (PowerPoint.Shape shape in shapes) { if (shape.Name == shapeName) { shape.Delete(); } } } }
private static bool WriteOnSlide() { var resultado = false; string filePath = CurrentDirectory() + fileName; try { Application pptApplication = new Application(); Presentations multi_presentations = pptApplication.Presentations; Presentation presentation = multi_presentations.Open(filePath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); CustomLayout customLayout = presentation.SlideMaster.CustomLayouts[PpSlideLayout.ppLayoutText]; Slides slides = presentation.Slides; Microsoft.Office.Interop.PowerPoint.Shapes shapes = presentation.Slides[1].Shapes; TextRange objText; slides = presentation.Slides; var text1 = "Esto es una prueba de escribir en el titulo"; var text2 = "Estoy escribiendo en la seccion de contenido de la diapositiva PPT"; objText = shapes[1].TextFrame.TextRange; objText.Text = text1; objText.Font.Name = "Arial"; objText.Font.Size = 32; objText = shapes[2].TextFrame.TextRange; objText.Text = text2; objText.Font.Name = "Arial"; objText.Font.Size = 28; ReadWriteTxt(filePath); presentation.SaveAs(filePath, PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoTrue); presentation.Close(); pptApplication.Quit(); resultado = true; } catch (Exception ex) { WriteException(ex.ToString()); } return(resultado); }
public bool WriteOnSlide() { var resultado = false; string filePath = System.Web.HttpContext.Current.Server.MapPath("~/TemplatePPT/Plantilla1.pptx"); try { Application pptApplication = new Application(); Presentations multi_presentations = pptApplication.Presentations; Presentation presentation = multi_presentations.Open(filePath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); CustomLayout customLayout = presentation.SlideMaster.CustomLayouts[PpSlideLayout.ppLayoutText]; Slides slides = presentation.Slides; Microsoft.Office.Interop.PowerPoint.Shapes shapes = presentation.Slides[1].Shapes; TextRange objText; slides = presentation.Slides; var text1 = "Escribiendo en el titulo: " + DateTime.Now.ToString(); var text2 = "Descripcion PPT: " + DateTime.Now.ToString(); objText = shapes[1].TextFrame.TextRange; objText.Text = text1; objText.Font.Name = "Arial"; objText.Font.Size = 32; objText = shapes[2].TextFrame.TextRange; objText.Text = text2; objText.Font.Name = "Arial"; objText.Font.Size = 28; ReadWriteTxt(filePath); presentation.SaveAs(filePath, PpSaveAsFileType.ppSaveAsDefault, Microsoft.Office.Core.MsoTriState.msoTrue); presentation.Close(); pptApplication.Quit(); resultado = true; } catch (Exception ex) { } return(resultado); }
private static string ExtractSlideTitlefromShape(PowerPoint.Slide slide, string defaultValue) { PowerPoint.HeadersFooters headersFooters = slide.HeadersFooters; PowerPoint.Shapes mastershapes = slide.Master.Shapes; for (int i = 1; i <= slide.Shapes.Count; i++) { PowerPoint.Shape shape = slide.Shapes[i]; bool hasTextFrame = shape.HasTextFrame == MsoTriState.msoTrue; bool isTypePlaceholder = shape.Type.Equals(MsoShapeType.msoPlaceholder); bool hasTextInTextFrame = shape.TextFrame.HasText == MsoTriState.msoTrue; bool isTitleShape = shape.Name.ToLower().Contains("title"); if (isTypePlaceholder && hasTextFrame && hasTextInTextFrame && isTitleShape) { return(shape.TextFrame.TextRange.Text); } } return(defaultValue); }
private static void replaceChartVariable(Microsoft.Office.Interop.PowerPoint.Shapes shapes, System.Data.DataTable dt) { foreach (Microsoft.Office.Interop.PowerPoint.Shape shape in shapes) { if (shape.HasChart == MsoTriState.msoTrue) { var chartData = shape.Chart.ChartData; chartData.Activate(); var workbook = chartData.Workbook; workbook.Application.Visible = false; var dataSheet = workbook.Worksheets[1]; var firstColNumber = 1; var firstRowNumber = 1; var dataRowNumber = 2; int iCol = firstColNumber; foreach (DataColumn dc in dt.Columns) { dataSheet.Cells[firstRowNumber, iCol].Value = dc.ColumnName; iCol++; } int iRow = dataRowNumber; foreach (DataRow dr in dt.Rows) { iCol = 1; foreach (DataColumn dc in dt.Columns) { dataSheet.Cells[iRow, iCol].Value = dr[dc.ColumnName]; iCol++; } iRow++; } System.Threading.Thread.Sleep(1000); workbook.Close(true); System.Threading.Thread.Sleep(1000); shape.Chart.Refresh(); } } }
public void add_choices(ref List<question> questions, ref int question_no, ref int choices_no1) { if (questions[question_no].show_choices == true) { objShapes = objSlide.Shapes; objShape1 = objSlide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 20, 160, 600, 400); objShape1.TextEffect.FontName = questions[question_no].choices_font.Name; objShape1.TextEffect.FontSize = questions[question_no].choices_font.Size; if (questions[question_no].choices_font.Italic == true) objShape1.TextEffect.FontItalic = MsoTriState.msoTrue; else if (questions[question_no].choices_font.Italic == false) objShape1.TextEffect.FontItalic = MsoTriState.msoFalse; if (questions[question_no].choices_font.Bold == true) objShape1.TextEffect.FontBold = MsoTriState.msoTrue; else if (questions[question_no].choices_font.Bold == false) objShape1.TextEffect.FontBold = MsoTriState.msoFalse; objShape1.TextFrame.TextRange.Font.Color.RGB = ColorTranslator.ToOle(questions[question_no].choices_color); objShape1.TextFrame.AutoSize = PowerPoint.PpAutoSize.ppAutoSizeShapeToFitText; for (int i = 2; i <= choices_no1 + 1; i++) { objShape1.TextEffect.Text = objShape1.TextEffect.Text + (i - 1) + "-" + questions[question_no].choices[i - 2] + "\n\n"; //if (questions[question_no].choices_font.Italic == true) // objShape1.TextEffect.FontItalic = MsoTriState.msoTrue; //else if (questions[question_no].choices_font.Italic == false) // objShape1.TextEffect.FontItalic = MsoTriState.msoFalse; //if (questions[question_no].choices_font.Bold == true) // objShape1.TextEffect.FontBold = MsoTriState.msoTrue; //else if (questions[question_no].choices_font.Bold == false) // objShape1.TextEffect.FontBold = MsoTriState.msoFalse; } } }
public static void IncludeOthers(string path) { //Build Slide #2: //Add text to the slide title, format the text. Also add a chart to the //slide and change the chart type to a 3D pie chart. objSlide = objSlides.Add(objSlides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly); objTextRng = objSlide.Shapes[1].TextFrame.TextRange; objTextRng.Text = "My Chart"; objTextRng.Font.Name = "Comic Sans MS"; objTextRng.Font.Size = 48; objChart = (Graph.Chart)objSlide.Shapes.AddOLEObject(150, 150, 480, 320, "MSGraph.Chart.8", "", MsoTriState.msoFalse, "", 0, "", MsoTriState.msoFalse).OLEFormat.Object; objChart.ChartType = Graph.XlChartType.xl3DPie; objChart.Legend.Position = Graph.XlLegendPosition.xlLegendPositionBottom; objChart.HasTitle = true; objChart.ChartTitle.Text = "Here it is..."; //Build Slide #3: //Change the background color of this slide only. Add a text effect to the slide //and apply various color schemes and shadows to the text effect. objSlide = objSlides.Add(objSlides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutBlank); objSlide.FollowMasterBackground = MsoTriState.msoFalse; objShapes = objSlide.Shapes; objShape = objShapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect27, "The End", "Impact", 96, MsoTriState.msoFalse, MsoTriState.msoFalse, 230, 200); //Save the presentation to disk objPres.SaveAs(path, PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, Microsoft.Office.Core.MsoTriState.msoFalse); //Modify the slide show transition settings for all 3 slides in //the presentation. int[] SlideIdx = new int[3]; for (int k = 0; k < 3; k++) SlideIdx[k] = k + 1; objSldRng = objSlides.Range(SlideIdx); objSST = objSldRng.SlideShowTransition; objSST.AdvanceOnTime = MsoTriState.msoTrue; objSST.AdvanceTime = 3; objSST.EntryEffect = PowerPoint.PpEntryEffect.ppEffectBoxOut; //Prevent Office Assistant from displaying alert messages: // bAssistantOn = objApp.Assistant.On; // objApp.Assistant.On = false; //Run the Slide show from slides 1 thru 3. objSSS = objPres.SlideShowSettings; objSSS.StartingSlide = 1; objSSS.EndingSlide = 3; objSSS.Run(); //Wait for the slide show to end. objSSWs = objApp.SlideShowWindows; while (objSSWs.Count >= 1) System.Threading.Thread.Sleep(100); ////Reenable Office Assisant, if it was on: //if (bAssistantOn) //{ // objApp.Assistant.On = true; // objApp.Assistant.Visible = false; //} //Close the presentation without saving changes and quit PowerPoint. // objPres.Close(); // objApp.Quit(); }
public void redata(ref int s, ref List<question> questions, ref int choices_no1, ref int data_format) { float total = 0; Graph.SeriesCollection ss = questions[s].datasheet.Application.Chart().SeriesCollection(); Graph.Points kj; kj = ss.Item(1).Points(); objSlide = objPres.Slides._Index(s + 1); objShapes = objSlide.Shapes; for (int i = 2; i <= choices_no1 + 1; i++) { total = (total + questions[s].values[i - 2]); } if (data_format == 2) { for (int i = 2; i <= choices_no1 + 1; i++) { questions[s].datasheet.Cells[2, i] = questions[s].values[i - 2]; } questions[s].datasheet.Application.Chart().Refresh(); objShape2 = objShapes[4]; objShape2.TextEffect.Text = "Total" + " " + total.ToString(); } else if (data_format == 1) { for (int i = 2; i <= choices_no1 + 1; i++) { questions[s].datasheet.Cells[2, i] = (((questions[s].values[i - 2]) / total) * 100) + "%"; } } else if (data_format == 3) { for (int i = 2; i <= choices_no1 + 1; i++) { questions[s].datasheet.Cells[2, i] = questions[s].values[i - 2]; Graph.DataLabel label = ss.Item(1).DataLabels(i - 1); label.Text = (((questions[s].values[i - 2]) / total) * 100).ToString() + "%" + "[" + questions[s].values[i - 2].ToString() + "]"; } objShape2 = objShapes[4]; objShape2.TextEffect.Text = "Total" + " " + total.ToString(); } }