What is OpenDocument Format
OpenDocument Format (ODF) is an open and ISO-standard file format for office application files such as word processing documents, spreadsheets and presentations. OpenDocument format has several advantages, for example, it is compatible with MS Office and open-source applications like OpenOffice and LibreOffice, it is platform-independent and does not rely on any office application suite, and it is an open standard that can be implemented by any company in its software.
OpenDocument files can have the following extensions:
- .odt (word processing documents)
- .ods (spreadsheets)
- .odp (presentations)
This article will introduce how to convert Office (Word, Excel, PowerPoint) files to OpenDocument Format (.odt, .ods, .odp) using C# and VB.NET. It includes the following topics:
- Convert Word Files to OpenDocument Text (.odt)
- Convert Excel Files to OpenDocument Spreadsheet (.ods)
- Convert PowerPoint Files to OpenDocument Presentation (.odp)
.NET Library to Convert Office Files to OpenDocument Format
In order to convert Office files to ODF, this article uses Spire.Office for .NET library. You can install Spire.Office for .NET via NuGet by selecting Tools > NuGet Package Manager > Package Manager Console, and then executing the following command:
PM> Install-Package Spire.Office
Alternatively, you can also download the DLL files of Spire.Office for .NET from the official website, extract the package and then add the DLL files under the Bin folder to your project as references.
Convert Word Files to OpenDocument Text (.odt) in C# and VB.NET
The following steps demonstrate how to convert a Word file to OpenDocument Text (.odt) format:
- Initialize an instance of the Document class.
- Load a Word file using Document.LoadFromFile(string) method.
- Save the file to OpenDocument Text (.odt) format using Document.SaveToFile(string, FileFormat) method.
C#
using Spire.Doc;
namespace ConvertWordFilesToODT
{
class Program
{
static void Main(string[] args)
{
//Initialize an instance of the Document class
Document document = new Document();
//Load a Word file
document.LoadFromFile(@"C:\Users\Administrator\Desktop\Test.docx");
//Save the Word file to OpenDocument Text (.odt) format
document.SaveToFile("WordToOdt.odt", Spire.Doc.FileFormat.Odt);
}
}
}
VB.NET
Imports Spire.Doc
Namespace ConvertWordFilesToODT
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'Initialize an instance of the Document class
Dim document As Document = New Document()
'Load a Word file
document.LoadFromFile("C:\Users\Administrator\Desktop\Test.docx")
'Save the Word file to OpenDocument Text (.odt) format
document.SaveToFile("WordToOdt.odt", Spire.Doc.FileFormat.Odt)
End Sub
End Class
End Namespace
Convert Excel Files to OpenDocument Spreadsheet (.ods) in C# and VB.NET
The following steps demonstrate how to convert an Excel file to OpenDocument Spreadsheet (.ods) format:
- Initialize an instance of the Workbook class.
- Load an Excel file using Workbook.LoadFromFile(string) method.
- Save the file to OpenDocument Spreadsheet (.ods) format using Workbook.SaveToFile(string, FileFormat) method.
C#
using Spire.Xls;
namespace ConvertExcelFilesToODS
{
class Program
{
static void Main(string[] args)
{
//Initialize an instance of the Workbook class
Workbook workbook = new Workbook();
//Load an Excel file
workbook.LoadFromFile(@"C:\Users\Administrator\Desktop\Test.xlsx");
//Save the Excel file to OpenDocument Spreadsheet (.ods) format
workbook.SaveToFile("ExcelToOds.ods", Spire.Xls.FileFormat.ODS);
}
}
}
VB.NET
Imports Spire.Xls
Namespace ConvertExcelFilesToODS
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'Initialize an instance of the Workbook class
Dim workbook As Workbook = New Workbook()
'Load an Excel file
workbook.LoadFromFile("C:\Users\Administrator\Desktop\Test.xlsx")
'Save the Excel file to OpenDocument Spreadsheet (.ods) format
workbook.SaveToFile("ExcelToOds.ods", Spire.Xls.FileFormat.ODS)
End Sub
End Class
End Namespace
Convert PowerPoint Files to OpenDocument Presentation (.odp) in C# and VB.NET
The following steps demonstrate how to convert a PowerPoint file to OpenDocument Presentation (.odp) format:
- Initialize an instance of the Presentation class.
- Load a PowerPoint file using Presentation.LoadFromFile(string) method.
- Save the file to OpenDocument Presentation (.odp) format using Presentation.SaveToFile(string, FileFormat) method.
C#
using Spire.Presentation;
namespace ConvertPowerPointFilesToODP
{
class Program
{
static void Main(string[] args)
{
//Initialize an instance of the Presentation class
Presentation presentation = new Presentation();
//Load a PowerPoint file
presentation.LoadFromFile(@"C:\Users\Administrator\Desktop\Test.pptx");
//Save the PowerPoint file to OpenDocument Presentation (.odp) format
presentation.SaveToFile("PowerPointToOdp.odp", Spire.Presentation.FileFormat.ODP);
}
}
}
VB.NET
Imports Spire.Presentation
Namespace ConvertPowerPointFilesToODP
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'Initialize an instance of the Presentation class
Dim presentation As Presentation = New Presentation()
'Load a PowerPoint file
presentation.LoadFromFile("C:\Users\Administrator\Desktop\Test.pptx")
'Save the PowerPoint file to OpenDocument Presentation (.odp) format
presentation.SaveToFile("PowerPointToOdp.odp", Spire.Presentation.FileFormat.ODP)
End Sub
End Class
End Namespace
Conclusion
This article demonstrated how to convert Office files to OpenDocument Format (ODF) using Spire.Office for .NET library. Besides the conversion from Office to ODF, you can also use the library to convert Office files to lots of other file formats, such as PDF, HTML, images and many more.