IO API

Back to index page

What is IO API?

IO API library is defined typically for external usage, which means to produce JChem for Excel [JC4XL] documents silently by a service in the background.

 

This API provides possibilities to read and write new or existing JChem for Excel workbooks. Furthermore this library also allows reading and converting ISIS for Excel, ChemDraw for Excel and Accord for Excel files to JC4XL files.

 

Installation

The current install package is available on the download page of the JChem for Excel product:

https://www.chemaxon.com/download/jchem-for-excel/

 

Licensing

IO API module requires the existence of a valid JChem for Excel license.

 

How to access it?

From C# project, add the references of the delivered assemblies to the project.

These are the following:

ChemAxon.NET.Base.dll
ChemAxon.NET.IKVM.dll
JChemExcel.Base.dll
JChemExcel.IKVM.dll
JChemExcel.IO.API.dll

 

IoApiReferences

 

These assemblies are available in the GAC (C:\Windows\assembly\GAC_MSIL) after the installation.

 

Usage

The IO API module has a static class called WorkbookHandlerFactory which can provide three different objects:

IWorkbookReader: it gives possibility to read a JChem, ISIS, ChemDraw or  Accord for Excel workbook
IWorkbookWriter: it gives possibility to write a JChem for Excel workbook
IWorkbookConverter: it gives possibility to convert an ISIS (Symyx), ChemDraw or Accord for Excel workbook to a JChem for Excel specific one

 

WorkbookHandlerFactory can create these kind of objects for a file path, a file stream or a specified workbook instance. Workbook instance can be an OpenXml document (DocumentFormat.OpenXml.Packaging.SpreadsheetDocument what is defined in the Microsoft-developed DocumentFormat.OpenXml assembly), or a SmartXls document (SmartXLS.WorkBook what is part of the third party DLL named XS.dll). OpenXml documents can handle OpenXml-based Excel files like XLSX, while SmartXls instances can handle the standard formats what are used by the MS Excel 2003 and the previous versions.

 

Here is the list of the available methods on the WorkbookHandlerFactory class:

Name

Signatures

CreateReader

IWorkbookReader CreateReader(string filePath)

IWorkbookReader CreateReader(string filePath, WorkbookType workbookType)

IWorkbookReader CreateReader(string filePath, ExcelFileType excelFileType)

IWorkbookReader CreateReader(string filePath, WorkbookType workbookType, ExcelFileType excelFileType)

IWorkbookReader CreateReader(Stream fileStream)

IWorkbookReader CreateReader(Stream fileStream, WorkbookType workbookType)

IWorkbookReader CreateReader(Stream fileStream, ExcelFileType excelFileType)

IWorkbookReader CreateReader(Stream fileStream, WorkbookType workbookType, ExcelFileType excelFileType)

IWorkbookReader CreateReader(object workbook)

IWorkbookReader CreateReader(object workbook, WorkbookType workbookType)

IWorkbookReader CreateReader(object workbook, ExcelFileType excelFileType)

IWorkbookReader CreateReader(object workbook, WorkbookType workbookType, ExcelFileType excelFileType)

TryCreateReader

bool TryCreateReader(string filePath, out IWorkbookReader reader)

bool TryCreateReader(string filePath, WorkbookType workbookType, out IWorkbookReader reader)

bool TryCreateReader(string filePath, ExcelFileType excelFileType, out IWorkbookReader reader)

bool TryCreateReader(string filePath, WorkbookType workbookType, ExcelFileType excelFileType, out IWorkbookReader reader)

bool TryCreateReader(Stream fileStream, out IWorkbookReader reader)

bool TryCreateReader(Stream fileStream, WorkbookType workbookType, out IWorkbookReader reader)

bool TryCreateReader(Stream fileStream, ExcelFileType excelFileType, out IWorkbookReader reader)

bool TryCreateReader(Stream fileStream, WorkbookType workbookType, ExcelFileType excelFileType, out IWorkbookReader reader)

bool TryCreateReader(object workbook, out IWorkbookReader reader)

bool TryCreateReader(object workbook, WorkbookType workbookType, out IWorkbookReader reader)

bool TryCreateReader(object workbook, ExcelFileType excelFileType, out IWorkbookReader reader)

bool TryCreateReader(object workbook, WorkbookType workbookType, ExcelFileType excelFileType, out IWorkbookReader reader)

CreateWriter

IWorkbookWriter CreateWriter(string filePath)

IWorkbookWriter CreateWriter(string filePath, ExcelFileType excelFileType)

IWorkbookWriter CreateWriter(Stream fileStream)

IWorkbookWriter CreateWriter(Stream fileStream, ExcelFileType excelFileType)

IWorkbookWriter CreateWriter(object workbook)

IWorkbookWriter CreateWriter(object workbook, ExcelFileType excelFileType)

TryCreateWriter

bool TryCreateWriter(string filePath, out IWorkbookWriter writer)

bool TryCreateWriter(string filePath, ExcelFileType excelFileType, out IWorkbookWriter writer)

bool TryCreateWriter(Stream fileStream, out IWorkbookWriter writer)

bool TryCreateWriter(Stream fileStream, ExcelFileType excelFileType, out IWorkbookWriter writer)

bool TryCreateWriter(object workbook, out IWorkbookWriter writer)

bool TryCreateWriter(object workbook, ExcelFileType excelFileType, out IWorkbookWriter writer)

CreateConverter

IWorkbookConverter CreateConverter(string filePath)

IWorkbookConverter CreateConverter(string filePath, WorkbookType workbookType)

IWorkbookConverter CreateConverter(string filePath, ExcelFileType excelFileType)

IWorkbookConverter CreateConverter(string filePath, WorkbookType workbookType, ExcelFileType excelFileType)

IWorkbookConverter CreateConverter(Stream fileStream)

IWorkbookConverter CreateConverter(Stream fileStream, WorkbookType workbookType)

IWorkbookConverter CreateConverter(Stream fileStream, ExcelFileType excelFileType)

IWorkbookConverter CreateConverter(Stream fileStream, WorkbookType workbookType, ExcelFileType excelFileType)

IWorkbookConverter CreateConverter(object workbook)

IWorkbookConverter CreateConverter(object workbook, WorkbookType workbookType)

IWorkbookConverter CreateConverter(object workbook, ExcelFileType excelFileType)

IWorkbookConverter CreateConverter(object workbook, WorkbookType workbookType, ExcelFileType excelFileType)

TryCreateConverter

bool TryCreateConverter(string filePath, out IWorkbookConverter converter)

bool TryCreateConverter(string filePath, WorkbookType workbookType, out IWorkbookConverter converter)

bool TryCreateConverter(string filePath, ExcelFileType excelFileType, out IWorkbookConverter converter)

bool TryCreateConverter(string filePath, WorkbookType workbookType, ExcelFileType excelFileType, out IWorkbookConverter converter)

bool TryCreateConverter(Stream fileStream, out IWorkbookConverter converter)

bool TryCreateConverter(Stream fileStream, WorkbookType workbookType, out IWorkbookConverter converter)

bool TryCreateConverter(Stream fileStream, ExcelFileType excelFileType, out IWorkbookConverter converter)

bool TryCreateConverter(Stream fileStream, WorkbookType workbookType, ExcelFileType excelFileType, out IWorkbookConverter converter)

bool TryCreateConverter(object workbook, out IWorkbookConverter converter)

bool TryCreateConverter(object workbook, WorkbookType workbookType, out IWorkbookConverter converter)

bool TryCreateConverter(object workbook, ExcelFileType excelFileType, out IWorkbookConverter converter)

bool TryCreateConverter(object workbook, WorkbookType workbookType, ExcelFileType excelFileType, out IWorkbookConverter converter)

 

where the following two enumerations are used:

 

   public enum WorkbookType : byte

   {

       JChemForExcel = 1,

      IsisForExcel = 2,

      ChemDrawForExcel = 4,

       AccordForExcel = 8

   }

 

   public enum ExcelFileType : byte

   {

       Standard = 1,

       XmlBased = 2

   }

 

The IWorkbookReader interface:

 

  public interface IWorkbookReader : IWorkbook

   {

      /// <summary>

      /// Gets the structure from the given cell (column, row).

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Column index.</param>

      /// <param name="rowIndex">Row index.</param>

      /// <returns>Returns the map of the structure.</returns>

      MoleculeMap GetStructure(string worksheetName, int columnIndex, int rowIndex);

 

      /// <summary>

      /// Gets all the structures from the given worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <returns>Returns the map of the structures.</returns>

      MoleculeMap[] GetStructures(string worksheetName);

 

      /// <summary>

      /// Gets all the structures from the column on the worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Column index.</param>

      /// <returns>Returns the map of the structures.</returns>

      MoleculeMap[] GetStructures(string worksheetName, int columnIndex);

 

      /// <summary>

      /// Gets all the structures from the column on the worksheet where the start row index is defined.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Column index.</param>

      /// <param name="startRowIndex">Start row index.</param>

      /// <returns>Returns the map of the structures.</returns>

      MoleculeMap[] GetStructures(string worksheetName, int columnIndex, int startRowIndex);

 

      /// <summary>

      /// Gets all the structures from the column on the worksheet where the start and the end row index is defined.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Column index.</param>

      /// <param name="startRowIndex">Start row index.</param>

      /// <param name="endRowIndex">End row index.</param>

      /// <returns>Returns the map of the structures.</returns>

      MoleculeMap[] GetStructures(string worksheetName, int columnIndex, int startRowIndex, int endRowIndex);

 

      /// <summary>

      /// Gets all the structures from the range.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="startColumnIndex">Start column index.</param>

      /// <param name="startRowIndex">Start row index.</param>

      /// <param name="endColumnIndex">End column index.</param>

      /// <param name="endRowIndex">End row index.</param>

      /// <returns>Returns the map of the structures.</returns>

      MoleculeMap[] GetStructures(string worksheetName, int startColumnIndex, int startRowIndex, int endColumnIndex, int endRowIndex);

 

      /// <summary>

      /// Gets all the structures from the workbook.

      /// </summary>

      /// <returns>Returns the map of the structures.</returns>

      MoleculeMap[] GetAllStructures();

   }

 

Where MoleculeMap class contains the structure itself and describes the exact position of the structure: sheet name, column and row indexes.

 

The IWorkbookWriter interface:

 

  public interface IWorkbookWriter : IWorkbook

   {

      /// <summary>

      /// Adds structure to the worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Index of the column.</param>

      /// <param name="rowIndex">Index of the row.</param>

      /// <param name="structure">Molecule string.</param>

      /// <returns>Returns the used cell.</returns>

      object AddStructure(string worksheetName, int columnIndex, int rowIndex, string structure);

 

      /// <summary>

      /// Adds structure to the worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Index of the column.</param>

      /// <param name="rowIndex">Index of the row.</param>

      /// <param name="structure">Molecule string.</param>

      /// <param name="id">ID of the molecule.</param>

      /// <param name="showId">Show the ID or the molecule.</param>

      /// <returns>Returns the used cell.</returns>

      object AddStructure(string worksheetName, int columnIndex, int rowIndex, string structure, string id, bool showId);

 

      /// <summary>

      /// Adds structure to the worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Index of the column.</param>

      /// <param name="rowIndex">Index of the row.</param>

      /// <param name="structure">Molecule string.</param>

      /// <param name="format">Format of the molecule string.</param>

      /// <returns>Returns the used cell.</returns>

      object AddStructure(string worksheetName, int columnIndex, int rowIndex, string structure, string format);

 

      /// <summary>

      /// Adds structure to the worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Index of the column.</param>

      /// <param name="rowIndex">Index of the row.</param>

      /// <param name="structure">Molecule string.</param>

      /// <param name="format">Format of the molecule string.</param>

      /// <param name="id">ID of the molecule.</param>

      /// <param name="showId">Show the ID or the molecule.</param>

      /// <returns>Returns the used cell.</returns>

      object AddStructure(string worksheetName, int columnIndex, int rowIndex, string structure, string format, string id, bool showId);

 

      /// <summary>

      /// Adds structure to the worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Index of the column.</param>

      /// <param name="rowIndex">Index of the row.</param>

      /// <param name="structure">Molecule string.</param>

      /// <param name="format">Format of the structure.</param>

      /// <returns>Returns the used cell.</returns>

      object AddStructure(string worksheetName, int columnIndex, int rowIndex, string structure, MoleculeFormat format);

 

      /// <summary>

      /// Adds structure to the worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Index of the column.</param>

      /// <param name="rowIndex">Index of the row.</param>

      /// <param name="structure">Molecule string.</param>

      /// <param name="format">Format of the structure.</param>

      /// <param name="id">ID of the molecule.</param>

      /// <param name="showId">Show the ID or the molecule.</param>

      /// <returns>Returns the used cell.</returns>

      object AddStructure(string worksheetName, int columnIndex, int rowIndex, string structure, MoleculeFormat format, string id, bool showId);

 

      /// <summary>

      /// Adds structure to the worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Index of the column.</param>

      /// <param name="rowIndex">Index of the row.</param>

      /// <param name="structure">Binary data of the molecule.</param>

      /// <returns>Returns the used cell.</returns>

      object AddStructure(string worksheetName, int columnIndex, int rowIndex, byte[] structure);

 

      /// <summary>

      /// Adds structure to the worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Index of the column.</param>

      /// <param name="rowIndex">Index of the row.</param>

      /// <param name="structure">Binary data of the molecule.</param>

      /// <param name="id">ID of the molecule.</param>

      /// <param name="showId">Show the ID or the molecule.</param>

      /// <returns>Returns the used cell.</returns>

      object AddStructure(string worksheetName, int columnIndex, int rowIndex, byte[] structure, string id, bool showId);

 

      /// <summary>

      /// Adds structure to the worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Index of the column.</param>

      /// <param name="rowIndex">Index of the row.</param>

      /// <param name="structure">Binary data of the molecule.</param>

      /// <param name="format">Format of the structure.</param>

      /// <returns>Returns the used cell.</returns>

      object AddStructure(string worksheetName, int columnIndex, int rowIndex, byte[] structure, string format);

 

      /// <summary>

      /// Adds structure to the worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Index of the column.</param>

      /// <param name="rowIndex">Index of the row.</param>

      /// <param name="structure">Binary data of the molecule.</param>

      /// <param name="format">Format of the structure.</param>

      /// <param name="id">ID of the molecule.</param>

      /// <param name="showId">Show the ID or the molecule.</param>

      /// <returns>Returns the used cell.</returns>

      object AddStructure(string worksheetName, int columnIndex, int rowIndex, byte[] structure, string format, string id, bool showId);

 

      /// <summary>

      /// Adds structure to the worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Index of the column.</param>

      /// <param name="rowIndex">Index of the row.</param>

      /// <param name="structure">Binary data of the molecule.</param>

      /// <param name="format">Format of the structure.</param>

      /// <returns>Returns the used cell.</returns>

      object AddStructure(string worksheetName, int columnIndex, int rowIndex, byte[] structure, MoleculeFormat format);

 

      /// <summary>

      /// Adds structure to the worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Index of the column.</param>

      /// <param name="rowIndex">Index of the row.</param>

      /// <param name="structure">Binary data of the molecule.</param>

      /// <param name="format">Format of the structure.</param>

      /// <param name="id">ID of the molecule.</param>

      /// <param name="showId">Show the ID or the molecule.</param>

      /// <returns>Returns the used cell.</returns>

      object AddStructure(string worksheetName, int columnIndex, int rowIndex, byte[] structure, MoleculeFormat format, string id, bool showId);

 

      /// <summary>

      /// Adds structure to the worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Index of the column.</param>

      /// <param name="rowIndex">Index of the row.</param>

      /// <param name="moleculeData">MoleculeData representation of the structure.</param>

      /// <returns>Returns the used cell.</returns>

      object AddStructure(string worksheetName, int columnIndex, int rowIndex, MoleculeData moleculeData);

 

      /// <summary>

      /// Adds structure to the worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Index of the column.</param>

      /// <param name="rowIndex">Index of the row.</param>

      /// <param name="moleculeData">MoleculeData representation of the structure.</param>

      /// <param name="id">ID of the molecule.</param>

      /// <param name="showId">Show the ID or the molecule.</param>

      /// <returns>Returns the used cell.</returns>

      object AddStructure(string worksheetName, int columnIndex, int rowIndex, MoleculeData moleculeData, string id, bool showId);

 

      /// <summary>

      /// Adds structure to the worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Index of the column.</param>

      /// <param name="rowIndex">Index of the row.</param>

      /// <param name="moleculeData">Molecule.</param>

      /// <returns>Returns the used cell.</returns>

      object AddStructure(string worksheetName, int columnIndex, int rowIndex, IJChemExcelMolecule molecule);

 

      /// <summary>

      /// Adds a MoleculeMap object to the workbook.

      /// </summary>

      /// <param name="moleculeMap">The MoleculeMap object.</param>

      /// <returns>Returns the used cell.</returns>

      object AddStructure(MoleculeMap moleculeMap);

 

      /// <summary>

      /// Adds structures to the worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Index of the column.</param>

      /// <param name="startRowIndex">Start index of the rows.</param>

      /// <param name="structures">Enumeration of the string-based structures.</param>

      /// <returns>Returns the array of the used cells.</returns>

      object[] AddStructures(string worksheetName, int columnIndex, int startRowIndex, IEnumerable<string> structures);

 

      /// <summary>

      /// Adds structures to the worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Index of the column.</param>

      /// <param name="startRowIndex">Start index of the rows.</param>

      /// <param name="structures">Enumeration of the string-based structures.</param>

      /// <param name="format">Format of the structures.</param>

      /// <returns>Returns the array of the used cells.</returns>

      object[] AddStructures(string worksheetName, int columnIndex, int startRowIndex, IEnumerable<string> structures, string format);

 

      /// <summary>

      /// Adds structures to the worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Index of the column.</param>

      /// <param name="startRowIndex">Start index of the rows.</param>

      /// <param name="structures">Enumeration of the string-based structures.</param>

      /// <param name="format">Format of the structures.</param>

      /// <returns>Returns the array of the used cells.</returns>

      object[] AddStructures(string worksheetName, int columnIndex, int startRowIndex, IEnumerable<string> structures, MoleculeFormat format);

 

      /// <summary>

      /// Adds structures to the worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Index of the column.</param>

      /// <param name="startRowIndex">Start index of the rows.</param>

      /// <param name="structures">Enumeration of the binary-based structures.</param>

      /// <returns>Returns the array of the used cells.</returns>

      object[] AddStructures(string worksheetName, int columnIndex, int startRowIndex, IEnumerable<byte[]> structures);

 

      /// <summary>

      /// Adds structures to the worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Index of the column.</param>

      /// <param name="startRowIndex">Start index of the rows.</param>

      /// <param name="structures">Enumeration of the binary-based structures.</param>

      /// <param name="format">Format of the structures.</param>

      /// <returns>Returns the array of the used cells.</returns>

      object[] AddStructures(string worksheetName, int columnIndex, int startRowIndex, IEnumerable<byte[]> structures, string format);

 

      /// <summary>

      /// Adds structures to the worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Index of the column.</param>

      /// <param name="startRowIndex">Start index of the rows.</param>

      /// <param name="structures">Enumeration of the binary-based structures.</param>

      /// <param name="format">Format of the structures.</param>

      /// <returns>Returns the array of the used cells.</returns>

      object[] AddStructures(string worksheetName, int columnIndex, int startRowIndex, IEnumerable<byte[]> structures, MoleculeFormat format);

 

      /// <summary>

      /// Adds structures to the worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Index of the column.</param>

      /// <param name="startRowIndex">Start index of the rows.</param>

      /// <param name="moleculeData">Enumeration of the molecule data objects.</param>

      /// <returns>Returns the array of the used cells.</returns>

      object[] AddStructures(string worksheetName, int columnIndex, int startRowIndex, IEnumerable<MoleculeData> moleculeData);

 

      /// <summary>

      /// Adds structures to the worksheet.

      /// </summary>

      /// <param name="worksheetName">Name of the worksheet.</param>

      /// <param name="columnIndex">Index of the column.</param>

      /// <param name="startRowIndex">Start index of the rows.</param>

      /// <param name="molecules">Enumeration of the molecules.</param>

      /// <returns>Returns the array of the used cells.</returns>

      object[] AddStructures(string worksheetName, int columnIndex, int startRowIndex, IEnumerable<IJChemExcelMolecule> molecules);

 

      /// <summary>

      /// Adds a MoleculeMap objects to the workbook.

      /// </summary>

      /// <param name="moleculeMaps">Enumeration of the MoleculeMap objects.</param>

      /// <returns>Returns the array of the used cells.</returns>

      object[] AddStructures(IEnumerable<MoleculeMap> moleculeMaps);

   }

 

The IWorkbookConverter interface:

 

  public interface IWorkbookConverter : IWorkbook

   {

      /// <summary>

      /// Converts the workbook to JChem for Excel workbook.

      /// </summary>

      /// <returns>Returns the file path of the converted workbook.</returns>

      string Convert();

 

      /// <summary>

      /// Converts the workbook to JChem for Excel workbook.

      /// </summary>

      /// <param name="overwrite">Overwriting enabled or not.</param>

      /// <returns>Returns the file path of the converted workbook.</returns>

      string Convert(bool overwrite);

 

      /// <summary>

      /// Converts the workbook to JChem for Excel workbook.

      /// </summary>

      /// <param name="outputDirectoryPath">Path of the output directory.</param>

      /// <param name="overwrite">Overwriting enabled or not.</param>

      /// <returns>Returns the file path of the converted workbook.</returns>

      string Convert(string outputDirectoryPath, bool overwrite);

 

      /// <summary>

      /// Converts the workbook to JChem for Excel workbook.

      /// </summary>

      /// <param name="outputFilePath">Path of the converted workbook.</param>

      /// <param name="overwrite">Overwriting enabled or not.</param>

      /// <returns>Returns the file path of the converted workbook.</returns>

      string ConvertTo(string outputFilePath, bool overwrite);

   }

 

 

 

The IO API module contains another static class named WorkbookRecognizer. This class provides information about the workbook types by the path of the file or a stream. It can be useful in case of mixed files, e.g. when a workbook contains ISIS and ChemDraw structures together. WorkbookRecognizer gives back the list of the recognized workbook types in a file.

 

 

Examples

Here is an example for a simple workbook writing:

          // Creates an IWorkbookWriter instance for an XLSX file.

          using (IWorkbookWriter workbookWriter = WorkbookHandlerFactory.CreateWriter(@"C:\Documents\Structures.xlsx"))

           {

              // Adds 'C=C' SMILES string to the cell A1.

              // Adds 'CCC' SMILES string to the cell A2.

              // Returns an array of the used cells. (In this case these are DocumentFormat.OpenXml.Spreadsheet.Cell objects.)

              object[] cells = workbookWriter.AddStructures("Sheet1", 1, 1, new string[] { "C=C", "CCC" }, MoleculeFormat.SMILES);

           }

 

Workbook reading:

          // Creates an IWorkbookReader instance for an XLSX file.

          using (IWorkbookReader workbookReader = WorkbookHandlerFactory.CreateReader(@"C:\Documents\Structures.xlsx"))

           {

              // Reads all of the structures from the first column (column A), from the row index 1 to 10.

              MoleculeMap[] mapArray = workbookReader.GetStructures("Sheet1", 1, 1, 10);

           }

 

ISIS for Excel workbook conversion:

          // Creates an IWorkbookConverter instance for an ISIS for Excel file.

          using (IWorkbookConverter workbookConverter = WorkbookHandlerFactory.CreateConverter(@"C:\Documents\IsisForExcel.xlsx"))

           {

              // Converts the XLSX file to JChem for Excel specific file

              // and put the result file to the 'Converted files' folder.

              // The result will be located here: 'C:\Converted files\IsisForExcel_JC4XL.xlsx'

               workbookConverter.Convert(@"C:\Converted files", true);

           }

 

Workbook recognition:

          IEnumerable<WorkbookType> recognizedWorkbookTypes = WorkbookRecognizer.Recognize(@"C:\Documents\Structures.xlsx");

 

 

Under the Code_examples\C#\OpenXmlApiDemo folder a demo project is available. It illustrates the handling of an XLSX file by IO API module.

 

Do you have a question? Would you like to learn more?

Please browse among the related topics on our support forum or search the website. If you want to suggest modifications or improvements to our documentation email our support directly!