Set the outline and effects for shapes in PowerPoint files via Spire.Presentation
Outline and effects for shapes can make the presentation of your PowerPoint files more attractive. This article talks about how to set the outline and effects for shapes via Spire.Presentation.
Step 1: Create a PowerPoint document.
Presentation ppt = new Presentation();
Step 2: Get the first slide
ISlide slide = ppt.Slides[0];
Step 3: Draw Rectangle shape on slide[0] with methord AppendShape();
IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 100, 100, 50));
Step 4: Set outline color as red.
//Outline color shape.ShapeStyle.LineColor.Color = Color.Red;
Step 5: Add shadow effect and set parameters for it.
//Effect PresetShadow shadow = new PresetShadow(); shadow.Preset = PresetShadowValue.FrontRightPerspective; shadow.Distance = 10.0; shadow.Direction = 225.0f; shape.EffectDag.PresetShadowEffect = shadow;
Step 6: Change a Ellipse to add yellow outline with a glow effect:
Change step 4 and 5 as Code:
shape = slide.Shapes.AppendShape(ShapeType.Ellipse, new RectangleF(200, 100, 100, 100)); //Outline color shape.ShapeStyle.LineColor.Color = Color.Yellow; //Effect GlowEffect glow = new GlowEffect(); glow.ColorFormat.Color = Color.Purple; glow.Radius = 20.0; shape.EffectDag.GlowEffect = glow;
Step 7: Save and review.
ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010); System.Diagnostics.Process.Start("Sample.PPTx");
Here is the screen shot:
Duplicate a Page within a PDF Document in C#/VB.NET
In some circumstance where we need to create a copy of the existing pages in our PDF document instead of copying the entire file, in particular, if we have to create hundreds copies of a certain page, it can be tedious to copy the page one after another. This article demonstrates a solution for how to duplicate a page in a PDF document and create multiple copies at a time using Spire.PDF.
In this example, I prepare a sample PDF file that only contains one page and eventually I’ll create ten copies of this page in the same document. Main method would be as follows:
Code Snippet:
Step 1: Create a new PDF document and load the sample file.
PdfDocument pdf = new PdfDocument("Sample.pdf");
Step 2: Get the first page from PDF, get the size of the page. Create a new instance of Pdf Template object based on the content and appearance of the first page.
PdfPageBase page = pdf.Pages[0]; SizeF size = page.Size; PdfTemplate template = page.CreateTemplate();
Step 3: Create a new PDF page with the method Pages.Add() based on the size of the first page, draw the template on the new page at the specified location. Use a for loops to get more copies of this page.
for (int i = 0; i < 10; i++) { page = pdf.Pages.Add(size, new PdfMargins(0)); page.Canvas.DrawTemplate(template, new PointF(0, 0)); }
Step 4: Save the file.
pdf.SaveToFile("Result.pdf");
Output:
Ten copies of the first page have been created in the sample PDF document.
Full Code:
using Spire.Pdf; using Spire.Pdf.Graphics; using System.Drawing; namespace DuplicatePage { class Program { static void Main(string[] args) { PdfDocument pdf = new PdfDocument("Sample.pdf"); PdfPageBase page = pdf.Pages[0]; SizeF size = page.Size; PdfTemplate template = page.CreateTemplate(); for (int i = 0; i < 10; i++) { page = pdf.Pages.Add(size, new PdfMargins(0)); page.Canvas.DrawTemplate(template, new PointF(0, 0)); } pdf.SaveToFile("Result.pdf"); } } }
Imports Spire.Pdf Imports Spire.Pdf.Graphics Imports System.Drawing Namespace DuplicatePage Class Program Private Shared Sub Main(args As String()) Dim pdf As New PdfDocument("Sample.pdf") Dim page As PdfPageBase = pdf.Pages(0) Dim size As SizeF = page.Size Dim template As PdfTemplate = page.CreateTemplate() For i As Integer = 0 To 9 page = pdf.Pages.Add(size, New PdfMargins(0)) page.Canvas.DrawTemplate(template, New PointF(0, 0)) Next pdf.SaveToFile("Result.pdf") End Sub End Class End Namespace
How to Apply Conditional Formatting to a Data Range in C#
Conditional formatting in Microsoft Excel has a number of presets that enables users to apply predefined formatting such as colors, icons and data bars, to a range of cells based on the value of the cell or the value of a formula. Conditional formatting usually reveals the data trends or highlights the data that meets one or more formulas.
In this article, I made an example to explain how these conditional formatting types can be achieved programmatically using Spire.XLS in C#. First of all, let's see the worksheet that contains a group of data in selected range as below, we’d like see which cells’ value is bigger than 800. In order to quickly figure out similar things like this, we can create a conditional formatting rule by formula: “If the value is bigger than 800, color the cell with Red” to highlight the qualified cells.
Code Snippet for Creating Conditional Formatting Rules:
Step 1: Create a worksheet and insert data to cell range from A1 to C4.
Workbook workbook = new Workbook(); Worksheet sheet = workbook.Worksheets[0]; sheet.Range["A1"].NumberValue = 582; sheet.Range["A2"].NumberValue = 234; sheet.Range["A3"].NumberValue = 314; sheet.Range["A4"].NumberValue = 50; sheet.Range["B1"].NumberValue = 150; sheet.Range["B2"].NumberValue = 894; sheet.Range["B3"].NumberValue = 560; sheet.Range["B4"].NumberValue = 900; sheet.Range["C1"].NumberValue = 134; sheet.Range["C2"].NumberValue = 700; sheet.Range["C3"].NumberValue = 920; sheet.Range["C4"].NumberValue = 450; sheet.AllocatedRange.RowHeight = 15; sheet.AllocatedRange.ColumnWidth = 17;
Step 2: Create one conditional formatting rule to highlight cells that are greater than 800, and another rule that enables to highlight cells lesser than 300. In our program, the rule is represented by formula. As is shown in the code below, we firstly initialize a new instance of ConditionalFormatWrapper class and apply the format1 to selected cell range. Then define the format1 by setting the related properties. The FirstFormula and Operater property allow us to find out which cells are greater than 800; the Color property enables to color the cells we find. Repeat this method to create format2 to get the cells under 300 highlighted.
ConditionalFormatWrapper format1 = sheet.AllocatedRange.ConditionalFormats.AddCondition(); format1.FormatType = ConditionalFormatType.CellValue; format1.FirstFormula = "800"; format1.Operator = ComparisonOperatorType.Greater; format1.FontColor = Color.Red; format1.BackColor = Color.LightSalmon; ConditionalFormatWrapper format2 = sheet.AllocatedRange.ConditionalFormats.AddCondition(); format2.FormatType = ConditionalFormatType.CellValue; format2.FirstFormula = "300"; format2.Operator = ComparisonOperatorType.Less; format2.FontColor = Color.Green; format2.BackColor = Color.LightBlue;
Step 3: Save and launch the file
workbook.SaveToFile("sample.xlsx", ExcelVersion.Version2010); System.Diagnostics.Process.Start("sample.xlsx");
Result:
The cells with value bigger than 800 and smaller than 300, have been highlighted with defined text color and background color.
Apply the Other Three Conditional Formatting Types:
Spire.XLS also supports applying some other conditional formatting types which were predefined in MS Excel. Use the following code snippets to get more formatting effects.
Apply Data Bars:
ConditionalFormatWrapper format = sheet.AllocatedRange.ConditionalFormats.AddCondition(); format.FormatType = ConditionalFormatType.DataBar; format.DataBar.BarColor = Color.CadetBlue;
Apply Icon Sets:
ConditionalFormatWrapper format = sheet.AllocatedRange.ConditionalFormats.AddCondition(); format.FormatType = ConditionalFormatType.IconSet;
Apply Color Scales:
ConditionalFormatWrapper format = sheet.AllocatedRange.ConditionalFormats.AddCondition(); format.FormatType = ConditionalFormatType.ColorScale;
Full Code:
using Spire.Xls; using System.Drawing; namespace ApplyConditionalFormatting { class Program { static void Main(string[] args) { { Workbook workbook = new Workbook(); Worksheet sheet = workbook.Worksheets[0]; sheet.Range["A1"].NumberValue = 582; sheet.Range["A2"].NumberValue = 234; sheet.Range["A3"].NumberValue = 314; sheet.Range["A4"].NumberValue = 50; sheet.Range["B1"].NumberValue = 150; sheet.Range["B2"].NumberValue = 894; sheet.Range["B3"].NumberValue = 560; sheet.Range["B4"].NumberValue = 900; sheet.Range["C1"].NumberValue = 134; sheet.Range["C2"].NumberValue = 700; sheet.Range["C3"].NumberValue = 920; sheet.Range["C4"].NumberValue = 450; sheet.AllocatedRange.RowHeight = 15; sheet.AllocatedRange.ColumnWidth = 17; //create conditional formatting rule ConditionalFormatWrapper format1 = sheet.AllocatedRange.ConditionalFormats.AddCondition(); format1.FormatType = ConditionalFormatType.CellValue; format1.FirstFormula = "800"; format1.Operator = ComparisonOperatorType.Greater; format1.FontColor = Color.Red; format1.BackColor = Color.LightSalmon; ConditionalFormatWrapper format2 = sheet.AllocatedRange.ConditionalFormats.AddCondition(); format2.FormatType = ConditionalFormatType.CellValue; format2.FirstFormula = "300"; format2.Operator = ComparisonOperatorType.Less; format2.FontColor = Color.Green; format2.BackColor = Color.LightBlue; ////add data bars //ConditionalFormatWrapper format = sheet.AllocatedRange.ConditionalFormats.AddCondition(); //format.FormatType = ConditionalFormatType.DataBar; //format.DataBar.BarColor = Color.CadetBlue; ////add icon sets //ConditionalFormatWrapper format = sheet.AllocatedRange.ConditionalFormats.AddCondition(); //format.FormatType = ConditionalFormatType.IconSet; ////add color scales //ConditionalFormatWrapper format = sheet.AllocatedRange.ConditionalFormats.AddCondition(); //format.FormatType = ConditionalFormatType.ColorScale; workbook.SaveToFile("sample.xlsx", ExcelVersion.Version2010); System.Diagnostics.Process.Start("sample.xlsx"); } } } }
How to remove the hyperlink on a slide in the presentation
In the previous topic, we discussed about how to insert hyperlink into PowerPoint presentation. In this topic, we will show you how to remove the hyperlink on a slide in the presentation by using the Spire.Presentation in C#.
Firstly, view the hyperlinks on a slide that we need to remove later.
Here comes to the steps of how to remove the hyperlinks in the PowerPoint presentation in C#.
Step 1: Create Presentation instance and load file.
Presentation ppt = new Presentation(); ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2010);
Step 2: Get the shape and its text with hyperlink.
IAutoShape shape = ppt.Slides[0].Shapes[1] as IAutoShape;
Step 3: Set the ClickAction property into null to remove the hyperlink.
shape.TextFrame.TextRange.ClickAction = null;
Step 4: Save the document to file.
ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010);
Effective screenshot after removing the first hyperlink:
Full codes:
using Spire.Presentation; namespace RemoveHyperlink { class Program { static void Main(string[] args) { Presentation ppt = new Presentation(); ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2010); IAutoShape shape = ppt.Slides[0].Shapes[1] as IAutoShape; shape.TextFrame.TextRange.ClickAction = null; ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010); } } }
How to add an image in Table Cell via Spire.Presentation
Adding an image in table cell can make your PPT files more different. Spire.Presentation allows developers add images to table cells. Here we introduce an example to add an image to a table cell in PPT.
Step 1: Create a new PPT document instance.
Presentation presentation = new Presentation();
Step 2: Call AppendTable() method to create a table and set the table style.
ISlide slide = presentation.Slides[0]; Double[] widths = new double[] { 100, 100}; Double[] heights = new double[] { 100, 100}; ITable table = presentation.Slides[0].Shapes.AppendTable(100, 80, widths, heights); table.StylePreset = TableStylePreset.LightStyle1Accent2;
Step 3: Use table[0, 0].FillFormat.PictureFill.Picture.EmbedImage to embed the image to the cell. The FillType can be changed.
IImageData imgData = presentation.Images.Append(Image.FromFile("1.jpg")); table[0, 0].FillFormat.FillType = FillFormatType.Picture; table[0, 0].FillFormat.PictureFill.Picture.EmbedImage = imgData; table[0, 0].FillFormat.PictureFill.FillType = PictureFillType.Stretch;
Step 4: Save and review.
presentation.SaveToFile("table.pptx", FileFormat.Pptx2010); System.Diagnostics.Process.Start("table.pptx");
Here is the screenshot:
How to set the layout of the slide in .NET
Layout of PPT concerns visual effect directly. PPT Viewer may have different feelings and thoughts such as tense, confused or anxious about different layouts. We can make our PPT files show main information and weaken minor information. This article will show how to set the layout for your slide via Spire.Presentation. Here are the steps:
Step 1: Create a PPT document.
Presentation ppt = new Presentation();
Step2: Set the layout for slide. Spire.Presentation offers 11 kinds of layout just as Microsoft PowerPoint supports.
ISlide slide = ppt.Slides.Append(SlideLayoutType.Title);
Step 3: Add content for Title and Text.
IAutoShape shape = slide.Shapes[0] as IAutoShape; shape.TextFrame.Text = "Hello Wolrd! –> This is title"; shape = slide.Shapes[1] as IAutoShape; shape.TextFrame.Text = "E-iceblue Support Team -> This is content";
Step 4: Save and review.
ppt.SaveToFile("Result.PPTx", FileFormat.PPTx2010); System.Diagnostics.Process.Start("Result.PPTx");
Here is the result:
Then change another layout (Picture With Caption) to show: PictureAndCaption
Use function AppendEmbedImage to add image, and notice the order of the shape in PictureAndCaption is Shapes[1], Shapes[0] and Shapes[2].
Full code:
using Spire.Presentation; namespace SetLayout { class Program { static void Main(string[] args) { Presentation ppt = new Presentation(); ISlide slide = ppt.Slides.Append(SlideLayoutType.PictureAndCaption); string ImageFile2 = "1.jpg"; IAutoShape shape0 = slide.Shapes[1] as IAutoShape; slide.Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile2, shape0.Frame.Rectangle); IAutoShape shape = slide.Shapes[0] as IAutoShape; shape.TextFrame.Text = "Title - Cattle back mountain"; IAutoShape shape2 = slide.Shapes[2] as IAutoShape; shape2.TextFrame.Text = " Text content - Got name because it's slender ridge seems cow back"; ppt.SaveToFile("Sample.pptx", FileFormat.Pptx2010); System.Diagnostics.Process.Start("Sample.PPTx"); } } }
Result:
C#/VB.NET: Extract Attachments from PDF
PDF attachments allow users to see more details on a particular point by visiting attachments inside the PDF. Basically, there are two types of attachments in PDF: document level attachment and annotation attachment. Below are the differences between them.
- Document Level Attachment (represented by PdfAttachment class): A file attached to a PDF at the document level won't appear on a page, but only appear in the PDF reader's "Attachments" panel.
- Annotation Attachment (represented by PdfAttachmentAnnotation class): A file that is attached to a specific position of a page. Annotation attachments are shown as a paper clip icon on the page; reviewers can double-click the icon to open the file.
In this article, you will learn how to extract these two kinds of attachments from a PDF document in C# and VB.NET using Spire.PDF for .NET.
Install Spire.PDF for .NET
To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.PDF
Extract Attachments from PDF in C# and VB.NET
The document level attachments of a PDF document can be obtained through PdfDocument.Attachments property. The following steps illustrate how to extract all document level attachments from a PDF document and save them to a local folder.
- Create a PdfDocument object.
- Load a PDF file using PdfDocument.LoadFromFile() method.
- Get the attachment collection from the document through PdfDocument.Attachments property.
- Get the data of a specific attachment through PdfAttachment.Data property.
- Write the data to a file and save to a specified folder.
- C#
- VB.NET
using Spire.Pdf; using Spire.Pdf.Attachments; using System.Net.Mail; namespace ExtractAttachments { class Program { static void Main(string[] args) { //Create a PdfDocument object PdfDocument doc = new PdfDocument(); //Load a PDF file that contains attachments doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Attachments.pdf"); //Get the attachment collection of the PDF document PdfAttachmentCollection attachments = doc.Attachments; //Specific output folder path string outputFolder = "C:\\Users\\Administrator\\Desktop\\output\\"; //Loop through the collection for (int i = 0; i < attachments.Count; i++) { //Write attachment to a file File.WriteAllBytes(outputFolder + attachments[i].FileName, attachments[i].Data); } } } }
Extract Annotation Attachments from PDF in C# and VB.NET
Annotation attachment is a page-based element. To get annotations from a specific page, use PdfPageBase.AnnotationsWidget property. After that, you’ll need to determine if a specific annotation is an annotation attachment. The follows are the steps to extract annotation attachments from a PDF document and save them to a local folder.
- Create a PdfDocument object.
- Load a PDF file using PdfDocument.LoadFromFile() method.
- Get a specific page from the document through PdfDocument.Pages[] property.
- Get the annotation collection from the page through PdfPageBase.AnnotationsWidget property.
- Determine if a specific annotation is an instance of PdfAttachmentAnnotationWidget. If yes, write the annotation attachment to a file and save it to a specified folder.
- C#
- VB.NET
using Spire.Pdf; using Spire.Pdf.Annotations; namespace ExtractAnnotationAttachments { class Program { static void Main(string[] args) { //Create a PdfDocument object PdfDocument doc = new PdfDocument(); //Load a PDF file that contains attachments doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\AnnotationAttachments.pdf"); //Specific output folder path string outputFolder = "C:\\Users\\Administrator\\Desktop\\Output\\"; //Loop through the pages for (int i = 0; i < doc.Pages.Count; i++) { //Get the annotation collection PdfAnnotationCollection collection = doc.Pages[i].AnnotationsWidget; //Loop through the annotations for (int j = 0; j < collection.Count; j++) { //Determine if an annotation is an instance of PdfAttachmentAnnotationWidget if (collection[j] is PdfAttachmentAnnotationWidget) { //Write annotation attachment to a file PdfAttachmentAnnotationWidget attachmentAnnotation = (PdfAttachmentAnnotationWidget)collection[j]; String fileName = Path.GetFileName(attachmentAnnotation.FileName); File.WriteAllBytes(outputFolder + fileName, attachmentAnnotation.Data); } } } } } }
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
Remove Textbox from PowerPoint Files
As a powerful and easy to use .NET component, Spire.Presentation enable developers to generate, modify, convert, render, and print documents without installing Microsoft PowerPoint. In this article let's see how to remove textbox.
Make sure Spire.Presentation for .NET has been installed correctly and then add Spire.Presentation.dll as reference in the downloaded Bin folder through the below path, for example .NET 4.0 : "..\Spire.Presentation\Bin\NET4.0\ Spire. Presentation.dll". Here comes to the details of how to remove textbox from PPT files:
Step 1: Create a PPT document and load sample PPT file. In this sample file three textboxes are added by order with their name number.
Presentation ppt = new Presentation("Sample.pptx", FileFormat.Pptx2010);
Step 2: Traverse all the shapes in Slide[0], then remove them as long as they were found.
ISlide slide = ppt.Slides[0]; for (int i = 0; i < slide.Shapes.Count;) { IAutoShape shape = slide.Shapes[i] as IAutoShape; slide.Shapes.Remove(shape); }
Step 3: Save the document as "Result.pptx" and review.
ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010); System.Diagnostics.Process.Start("Result.pptx");
The result is just as we thought.
If we need to delete textbox1, just remove the first shape. Check if this shape is textbox and its contents is “Textbox1” and then remove it, modify Step2 as:
ISlide slide = ppt.Slides[0]; for (int i = 0; i < slide.Shapes.Count; ) { IAutoShape shape = slide.Shapes[i] as IAutoShape; if (shape.IsTextBox ||shape.TextFrame.Text.Equals("Textbox1")) { slide.Shapes.Remove(shape); } }
Here is the result:
Full Code:
using Spire.Presentation; namespace RemoveText { class Program { static void Main(string[] args) { Presentation ppt = new Presentation("Sample.pptx", FileFormat.Pptx2010); ISlide slide = ppt.Slides[0]; for (int i = 0; i < slide.Shapes.Count; ) { IAutoShape shape = slide.Shapes[0] as IAutoShape; slide.Shapes.Remove(shape); } ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010); System.Diagnostics.Process.Start("Result.pptx"); } } }
Remove Textbox1:
using Spire.Presentation; namespace RemoveText { class Program { static void Main(string[] args) { Presentation ppt = new Presentation("Sample.pptx", FileFormat.Pptx2010); ISlide slide = ppt.Slides[0]; for (int i = 0; i < slide.Shapes.Count; ) { IAutoShape shape = slide.Shapes[i] as IAutoShape; if (shape.IsTextBox || shape.TextFrame.Text.Equals("Textbox1")) { slide.Shapes.Remove(shape); } } ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010); System.Diagnostics.Process.Start("Result.pptx"); } }
How to Convert Embedded Excel Sheet to Word Table in C#, VB.NET
In our daily work, we may receive Word documents that will sometimes contain embedded Excel object (sheet) and we need to convert embedded Excel sheet to Word table so that we can easily change the date or format the table with style. In this article, you will learn how to convert embedded Excel sheet to Word table using Spire.Doc and Spire.XLS in C#, VB.NET.
Firstly, you need to download Spire.Office because Spire.Doc and Spire.XLS will be used in the same program. Add Spire.Doc.dll and Spire.XLS.dll as references in your VS project. Then follow the program guidance below to finish this work.
Step 1: Create a new Word document, load the sample file. Get the paragraph that contains the Excel object from the section. Initialize a new datatable.
Document doc = new Document("Sample.docx", Spire.Doc.FileFormat.Docx2010); Section section = doc.Sections[0]; Paragraph para = section.Paragraphs[2]; DataTable dt = new DataTable();
Step 2: Traverse every DocumentObject in the paragraph, use IF statement to test if DocumentObject is OLE object, use another IF statement to test if OLE object type is Excel.Sheet.12. If yes, save the data of OLE object to a workbook through LoadFromStrem(). Then export data from worksheet to datatable.
foreach (DocumentObject obj in para.ChildObjects) { if (DocumentObjectType.OleObject == obj.DocumentObjectType) { DocOleObject dObj = obj as DocOleObject; if (dObj.ObjectType == "Excel.Sheet.12") { Workbook wb = new Workbook(); wb.LoadFromStream(new MemoryStream(dObj.NativeData)); Worksheet ws = wb.Worksheets[0]; dt = ws.ExportDataTable(ws.AllocatedRange, false); } } }
Step 3: Create a new Word table and set row number and column number according to rows and columns of datatable. Export data from datatable to Word table.
Table table = section.AddTable(true); table.ResetCells(dt.Rows.Count, dt.Columns.Count); for (int i = 0; i < dt.Rows.Count; i++) { for (int j = 0; j < dt.Columns.Count; j++) { string text = dt.Rows[i][j] as string; table.Rows[i].Cells[j].AddParagraph().AppendText(text); } }
Step 4: Save the file.
doc.SaveToFile("Result.docx", Spire.Doc.FileFormat.Docx2010);
Result:
Full Code:
using Spire.Doc; using Spire.Doc.Documents; using Spire.Doc.Fields; using Spire.Xls; using System.Data; using System.IO; namespace ApplyTableStyles { class Program { static void Main(string[] args) { Document doc = new Document("Sample.docx", Spire.Doc.FileFormat.Docx2010); Section section = doc.Sections[0]; Paragraph para = section.Paragraphs[2]; DataTable dt = new DataTable(); foreach (DocumentObject obj in para.ChildObjects) { if (DocumentObjectType.OleObject == obj.DocumentObjectType) { DocOleObject dObj = obj as DocOleObject; if (dObj.ObjectType == "Excel.Sheet.12") { Workbook wb = new Workbook(); wb.LoadFromStream(new MemoryStream(dObj.NativeData)); Worksheet ws = wb.Worksheets[0]; dt = ws.ExportDataTable(ws.AllocatedRange, false); } } } Table table = section.AddTable(true); table.ResetCells(dt.Rows.Count, dt.Columns.Count); for (int i = 0; i < dt.Rows.Count; i++) { for (int j = 0; j < dt.Columns.Count; j++) { string text = dt.Rows[i][j] as string; table.Rows[i].Cells[j].AddParagraph().AppendText(text); } } doc.SaveToFile("Result.docx", Spire.Doc.FileFormat.Docx2010); } } }
Imports Spire.Doc Imports Spire.Doc.Documents Imports Spire.Doc.Fields Imports Spire.Xls Imports System.Data Imports System.IO Namespace ApplyTableStyles Class Program Private Shared Sub Main(args As String()) Dim doc As New Document("Sample.docx", Spire.Doc.FileFormat.Docx2010) Dim section As Section = doc.Sections(0) Dim para As Paragraph = section.Paragraphs(2) Dim dt As New DataTable() For Each obj As DocumentObject In para.ChildObjects If DocumentObjectType.OleObject = obj.DocumentObjectType Then Dim dObj As DocOleObject = TryCast(obj, DocOleObject) If dObj.ObjectType = "Excel.Sheet.12" Then Dim wb As New Workbook() wb.LoadFromStream(New MemoryStream(dObj.NativeData)) Dim ws As Worksheet = wb.Worksheets(0) dt = ws.ExportDataTable(ws.AllocatedRange, False) End If End If Next Dim table As Table = section.AddTable(True) table.ResetCells(dt.Rows.Count, dt.Columns.Count) For i As Integer = 0 To dt.Rows.Count - 1 For j As Integer = 0 To dt.Columns.Count - 1 Dim text As String = TryCast(dt.Rows(i)(j), String) table.Rows(i).Cells(j).AddParagraph().AppendText(text) Next Next doc.SaveToFile("Result.docx", Spire.Doc.FileFormat.Docx2010) End Sub End Class End Namespace
C#/VB.NET: Add, Read or Delete Speaker Notes in PowerPoint
Speaker notes in PowerPoint are specific contents that appear only on the presenter's monitor when presenting the slideshow. They can remind the presenter of the important points that he needs to explain to the audience. In this article, we will demonstrate how to add, read or delete speaker notes in PowerPoint in C# and VB.NET using Spire.Presentation for .NET.
Install Spire.Presentation for .NET
To begin with, you need to add the DLL files included in the Spire.Presentation for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.Presentation
Add Speaker Notes in PowerPoint in C# and VB.NET
The following are the main steps to add speaker notes to a PowerPoint document:
- Create a Presentation instance and load a PowerPoint document using Presentation.LoadFromFile() method.
- Get the desired slide that you want to add speaker notes to through Presentation.Slides[slideIndex] property.
- Add a notes slide to the slide using ISlide.AddNotesSlides() method.
- Create a TextParagraph instance.
- Set text for the paragraph through TextParagraph.Text property, then append the paragraph to the notes slide using NotesSlide.NotesTextFrame.Paragraphs.Append() method.
- Save the result document using Presentation.SaveToFile() method.
- C#
- VB.NET
using Spire.Presentation; namespace AddSpeakerNotes { internal class Program { static void Main(string[] args) { //Load a PowerPoint document Presentation ppt = new Presentation(); ppt.LoadFromFile("Sample.pptx"); //Get the first slide ISlide slide = ppt.Slides[0]; //Add a notes slide NotesSlide notesSlide = slide.AddNotesSlide(); //Add a paragraph to the notes slide TextParagraph paragraph = new TextParagraph(); paragraph.Text = "Tips for making effective presentations:"; notesSlide.NotesTextFrame.Paragraphs.Append(paragraph); //Add a paragraph to the notes slide paragraph = new TextParagraph(); paragraph.Text = "Use the slide master feature to create a consistent and simple design template."; notesSlide.NotesTextFrame.Paragraphs.Append(paragraph); //Add a paragraph to the notes slide paragraph = new TextParagraph(); paragraph.Text = "Simplify and limit the number of words on each screen."; notesSlide.NotesTextFrame.Paragraphs.Append(paragraph); //Add a paragraph to the notes slide paragraph = new TextParagraph(); paragraph.Text = "Use contrasting colors for text and background."; notesSlide.NotesTextFrame.Paragraphs.Append(paragraph); //Set the bullet type and bullet style for specific paragraphs on the notes slide for (int i = 2; i < notesSlide.NotesTextFrame.Paragraphs.Count;i++) { notesSlide.NotesTextFrame.Paragraphs[i].BulletType = TextBulletType.Numbered; notesSlide.NotesTextFrame.Paragraphs[i].BulletStyle = NumberedBulletStyle.BulletArabicPeriod; } //Save the result document ppt.SaveToFile("SpeakerNotes.pptx", FileFormat.Pptx2013); } } }
Read Speaker Notes in PowerPoint in C# and VB.NET
The following are the steps to read the speaker notes on a PowerPoint slide:
- Create a Presentation instance and load the PowerPoint document using Presentation.LoadFromFile() method.
- Get the desired slide that you want to read speaker notes from through Presentation.Slides[slideIndex] property.
- Get the notes slide from the slide through ISlide.NotesSlide property.
- Get the speaker notes from the notes slide through NotesSlide.NotesTextFrame.Text property.
- Create a StringBuilder instance.
- Append the speaker notes to the string builder, then write them into a .txt file.
- C#
- VB.NET
using Spire.Presentation; using System.Text; using System.IO; namespace ReadSpeakerNotes { internal class Program { static void Main(string[] args) { //Load the PowerPoint document Presentation ppt = new Presentation(); ppt.LoadFromFile("SpeakerNotes.pptx"); //Get the first slide ISlide slide = ppt.Slides[0]; //Get the notes slide from the first slide NotesSlide notesSlide = slide.NotesSlide; //Get the speaker notes from the notes slide string notes = notesSlide.NotesTextFrame.Text; //Create a StringBuilder instance StringBuilder sb = new StringBuilder(); //Append the speaker notes to the string builder sb.AppendLine(notes); //Save to .txt file File.WriteAllText("SpeakerNotes.txt", sb.ToString()); } } }
Delete Speaker Notes in PowerPoint in C# and VB.NET
The following are the steps to delete speaker notes from a PowerPoint slide:
- Create a Presentation instance and load the PowerPoint document using Presentation.LoadFromFile() method.
- Get the desired slide that you want to delete speaker notes from through Presentation.Slides[slideIndex] property.
- Get the notes slide from the slide through ISlide.NotesSlide property.
- Delete a specific speaker note from the notes slide using NotesSlide.NotesTextFrame.Paragraphs.RemoveAt(paragraphIndex) method or delete all the speaker notes from the notes slide using NotesSlide.NotesTextFrame.Paragraphs.Clear() method.
- Save the result document using Presentation.SaveToFile() method.
- C#
- VB.NET
using Spire.Presentation; using System.Text; using System.IO; namespace DeleteSpeakerNotes { internal class Program { static void Main(string[] args) { //Load the PowerPoint document Presentation ppt = new Presentation(); ppt.LoadFromFile("SpeakerNotes.pptx"); //Get the first slide ISlide slide = ppt.Slides[0]; //Get the notes slide from the slide NotesSlide notesSlide = slide.NotesSlide; //Remove a specific speaker note from notes slide //notesSlide.NotesTextFrame.Paragraphs.RemoveAt(1); //Remove all the speaker notes from notes slide notesSlide.NotesTextFrame.Paragraphs.Clear(); //Save the result document ppt.SaveToFile("DeleteSpeakerNotes.pptx", FileFormat.Pptx2013); } } }
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.