Skip to content

Convert binary documents

Manfredi Marceca edited this page Mar 2, 2025 · 1 revision

Convert Office 97-2003 documents

Convert DOC to DOCX

  1. Install the DocSharp.Binary.Doc package from NuGet

  2. Use the following code:

using WordprocessingDocument = DocSharp.Binary.OpenXmlLib.WordprocessingML.WordprocessingDocument;
using DocSharp.Binary.DocFileFormat;
using DocSharp.Binary.StructuredStorage.Reader;
// ...
using (var reader = new StructuredStorageReader(inputFile))
{
    var outputType = DocSharp.Binary.OpenXmlLib.OpenXmlDocumentType.Document; // Use Template type for .dot files
    var doc = new WordDocument(reader);
    using (var docx = WordprocessingDocument.Create(outputFile, outputType))
    {
        DocSharp.Binary.WordprocessingMLMapping.Converter.Convert(doc, docx);
    }
}

Convert XLS to XLSX

  1. Install the DocSharp.Binary.Xls package from NuGet

  2. Use the following code:

using SpreadsheetDocument = DocSharp.Binary.OpenXmlLib.SpreadsheetML.SpreadsheetDocument;
using DocSharp.Binary.Spreadsheet.XlsFileFormat;
using DocSharp.Binary.StructuredStorage.Reader;
// ...
using (var reader = new StructuredStorageReader(inputFile))
{
    var outputType = DocSharp.Binary.OpenXmlLib.OpenXmlDocumentType.Document; // Use Template type for .xlt files
    var xls = new XlsDocument(reader);
    using (var xlsx = SpreadsheetDocument.Create(outputFile, outputType))
    {
        DocSharp.Binary.SpreadsheetMLMapping.Converter.Convert(xls, xlsx);
    }
}

Convert PPT to PPTX

  1. Install the DocSharp.Binary.Ppt package from NuGet

  2. Use the following code:

using PresentationDocument = DocSharp.Binary.OpenXmlLib.PresentationML.PresentationDocument;
using DocSharp.Binary.PptFileFormat;
using DocSharp.Binary.StructuredStorage.Reader;
// ...
using (var reader = new StructuredStorageReader(inputFile))
{
    var outputType = DocSharp.Binary.OpenXmlLib.OpenXmlDocumentType.Document; // Use Template type for .pot files
    var ppt = new PowerpointDocument(reader);
    using (var pptx = PresentationDocument.Create(outputFile, outputType))
    {
        DocSharp.Binary.PresentationMLMapping.Converter.Convert(ppt, pptx);
    }
}
Clone this wiki locally