XLS and XLSX are two different file formats for Microsoft Excel spreadsheets. XLS is the default file format for Microsoft Excel 2003 and earlier versions, while XLSX is the default file format for Microsoft Excel 2007 and later versions. In some cases, developers may need to convert between Excel XLS and XLSX file formats. In this article, we will explain how to convert XLS to XLSX or XLSX to XLS in C# and VB.NET using Spire.XLS for .NET.

Install Spire.XLS for .NET

To begin with, you need to add the DLL files included in the Spire.XLS 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.XLS

Convert XLS to XLSX in C# and VB.NET

The following are the steps to convert an XLS file to XLSX format using Spire.XLS for .NET:

  • Create a Workbook instance.
  • Load the XLS file using Workbook.LoadFromFile() method.
  • Save the XLS file to XLSX format using Workbook.SaveToFile(string, ExcelVersion) method.
  • C#
  • VB.NET
using Spire.Xls;

namespace ConvertXlsToXlsx
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Workbook instance
            Workbook workbook = new Workbook();
            //Load an XLS file
            workbook.LoadFromFile("Input.xls");

            //Convert the file to XLSX format
            workbook.SaveToFile("ToXlsx.xlsx", ExcelVersion.Version2016);
        }
    }
}

C#/VB.NET: Convert XLS to XLSX and Vice versa

Convert XLSX to XLS in C# and VB.NET

The following are the steps to convert an XLSX file to XLS format using Spire.XLS for .NET:

  • Create a Workbook instance.
  • Load the XLSX file using Workbook.LoadFromFile() method.
  • Save the XLSX file to XLS format using Workbook.SaveToFile(string, ExcelVersion) method.
  • C#
  • VB.NET
using Spire.Xls;

namespace ConvertXlsxToXls
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Workbook instance
            Workbook workbook = new Workbook();
            //Load an XLSX file
            workbook.LoadFromFile("Input.xlsx");

            //Convert the file to XLS format
            workbook.SaveToFile("ToXls.xls", ExcelVersion.Version97to2003);
        }
    }
}

C#/VB.NET: Convert XLS to XLSX and Vice versa

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.

Traverse through the cells of Table

2014-06-19 07:17:19 Written by Koohji

Spire.Presentation is a powerful and easy-to-use .NET component, especially designed for developers. Using Spire.Presentation you can generate, modify, convert, render, and print documents without installing Microsoft PowerPoint on your machine. There are documents on our site introducing how to insert table and edit table in PowerPoint file. In this document, I will introduce you how to traverse through the cells of table.

It is very easy to traverse through the cells of table using Spire.Presentation. Just get the row collection using the property - TableRows of Table. Then traverse through each cell of each row. Or you can get the column collection using the property – ColumnsList of Table. Then traverse through each cell of each column.

Step 1: Create Presentation instance and load file.

Presentation presentation = new Presentation();
presentation.LoadFromFile("table.pptx");

Step 2: Get the table in PowerPoint file.

foreach (IShape shape in presentation.Slides[0].Shapes)
{
    if (shape is ITable)
    {
        table = (ITable)shape;
    }
}

Step 3: Traverse through the rows in row collection and traverse through each cell in each row.

foreach (TableRow row in table.TableRows)
{
    foreach (Cell cell in row)
    {
        //print the data in cell
        Console.Write("{0,15}", cell.TextFrame.Text);
    }
    Console.WriteLine();
}

Download and install Spire.Presentation for .NET and refer to below code to traverse through the cells in PowerPoint document.

Screenshots and Full code:

Traverse through the cells of Table

Traverse through the cells of Table

[C#]
using Spire.Presentation;
using System;

namespace Trasverse
{

    class Program
    {

        static void Main(string[] args)
        {
            //create Presentation instance and load file
            Presentation presentation = new Presentation();
            presentation.LoadFromFile("table.pptx");

            ITable table = null;

            //get the table
            foreach (IShape shape in presentation.Slides[0].Shapes)
            {
                if (shape is ITable)
                {
                    table = (ITable)shape;

                    //traverse through the cells of table
                    foreach (TableRow row in table.TableRows)
                    {
                        foreach (Cell cell in row)
                        {
                            //print the data in cell
                            Console.Write("{0,15}", cell.TextFrame.Text);
                        }
                        Console.WriteLine();
                    }
                }
            }
            Console.ReadLine();

        }

    }
}

If you couldn't successfully use Spire.Presentation, please refer Spire.Presentation Quick Start which can guide you quickly use Spire.Presentation.

How to Remove Row or Column in Table

2014-06-12 07:03:21 Written by Koohji

We have previously introduced how to insert a custom table and how to edit a table in PowerPoint documents. Now, we are going to make a brief introduction about how to remove the rows or columns that belong to an existing table.

Spire.Presentation for .NET, built to provide flexible PowerPoint document handling capabilities, allows developers to add a table to a slide and perform some basic operations as removing rows and columns in the table in an easy way.

Step 1: Create a PowerPoint instance and load a sample file.

Presentation presentation = new Presentation();
presentation.LoadFromFile("table.pptx");

Step 2: Find the table and remove the second column and second row.

ITable table = null;  
foreach (IShape shape in presentation.Slides[0].Shapes)
{
  if (shape is ITable)
  {
    table = (ITable)shape;
    table.ColumnsList.RemoveAt(1, false)    
    table.TableRows.RemoveAt(1, false);       
  }
}

Step 3: Save the document.

presentation.SaveToFile("result.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("result.pptx");

The sample table with the second row and second column highlighted.

Remove Row or Column in Table

Result:

Remove Row or Column in Table

Full C# code:

using Spire.Presentation;

namespace RemoveRow
{

    class Program
    {

        static void Main(string[] args)
        {
            //create a PPT document
            Presentation presentation = new Presentation();
            presentation.LoadFromFile("table.pptx");

            //get the table in PPT document
            ITable table = null;
            foreach (IShape shape in presentation.Slides[0].Shapes)
            {
                if (shape is ITable)
                {
                    table = (ITable)shape;

                    //remove the second column
                    table.ColumnsList.RemoveAt(1, false);

                    //remove the second row
                    table.TableRows.RemoveAt(1, false);
                }
            }
            //save the document
            presentation.SaveToFile("result.pptx", FileFormat.Pptx2010);
            System.Diagnostics.Process.Start("result.pptx");

        }

    }
}
page 262