-
Notifications
You must be signed in to change notification settings - Fork 3
Convert binary documents
Manfredi Marceca edited this page Mar 2, 2025
·
1 revision
-
Install the DocSharp.Binary.Doc package from NuGet
-
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);
}
}
-
Install the DocSharp.Binary.Xls package from NuGet
-
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);
}
}
-
Install the DocSharp.Binary.Ppt package from NuGet
-
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);
}
}