With Spire.XLS, developers can add text or image to the textbox to Excel worksheet easily. From version 9.3.10, Spire.XLS supports to set the inner margin of contents on Excel text box. With this feature, we can adjust the position of the text contents on the textbox to make it beautiful. This article is going to introduce how to set the inner margins of the textbox in Excel worksheet in C#.

using Spire.Xls;
using Spire.Xls.Core.Spreadsheet.Shapes;
namespace SetInternalMargin
{
    class Program
    {
        static void Main(string[] args)
        {
            {

                //load the sample document
                Workbook workbook = new Workbook();
                workbook.LoadFromFile("Sample.xlsx", ExcelVersion.Version2010);

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

                //add a textbox to the sheet and set its position and size
                XlsTextBoxShape textbox = sheet.TextBoxes.AddTextBox(4, 2, 100, 300) as XlsTextBoxShape;

                //set the text on the textbox
                textbox.Text = "Insert TextBox in Excel and set the margin for the text";
                textbox.HAlignment = CommentHAlignType.Center;
                textbox.VAlignment = CommentVAlignType.Center;

                //set the inner margins of the contents 
                textbox.InnerLeftMargin = 1;
                textbox.InnerRightMargin = 3;
                textbox.InnerTopMargin = 1;
                textbox.InnerBottomMargin = 1;

                //save the document to file
                workbook.SaveToFile("Result.xlsx", ExcelVersion.Version2010);

            }

        }
    }
}

Effective screenshot after setting the margins of the contents:

Set the internal margin of excel textbox in C#

Get Cell Type in Excel in C#

2025-04-23 06:35:00 Written by Koohji

When working with Excel files programmatically in C#, determining the data type of a cell is critical for accurate data processing. Whether you're validating user inputs, parsing spreadsheets, or migrating data, knowing how to get the cell data types ensures your application handles information correctly.

In this guide, you'll learn how to use Spire.XLS for .NET library to check the cell data types in Excel in C#, covering the following aspects:

Install the .NET Excel Library

Before proceeding, you need to have the Spire.XLS for .NET library installed in your project. A recommended way to install it is via NuGet, and there are two available options:

  • 1.Right-click the project in “Solution Explorer -> Manage NuGet Packages”. Search for “Spire.XLS” and install the latest version.
  • 2.Go to “Tools -> NuGet Package Manager -> Package Manager Console”, and then run the following command:
    PM> Install-Package Spire.XLS

Alternatively, you can download the library from this link and manually add the DLL files as references.

Learn the Cell Data Types in Spire.XLS

Spire.XLS provides the XlsWorksheet.TRangeValueType enumeration to represents the cell value types. It includes following members:

Cell Type Description
String Represents the cells that store alphanumeric characters, including numbers stored as text.
Number Represents the cells that contain numeric value, including integers, decimals, scientific notation, and date-time values.
Formula Represents the cells that contain a formula.
Blank Represents the cells contain no data.
Boolean Represents the cells that contain TRUE or FALSE.
Error Represents the cells may display errors as #VALUE! or #N/A due to invalid operations.

How to Get Cell Data Type in Excel in C#

To check the value type of a cell, you need to follow the below steps.

  • Create a Workbook object.
  • Load an XLS or XLSX Excel file, and then get a specified worksheet within it.
  • Get a specified cell range in the sheet though the Worksheet.Range[] property.
  • Iterate through each cell in the cell range.
  • Get the row number and column number of the current cell.
  • Call the Worksheet.GetCellType(int row, int column, bool bNeedFormulaSubType) method to get the value type of the current cell, and return a specific enumeration member of the XlsWorksheet.TRangeValueType enumeration type.
  • Converts the value of the enumeration member to its corresponding text string.
  • Write the text string to another cell and set its font style.
  • Save the result file using the Workbook.SaveToFile() method.
  • Sample C# Code
using System.Drawing;
using Spire.Xls;
using Spire.Xls.Core.Spreadsheet;

namespace GetCellType
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a Workbook object
            Workbook workbook = new Workbook();
            // Load an Excel file
            workbook.LoadFromFile("Test1.xlsx");

            // Get the first worksheet
            Worksheet sheet = workbook.Worksheets[0];
            // Get a specified cell range
            CellRange range = sheet.Range["A2:A8"];

            // Iterate through all cells in the range
            foreach (CellRange cell in range)
            {
                // Get the row number and column number of the current cell
                int row = cell.Row;
                int column = cell.Column;

                // Get the value type of the current cell
                XlsWorksheet.TRangeValueType cellType = sheet.GetCellType(row, column, false);

                // Convert the cell type value to a text string and write to another cell
                sheet[row, column + 1].Text = cellType.ToString();

                // Set the font style of the output cell
                sheet[row, column + 1].Style.Font.Color = Color.Red;
                sheet[row, column + 1].Style.Font.IsBold = true;
            }

            // Save the result file
            workbook.SaveToFile("GetCellType.xlsx", ExcelVersion.Version2016);
        }
    }
}

A screenshot of the result file:

Get or retrieve the cell data types in an Excel worksheet

Conclusion

Spire.XLS simplifies checking Excel cell data types in C# with its intuitive API. By leveraging the GetCellType() method, you can accurately determine whether a cell contains a number, string, boolean, etc. This approach ensures robust data processing for applications that interact with Excel files.

Get a Free License

To fully experience the capabilities of Spire.XLS for .NET without any evaluation limitations, you can request a free 30-day trial license.

To emphasize the text on a shape, we can only animate text instead of the whole shape. This article demonstrates how to apply animations to text in PowerPoint using Spire.Presenstation with C# and VB.NET.

Code Snippets

[C#]
//create a PowerPoint document
Presentation ppt = new Presentation();

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

//add a shape to the slide
IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 50, 200, 80));
shape.Fill.FillType = FillFormatType.Solid;
shape.Fill.SolidColor.Color = Color.Purple;
shape.ShapeStyle.LineColor.Color = Color.White;
shape.AppendTextFrame("Welcome to download Spire.Presentation");

//apply animation to the text in shape
AnimationEffect animation = shape.Slide.Timeline.MainSequence.AddEffect(shape, AnimationEffectType.Float);
animation.SetStartEndParagraphs(0, 0);

//save to file
ppt.SaveToFile("result.pptx", FileFormat.Pptx2013);
ppt.Dispose();
[VB.NET]
'create a PowerPoint document
Dim ppt As Presentation =  New Presentation() 
 
'get the first slide
Dim slide As ISlide =  ppt.Slides(0) 
 
'add a shape to the slide
Dim shape As IAutoShape =  slide.Shapes.AppendShape(ShapeType.Rectangle,New RectangleF(50,50,200,80)) 
shape.Fill.FillType = FillFormatType.Solid
shape.Fill.SolidColor.Color = Color.Purple
shape.ShapeStyle.LineColor.Color = Color.White
shape.AppendTextFrame("Welcome to download Spire.Presentation")
 
'apply animation to the text in shape
Dim animation As AnimationEffect =  shape.Slide.Timeline.MainSequence.AddEffect(shape,AnimationEffectType.Float) 
animation.SetStartEndParagraphs(0, 0)
 
'save to file
ppt.SaveToFile("result.pptx", FileFormat.Pptx2013)
ppt.Dispose()

Output

Apply Animations to Text in PowerPoint in C#, VB.NET

Digital timestamps mark a PDF signature with the time and date as proof of integrity. A timestamp shows that the contents of the document existed at a point in time, and are unchanged. This article is going to introduce how to digitally sign a PDF document with a timestamp server by using Spire.PDF.

Code Snippets

[C#]
using Spire.Pdf;
using Spire.Pdf.Graphics;
using Spire.Pdf.Security;
using System.Drawing;


namespace SignPDFwithTimestamp
{
    class Program
    {
        static void Main(string[] args)
        {
            //create a PdfDocument object and load a PDF file
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(@"C:\Users\Administrator\Desktop\Example.pdf");

            //load the certificate .pfx file
            PdfCertificate cert = new PdfCertificate(@"C:\Users\Administrator\Desktop\gary.pfx", "e-iceblue");

            //add a signature to the specified position
            PdfSignature signature = new PdfSignature(doc, doc.Pages[0], cert, "signature");
            signature.Bounds = new RectangleF(new PointF(350, 700), new SizeF(180, 90));

            //set the signature content
            signature.NameLabel = "Digitally signed by:Gary";
            signature.LocationInfoLabel = "Location:";
            signature.LocationInfo = "CN";
            signature.ReasonLabel = "Reason: ";
            signature.Reason = "Ensure authenticity";
            signature.ContactInfoLabel = "Contact Number: ";
            signature.ContactInfo = "028-81705109";
            signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill | PdfCertificationFlags.ForbidChanges;
            signature.SignImageSource = PdfImage.FromFile(@"C:\Users\Administrator\Desktop\company-logo.jpg");

            //configure a timestamp server
            string url = "http://timestamp.wosign.com/rfc3161";
            signature.ConfigureTimestamp(url);

            //save to file
            doc.SaveToFile("output.pdf");
        }
    }
}
[VB.NET]
Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Imports Spire.Pdf.Security
Imports System.Drawing


Namespace SignPDFwithTimestamp
	Class Program
		Private Shared Sub Main(args As String())
			'create a PdfDocument object and load a PDF file
Dim doc As PdfDocument =  New PdfDocument()
doc.LoadFromFile("C:\Users\Administrator\Desktop\Example.pdf")

'load the certificate .pfx file
Dim cert As PdfCertificate =  New PdfCertificate("C:\Users\Administrator\Desktop\gary.pfx","e-iceblue")

'add a signature to the specified position
Dim signature As PdfSignature =  New PdfSignature(doc,doc.Pages(0),cert,"signature")
signature.Bounds = New RectangleF(New PointF(350, 700), New SizeF(180, 90))

'set the signature content
signature.NameLabel = "Digitally signed by:Gary"
signature.LocationInfoLabel = "Location:"
signature.LocationInfo = "CN"
signature.ReasonLabel = "Reason: "
signature.Reason = "Ensure authenticity"
signature.ContactInfoLabel = "Contact Number: "
signature.ContactInfo = "028-81705109"
signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill Or PdfCertificationFlags.ForbidChanges
signature.SignImageSource = PdfImage.FromFile("C:\Users\Administrator\Desktop\company-logo.jpg")

'configure a timestamp server
Dim url As String =  "http://timestamp.wosign.com/rfc3161"
signature.ConfigureTimestamp(url)

'save to file
doc.SaveToFile("output.pdf")
		End Sub
	End Class
End Namespace

Output

How to Digitally Sign PDF with Timestamp Server in C#, VB.NET

PowerPoint print settings allow users to control how presentation slides are printed, such as print all slides, print some selected slides, print slides with frames or not, print many slides into one page, print order, print color and so on. This article will show you how to set print options when print PowerPoint documents in C#.

Firstly, view Microsoft PowerPoint's page print settings:

Set the print settings of PowerPoint document in C#

Code Snippets of set print settings of PowerPoint document by using PrinterSettings object to print the presentation slides:

static void Main(string[] args)
{
    //load the sample document from file
    Presentation ppt = new Presentation();
    ppt.LoadFromFile("Sample.pptx");


    //use PrinterSettings object to print presentation slides
    PrinterSettings ps = new PrinterSettings();
    ps.PrintRange = PrintRange.AllPages;
    ps.PrintToFile = true;
    ps.PrintFileName = ("Print.xps");

    //print the slide with frame
    ppt.SlideFrameForPrint = true;

    //print the slide with Grayscale
    ppt.GrayLevelForPrint = true;

    //Print 4 slides horizontal
    ppt.SlideCountPerPageForPrint = PageSlideCount.Four;
    ppt.OrderForPrint = Order.Horizontal;


    ////only select some slides to print
    //ppt.SelectSlidesForPrint("1", "3");


    //print the document
    ppt.Print(ps);

}

Code Snippets of set print document name by using PrintDocument object to print presentation slides:

static void Main(string[] args)
{
    //load the sample document from file
    Presentation ppt = new Presentation();
    ppt.LoadFromFile("Sample.pptx");

    //use PrintDocument object to print presentation slides
    PresentationPrintDocument document = new PresentationPrintDocument(ppt);

    //print document to virtual printer 
    document.PrinterSettings.PrinterName = "Microsoft XPS Document Writer";

    //print the slide with frame
    ppt.SlideFrameForPrint = true;

    //print 4 slides horizontal
    ppt.SlideCountPerPageForPrint = PageSlideCount.Four;
    ppt.OrderForPrint = Order.Horizontal;

    //print the slide with Grayscale
    ppt.GrayLevelForPrint = true;

    //set the print document name
    document.DocumentName = "Print Task"; 

    document.PrinterSettings.PrintToFile = true;
    document.PrinterSettings.PrintFileName = ("Print.xps");

    ppt.Print(document);                   
  
}

PostScript was developed by Adobe Systems in the 1980s as a way of turning digital graphics or text files into a fixed format ready for printing. With the passage time, although the PostScript (PS) file format is no longer as popular as it once was, now it is still supported by most printers. In this article, you will learn how to how to programmatically convert a PDF file to a PostScript (PS) file 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 

Convert PDF to PostScript in C# and VB.NET

Converting PDF to PS can improve the quality of the printed output. With Spire.PDF for .NET, you can complete the conversion with only three lines of code. The following are the detailed steps.

  • Create a PdfDocument instance.
  • Load a sample PDF file using PdfDocument.LoadFromFile() method.
  • Save the PDF file as a PS file using PdfDocument.SaveToFile(string filename, FileFormat.POSTSCRIPT) method.
  • C#
  • VB.NET
using Spire.Pdf;

namespace PDFtoPS
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a PdfDocument instance
            PdfDocument document = new PdfDocument();

            //Load a sample PDF file
            document.LoadFromFile("Test.pdf");

            //Save the PDF file as a PS file
            document.SaveToFile("toPostScript.ps", FileFormat.POSTSCRIPT);
        }
    }
}

C#/VB.NET: Convert PDF to PostScript (PS)

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.

Convert PDF to PCL using C#

2025-04-29 07:45:00 Written by Koohji

Converting a PDF to PCL (Printer Command Language) in C# can be an essential task for developers working with printing solutions. PCL is a well-established page description language used by many laser printers, and converting documents into this format allows for more efficient and accurate printing.

In this article, we will explore the process of converting PDFs to PCL format in C# using Spire.PDF for .NET, including batch conversion for processing multiple files efficiently.

Install Spire.PDF for .NET

To get started, you’ll need to install the Spire.PDF for .NET library in your project. The easiest way to do this is via NuGet.

  • 1.Open “NuGet Package Manager” in Visual Studio.
  • 2.Search for “Spire.PDF” and install the package.

Alternatively, you can run the following command in the Package Manager Console:

PM> Install-Package Spire.PDF

How to Convert PDF to PCL in C#

Once the Spire.PDF library is installed, you're ready to start converting PDF documents into PCL. The classes and methods used for conversion are explained below:

  • PdfDocument: This class represents the PDF document you're working with.
  • LoadFromFile(): This method loads the PDF file into the PdfDocument object.
  • SaveToFile(): This method saves the loaded PDF document in the specified format (PCL in this case).

Code Example:

  • C#
using Spire.Pdf;

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

            // Load a PDF file
            pdf.LoadFromFile("Input1.pdf");

            // Save to PCL format
            pdf.SaveToFile("PdfToPcl.pcl", FileFormat.PCL);
            pdf.Close();

        }
    }
}

Convert a PDF file to a PCL file.

Batch Conversion of PDF to PCL using C#

If you need to convert a large number of PDF files in a folder, you can perform batch conversion by following the below steps and code:

  • 1. Get all PDF files in a specified folder using the Directory.GetFiles() method.
  • 2. Use foreach loop to iterate over each PDF file.
  • 3. Load each PDF file into the PdfDocument object.
  • 4. Generate the output PCL file path, and then convert the PDF to PCL.

Code Example:

  • C#
using Spire.Pdf;
using System.IO;

namespace PDFtoPCL
{
    class Program
    {
        static void Main(string[] args)
        {

            string pdfFolder = @"F:\PDFs\";
            string pclFolder = @"F:\PCLs\";

            // Get all PDF files in a folder
            string[] pdfFiles = Directory.GetFiles(pdfFolder, "*.pdf");

            // Iterate through each PDF file
            foreach (string pdfFile in pdfFiles)
            {
                // Load the PDF file into the PdfDocument object
                PdfDocument pdf = new PdfDocument();
                pdf.LoadFromFile(pdfFile);

                // Define the file path and file name of the output PCL file
                string outputFile = Path.Combine(pclFolder, Path.GetFileNameWithoutExtension(pdfFile) + ".pcl");

                // Save PDF as PCL file
                pdf.SaveToFile(outputFile, FileFormat.PCL);
                pdf.Close();
            }
        }
    }
}

Batch convert the PDF files to PCL files.

Conclusion

With Spire.PDF for .NET, converting PDFs to PCL in C# becomes straightforward, whether you're handling individual files or bulk operations. Its robust API makes it an excellent choice for automating printing workflows or integrating conversion features into applications.

Get a Free License

To fully experience the capabilities of Spire.PDF for .NET without any evaluation limitations, you can request a free 30-day trial license.

Convert Word to PCL

2019-03-05 09:02:05 Written by Koohji

PCL File is Digital printed document created in the Printer Command Language (more commonly referred to as PCL) page description language. From v7.1.19, Spire.Doc supports to convert word document to PCL. There are many kinds of standard for PCL document; the PCL here refers to PCL 6 (PCL 6 Enhanced or PCL XL). This article will show you how to save word document to PCL in C# and VB.NET by only three lines of codes.

[C#]
using Spire.Doc;

namespace DOCPCL
{
    class Program
    {
        static void Main(string[] args)
        {
            //load the sample document
            Document doc = new Document();
            doc.LoadFromFile("Sample.docx", FileFormat.Docx2010);

            //save the document as a PCL file
            doc.SaveToFile("Result.pcl", FileFormat.PCL);



        }
    }
}
[VB.NET]
Imports Spire.Doc

Namespace DOCPCL
	Class Program
		Private Shared Sub Main(args As String())
			'load the sample document
			Dim doc As New Document()
			doc.LoadFromFile("Sample.docx", FileFormat.Docx2010)

			'save the document as a PCL file
			doc.SaveToFile("Result.pcl", FileFormat.PCL)



		End Sub
	End Class
End Namespace

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);
        }
    }
}
page 13