Shrink to fit is a useful option in Excel, it enables us to automatically reduce the font size in a cell until the text fits within the cell. This article demonstrates how to accomplish the same functionality programmatically in C# using Spire.XLS.

Below is the screenshot of the input Excel file:

Shrink Text to Fit in a Cell in Excel in C#

Detail steps:

Step 1: Instantiate a Workbook object and load the Excel file.

Workbook workbook = new Workbook();
workbook.LoadFromFile(@"Input.xlsx");

Step 2: Get the first worksheet.

Worksheet sheet = workbook.Worksheets[0];

Step 3: Specify the cell range to shrink text.

CellRange cell = sheet.Range["A1:E3"];

Step 4: Enable ShrinkToFit.

CellStyle style = cell.Style;
style.ShrinkToFit = true;

Step 5: Save the file.

workbook.SaveToFile("ShrinkTextToFitCell.xlsx", ExcelVersion.Version2013);

Output:

Shrink Text to Fit in a Cell in Excel in C#

Full code:

using Spire.Xls;
namespace ShrinkText
{
    class Program
    {

        static void Main(string[] args)
        {
            //Load the Excel file
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"Input.xlsx");

            //Get the first worksheet
            Worksheet sheet = workbook.Worksheets[0];

            //The cell range to shrink text
            CellRange cell = sheet.Range["A1:E3"];

            //Enable ShrinkToFit
            CellStyle style = cell.Style;
            style.ShrinkToFit = true;

            //Save the file
            workbook.SaveToFile("ShrinkTextToFitCell.xlsx", ExcelVersion.Version2013);
        }
    }
}

This article demonstrates how to create a chart without reference to the worksheet data range using Spire.XLS.

Detail steps:

Step 1: Create a workbook and get the first worksheet.

Workbook wb = new Workbook();            
Worksheet sheet = wb.Worksheets[0];

Step 2: Add a chart to the worksheet.

Chart chart = sheet.Charts.Add();

Step 3: Add a series to the chart.

var series = chart.Series.Add();

Step 4: Add data.

series.EnteredDirectlyValues = new object[] { 10, 20, 30 };

Step 5: Save the file.

wb.SaveToFile("result.xlsx", ExcelVersion.Version2013);

Output:

Create Chart without Using Worksheet Data Range in C#

Full code:

using Spire.Xls;

namespace Create_chart
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a workbook
            Workbook wb = new Workbook();
            
            //Get the first worksheet
            Worksheet sheet = wb.Worksheets[0];

            //Add a chart to the worksheet
            Chart chart = sheet.Charts.Add();

            //Add a series to the chart
            var series = chart.Series.Add();

            //Add data 
            series.EnteredDirectlyValues = new object[] { 10, 20, 30 };

            //Save the file
            wb.SaveToFile("result.xlsx", ExcelVersion.Version2013);
        }
    }
}

In this article, we will explain how to copy a shapes or all shapes from one slide into another within the same PowerPoint document by using Spire.Presentation.

Firstly, view the sample PowerPoint document:

C# Copy shapes between slides in PowerPoint document

Copy a single shape from the first slide to the second slide:

//Load the sample document
Presentation ppt = new Presentation();
ppt.LoadFromFile("Sample.pptx");


//define the source slide and target slide
ISlide sourceSlide = ppt.Slides[0];
ISlide targetSlide = ppt.Slides[1];

//copy the second shape from the source slide to the target slide
targetSlide.Shapes.AddShape((Shape)sourceSlide.Shapes[1]);

//save the document to file 
ppt.SaveToFile("Copyshape.pptx", FileFormat.Pptx2013);

Effective screenshot after copy a single shape from the first slide to second slide:

C# Copy shapes between slides in PowerPoint document

Copy all shapes from the first slide to the second slide:

//Load the sample document
Presentation ppt = new Presentation();
ppt.LoadFromFile("Sample.pptx");


//copy all the shapes from the source slide to the target slide
for (int i = 0; i < ppt.Slides.Count - 1; i++)
{
    ISlide sourceSlide = ppt.Slides[i];
    ISlide targetSlide = ppt.Slides[ppt.Slides.Count - 1];
    for (int j = 0; j < sourceSlide.Shapes.Count; j++)
    {
        targetSlide.Shapes.AddShape((Shape)sourceSlide.Shapes[j]);
    }
}

//save the document to file 
ppt.SaveToFile("Copyshapes.pptx", FileFormat.Pptx2013);

Effective screenshot after copy all shapes from the first slide to second slide:

C# Copy shapes between slides in PowerPoint document

Spire.PDF supports to horizontally and vertically split a PDF page into two or more pages. This article will show you how to use Spire.PDF to accomplish this function.

The sample PDF file:

Horizontally and Vertically Split a PDF Page into multiple Pages in C#

Detail steps:

Step 1: Load the sample PDF file and get the first page.

PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("New Zealand.pdf");

PdfPageBase page = pdf.Pages[0];

Step 2: Create a new PDF file and remove page margins.

PdfDocument newPdf = new PdfDocument();
newPdf.PageSettings.Margins.All = 0;

Step 3: Set page width and height in order to horizontally or vertically split the first page into 2 pages.

//Horizontally Split
newPdf.PageSettings.Width = page.Size.Width;
newPdf.PageSettings.Height = page.Size.Height / 2;
//Vertically split
//newPdf.PageSettings.Width = page.Size.Width / 2;
//newPdf.PageSettings.Height = page.Size.Height;

Step 5: Add a new page to the new PDF file.

PdfPageBase newPage = newPdf.Pages.Add();

Step 6: Create layout format.

PdfTextLayout format = new PdfTextLayout();
format.Break = PdfLayoutBreakType.FitPage;
format.Layout = PdfLayoutType.Paginate;

Step 7: Create template from the first Page of the sample PDF, and draw the template to the new added page with the layout format.

page.CreateTemplate().Draw(newPage, new PointF(0, 0), format);

Step 8: Save and close.

newPdf.SaveToFile("SplitPage.pdf");
newPdf.Close();
pdf.Close();  

Horizontally split:

Horizontally and Vertically Split a PDF Page into multiple Pages in C#

Vertically split:

Horizontally and Vertically Split a PDF Page into multiple Pages in C#

Full code:

using System.Drawing;
using Spire.Pdf;
using Spire.Pdf.Graphics;

namespace SplitPDFPage
{
    class Program
    {
        static void Main(string[] args)
        {
            //Load the sample PDF
            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile("New Zealand.pdf");

            //Get the first page
            PdfPageBase page = pdf.Pages[0];

            //Create a new PDF
            PdfDocument newPdf = new PdfDocument();

            //Remove page margins
            newPdf.PageSettings.Margins.All = 0;

            //Set page width and height in order to horizontally split the first page into 2 pages
            newPdf.PageSettings.Width = page.Size.Width;
            newPdf.PageSettings.Height = page.Size.Height / 2;

            //Set page width and height in order to vertically split the first page into 2 pages
            //newPdf.PageSettings.Width = page.Size.Width / 2;
            //newPdf.PageSettings.Height = page.Size.Height;

            //Add a new page to the new PDF
            PdfPageBase newPage = newPdf.Pages.Add();

            //Create layout format
            PdfTextLayout format = new PdfTextLayout();
            format.Break = PdfLayoutBreakType.FitPage;
            format.Layout = PdfLayoutType.Paginate;

            //Create template from the first Page of the sample PDF, and draw the template to the new added page with the layout format
            page.CreateTemplate().Draw(newPage, new PointF(0, 0), format);

            //Save and close
            newPdf.SaveToFile("SplitPage.pdf");
            newPdf.Close();
            pdf.Close();                                               
        }
    }
}

In this article, we're going to demonstrate how to draw superscript and subscript text in PDF using Spire.PDF.

Draw Superscript Text

using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;


namespace Superscript
{
    class Program
    {
        static void Main(string[] args)
        {
            //Instantiate a PdfDocument instance
            PdfDocument pdf = new PdfDocument();

            //Add a page
            PdfPageBase page = pdf.Pages.Add();

            //Set initial (x, y) coordinate
            float x = 0;
            float y = 50;

            //Set font
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial Unicode MS", 11f), true);

            //Draw string
            string text = "Sample Text";
            page.Canvas.DrawString(text, font, PdfBrushes.Black, new PointF(x, y));

            //Measure the string
            SizeF size = font.MeasureString(text);

            //Set the x coordinate of the superscript text
            x += size.Width;

            //Instantiate a PdfStringFormat instance
            PdfStringFormat format = new PdfStringFormat();
            //Set format as superscript
            format.SubSuperScript = PdfSubSuperScript.SuperScript;

            //Draw superscript text with format
            text = "Superscript";
            page.Canvas.DrawString(text, font, PdfBrushes.Black, new PointF(x, y), format);

            //Save the document
            pdf.SaveToFile("SuperScript.pdf");
        }
    }
}

Draw Superscript and Subscript Text in PDF in C#

Draw Superscript Text

using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;


namespace Subscript
{
    class Program
    {
        static void Main(string[] args)
        {
            //Instantiate a PdfDocument instance
            PdfDocument pdf = new PdfDocument();

            //Add a page
            PdfPageBase page = pdf.Pages.Add();

            //Set initial (x, y) coordinate
            float x = 0;
            float y = 50;

            //Set font
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial Unicode MS", 11f), true);

            //Draw string
            string text = "Sample Text";
            page.Canvas.DrawString(text, font, PdfBrushes.Black, new PointF(x, y));

            //Measure the string
            SizeF size = font.MeasureString(text);

            //Set the x coordinate of the subscript text
            x += size.Width;

            //Instantiate a PdfStringFormat instance
            PdfStringFormat format = new PdfStringFormat();
            //Set format as subscript
            format.SubSuperScript = PdfSubSuperScript.SubScript;

            //Draw subscript
            text = "Subscript";
            page.Canvas.DrawString(text, font, PdfBrushes.Black, new PointF(x, y), format);

            //Save the document
            pdf.SaveToFile("SubScript.pdf");
        }
    }
}

Draw Superscript and Subscript Text in PDF in C#

PostScript is a page description language that is an industry standard for outputting high-resolution text and graphics. From Version 6.11.2, Spire.Doc supports to convert doc/docx to a postscript file in both WinForm app and ASP.NET app. This article will demonstrate how to convert word to PostScript in C# and VB.NET.

Firstly, view the sample word document:

How to convert Word to PostScript in C#

[C#]
using Spire.Doc;

namespace Word
{
    class Program
    {
        static void Main(string[] args)
        {            
            Document doc = new Document();
            doc.LoadFromFile("Sample.docx", FileFormat.Docx2010);
            doc.SaveToFile("Result.ps", FileFormat.PostScript);                 
        }
    }
}
[VB.NET]
Imports Spire.Doc
Namespace Word
    Class Program
        Private Shared Sub Main(ByVal args As String())
            Dim doc As Document = New Document()
            doc.LoadFromFile("Sample.docx", FileFormat.Docx2010)
            doc.SaveToFile("Result.ps", FileFormat.PostScript)
        End Sub
    End Class
End Namespace

Effective screenshot of the resulted PostScript file converted from .docx document:

How to convert Word to PostScript in C#

A ChartSheet represents a chart sheet. It is a worksheet that contains only a chart. This article will demonstrate how to convert a chart sheet to SVG stream by using Spire.XLS.

Firstly, view the sample Excel worksheets with two chart sheets.

How to save Excel chart sheet to SVG in C#

Convert all the chart sheets to SVG stream:

using System.Drawing.Imaging;
using System.IO;
namespace Convert
{
    class Program
    {
        static void Main(string[] args)
        {
            //load the document from file
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("Sample.xlsx");

            //call ToSVGStream(Stream stream) method to save each chart sheet to SVG stream 
            for (int i = 0; i < workbook.Chartsheets.Count; i++)
            {
                FileStream fs = new FileStream(string.Format("chartsheet-{0}.svg", i), FileMode.Create);
                workbook.Chartsheets[i].ToSVGStream(fs);
                fs.Flush();
                fs.Close();
            }


        }
    }
}

Effective screenshot of the two chart sheets to SVG.

How to save Excel chart sheet to SVG in C#

using System.Drawing.Imaging;
using System.IO;
namespace Convert
{
    class Program
    {
        static void Main(string[] args)
        {
            //load the document from file
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("Sample.xlsx");

            //get the second chartsheet by name
            ChartSheet cs = workbook.GetChartSheetByName("Chart2");

            //save to SVG stream
            FileStream fs = new FileStream(string.Format("chart2.svg"), FileMode.Create);
            cs.ToSVGStream(fs);
            fs.Flush();
            fs.Close();


        }
    }
}

How to save Excel chart sheet to SVG in C#

Alternative text (alt text) can help people with screen readers understand the content of our table. This article is going to demonstrate how to add or get the alternative text of a table in a word document using Spire.Doc.

In Spire.Doc, we can set or get the alternative text of a table using the Table.Title and Table.TableDescription properties. The following example shows how to add alternative text to a table.

Detail steps:

Step 1: Instantiate a Document object and load a word document.

Document doc = new Document();
doc.LoadFromFile("Input.docx");

Step 2: Get the first section.

Section section = doc.Sections[0];

Step 3: Get the first table in the section.

Table table = section.Tables[0] as Table;

Step 4: Add alt text to the table.

//Add title
table.Title = "Table 1";
//Add description
table.TableDescription = "Description Text";

Step 5: Save the document.

doc.SaveToFile("output.docx", FileFormat.Docx2013);

Screenshot:

Add/Get Alternative Text of Table in Word in C#

Full code:

using Spire.Doc;

namespace Add_Alt_Text_To_Word_Table
{
    class Program
    {
        static void Main(string[] args)
        {
            //Instantiate a Document object
            Document doc = new Document();
            //Load a word document
            doc.LoadFromFile("Input.docx");

            //Get the first section
            Section section = doc.Sections[0];

            //Get the first table in the section
            Table table = section.Tables[0] as Table;
 
            //Add alt text

            //Add tile
            table.Title = "Table 1";
            //Add description
            table.TableDescription = "Description Text";

            //Save the document
            doc.SaveToFile("output.docx", FileFormat.Docx2013);            
        }
    }
}

We have demonstrated how to use Spire.Presentation to add and get speaker notes in presentation slides. This article will show how to remove the speaker notes in presentation slides in C#.

Firstly, view the sample document contains the speaker notes.

How to remove speaker notes from a presentation slide in C#

Step 1: Create a presentation document and load the document from the file.

Presentation ppt = new Presentation();
ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2013);

Step 2: Get the first slide from the sample document.

ISlide slide = ppt.Slides[0];

Step 3: Remove the first speak notes:

slide.NotesSlide.NotesTextFrame.Paragraphs.RemoveAt(1);

Remove all the speak notes from the first slide:

slide.NotesSlide.NotesTextFrame.Paragraphs.Clear();

Step 4: Save the document to file.

ppt.SaveToFile("Result.pptx",FileFormat.Pptx2013);

Effective screenshot of removing the first note:

How to remove speaker notes from a presentation slide in C#

Effective screenshot of removing all the notes:

How to remove speaker notes from a presentation slide in C#

Full codes:

Remove the first note in presentation slide:

using Spire.Presentation;
namespace RemoveSpeakerNotes
{

    class Program
    {

        static void Main(string[] args)
        {
            Presentation ppt = new Presentation();
            ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2013);

            ISlide slide = ppt.Slides[0];

            slide.NotesSlide.NotesTextFrame.Paragraphs.RemoveAt(1);
            ppt.SaveToFile("Result.pptx", FileFormat.Pptx2013);

        }

    }
}

Clear all notes in presentation slide:

Imports Spire.Presentation
Namespace RemoveSpeakerNotes

	Class Program

		Private Shared Sub Main(args As String())
			Dim ppt As New Presentation()
			ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2013)

			Dim slide As ISlide = ppt.Slides(0)

			slide.NotesSlide.NotesTextFrame.Paragraphs.RemoveAt(1)
			ppt.SaveToFile("Result.pptx", FileFormat.Pptx2013)

		End Sub

	End Class
End Namespace

Split Table Cells in PowerPoint in C#

2018-09-26 08:02:37 Written by Koohji

This article is going to demonstrate how to split a specific table cell in PowerPoint using Spire.Presentation.

The original table:

Split Table Cells in PowerPoint in C#

Detail steps:

Step 1: Instantiate a Presentation object and load the PowerPoint file.

Presentation ppt = new Presentation();
ppt.LoadFromFile("Input.pptx");

Step 2: Get the first slide.

ISlide slide = ppt.Slides[0];

Step 3: Get the table on the slide.

ITable table = slide.Shapes[0] as ITable;

Step 4: Split the cell [1, 2] into 3 rows and 2 columns.

table[1, 2].Split(3, 2);

Step 5: Save the file.

ppt.SaveToFile("Split.pptx", FileFormat.Pptx2013);

Screenshot after splitting:

Split Table Cells in PowerPoint in C#

Full code:

using Spire.Presentation;

namespace Split_Table_Cells_in_PPT
{
    class Program
    {
        static void Main(string[] args)
        {
            //Instantiate a Presentation object
            Presentation ppt = new Presentation();
            //Load the PowerPoint file
            ppt.LoadFromFile("Input.pptx");

            //Get the first slide
            ISlide slide = ppt.Slides[0];

            //Get the table
            ITable table = slide.Shapes[0] as ITable;

            //Split cell [1, 2] into 3 rows and 2 columns
            table[1, 2].Split(3, 2);

            //Save the file
            ppt.SaveToFile("Split.pptx", FileFormat.Pptx2013);
        }
    }
}
page 14