Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the conversion between Word and ODT documents in C #

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the knowledge of "how to convert Word and ODT documents in C #". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

ODT document format is an open document format (OpenDocument Text). Typically, files in ODT format can be opened using LibreOffice Writer, MS Word, or some other document editor. When we are dealing with a document, we can get the target document by converting ODT to other formats or to ODT by format conversion.

Program environment

In this test, Free Spire.Doc for .NET was introduced into the program. You can reference Spire.Doc.dll files in the following ways:

Method 1

Download Free Spire.Doc for .NET locally, extract it, and install it. After the installation is complete, locate the Spire.Doc.dll in the BIN folder under the installation path. Then open solution Explorer in Visual Studio, right-click "reference" and "add reference" to add a reference to the dll file under the local path BIN folder.

Method 2

Install via NuGet. It can be installed in the following two ways:

(1) you can open "solution Explorer" in Visual Studio, right-click "reference", "manage NuGet package", then search for "Free Spire.Doc" and click "install". Wait for the program to be installed.

(2) copy the following to the PM console installation.

Install-Package FreeSpire.Doc-Version 10.2.0

Format conversion

When you convert, you only need to operate three lines of code to do this:

1. Create an object of the Document class.

two。 Call the Document.LoadFromFile (string fileName) method to load the source document.

3. Save to the specified path in the target file format through the Document.SaveToFile (string fileName, FileFormat fileFormat) method.

1. Word is converted to ODTC#using Spire.Doc;namespace WordtoODT {class Program {static void Main (string [] args) {/ / create an object of Document class Document document = new Document (); / / load Word document document.LoadFromFile ("sample.docx") / / Save to ODT format document.SaveToFile ("ToODT.odt", FileFormat.Odt) } vb.netImports Spire.DocNamespace WordtoODT Class Program Private Shared Sub Main (args As String ()) 'create an object of Document class Dim document As New Document ()' load Word document document.LoadFromFile ("sample.docx") 'save to ODT format document.SaveToFile ("ToODT.odt", FileFormat.Odt) End Sub End ClassEnd Namespace2. ODT is converted to WordC#using Spire.Doc;namespace ODTtoWord {class Program {static void Main (string [] args) {/ / create an object of Document class Document document = new Document (); / / load ODT document document.LoadFromFile ("test.odt"); / / Save to Word format document.SaveToFile ("toWord.docx", FileFormat.Docx2013) } vb.netImports Spire.DocNamespace ODTtoWord Class Program Private Shared Sub Main (args As String ()) 'create an object of Document class Dim document As New Document ()' load ODT document document.LoadFromFile ("test.odt") 'save to Word format document.SaveToFile ("toWord.docx", FileFormat.Docx2013) End Sub End ClassEnd Namespace

Note: the file path in the test code is the program Debug path, and the file path can be customized to another path.

This is the end of the introduction of "how to convert Word and ODT documents in C #". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report