Convert to MS Office from any file in C#
Nutrient .NET SDK (formerly GdPicture.NET) supports converting 100+ file types to Word, Excel, or PowerPoint. For more information, refer to the full list of supported file types.
Office target availability depends on the source file type, and not every input can be meaningfully converted to every Office format.
Converting PDF to MS Office
To convert PDF files to MS Office, refer to our separate PDF-to-Word, PDF-to-Excel, and PDF-to-PowerPoint guides.
Converting other file types to MS Office
To save a file to Word, Excel, or PowerPoint format, first load the source document with the [LoadFromFile method][loadfromfile] of the GdPictureDocumentConverter class. Then use the [SaveAsDOCX method][saveasdocx] to convert it to a DOCX, the [SaveAsXLSX method][saveasxlsx] to convert it to an XLSX, or the [SaveAsPPTX method][saveaspptx] to convert it to a PPTX.
The LoadFromFile method uses the following parameters:
FilePath— The source file path.DocumentFormat— A member of the [DocumentFormatenumeration][documentformat]. Specify the source file format when possible. UseDocumentFormat.DocumentFormatUNKNOWNif you aren’t sure about the format.
The SaveAsDOCX, SaveAsXLSX, and SaveAsPPTX methods use the following parameter:
Stream, or the overloadFilePath— A stream or file path where the currently loaded document is saved. When using a stream, it must be open for reading, writing, and seeking.
When you use the stream overload, the stream should be open for both reading and writing, and it should be closed/disposed of by the user once processing is complete using the [CloseDocument method][closedocument method].
How to convert any file to MS Office
- Create a
GdPictureDocumentConverterobject. - Load the source file with [
GdPictureDocumentConverter.LoadFromFile(String, DocumentFormat)][loadfromfile]. Recommended: Specify the source document format with a member of the [DocumentFormatenumeration][documentformat]. - Save the loaded document as a DOCX using
SaveAsDOCX, as an XLSX usingSaveAsXLSX, or as a PPTX usingSaveAsPPTX.
The following example converts and saves an RTF document to a DOCX file:
using GdPictureDocumentConverter converter = new();
GdPictureStatus status = converter.LoadFromFile(@"input.rtf", GdPicture14.DocumentFormat.DocumentFormatRTF);if (status != GdPictureStatus.OK){ throw new Exception(status.ToString());}
status = converter.SaveAsDOCX("output.docx");if (status != GdPictureStatus.OK){ throw new Exception(status.ToString());}
status = converter.CloseDocument();if (status != GdPictureStatus.OK && status != GdPictureStatus.Aborted){ throw new Exception(status.ToString());}
Console.WriteLine("The input document has been converted to a docx file");DocxImageQuality PropertyGdPictureDocumentConverter Class- [
GdPictureDocumentConverter Members][gdpicturedocumentconverter members] - [
CloseDocument Method][closedocument method] RasterizationDPI Property
Optional file type configuration properties
The following file types have optional configuration properties for greater precision:
Optional Office conversion properties
Optionally, configure the conversion with the following properties of the GdPictureDocumentConverter object:
DocxImageQualityis an integer from 0 to 100 that specifies the quality used to compress images embedded in the resulting DOCX document.RasterizationDPIis an integer that specifies the resolution, expressed in dots per inch (DPI), used when vector content must be rasterized during conversion to Office formats.