GdPicture.NET.14
GdPicture14 Namespace / GdPictureOCR Class / SaveAsXLSX Method / SaveAsXLSX(String,Stream,Int32,SpreadsheetOptions) Method
An OCR result identifiers. It specifies the OCR result containing the table you want to save.
A Stream object where the results will be saved to. This Stream object must be initialized before it can be sent into this method and it should remain open for subsequent use.
A table index. It specifies the table you want to save.
The class that handles different options requested by a GdPictureOCR instance to export OCR result to a spreadsheet document.
Example





In This Topic
SaveAsXLSX(String,Stream,Int32,SpreadsheetOptions) Method
In This Topic
Saves the table, specified by its index, to a stream in the XLSX format.
Syntax
'Declaration
 
Public Overloads Function SaveAsXLSX( _
   ByVal OCRResultID As String, _
   ByVal Stream As Stream, _
   ByVal TableIdx As Integer, _
   Optional ByVal SpreadsheetOptions As GdPictureOCR.SpreadsheetOptions _
) As GdPictureStatus
public function SaveAsXLSX( 
    OCRResultID: String;
    Stream: Stream;
    TableIdx: Integer;
    SpreadsheetOptions: GdPictureOCR.SpreadsheetOptions
): GdPictureStatus; 
public function SaveAsXLSX( 
   OCRResultID : String,
   Stream : Stream,
   TableIdx : int,
   SpreadsheetOptions : GdPictureOCR.SpreadsheetOptions
) : GdPictureStatus;

Parameters

OCRResultID
An OCR result identifiers. It specifies the OCR result containing the table you want to save.
Stream
A Stream object where the results will be saved to. This Stream object must be initialized before it can be sent into this method and it should remain open for subsequent use.
TableIdx
A table index. It specifies the table you want to save.
SpreadsheetOptions
The class that handles different options requested by a GdPictureOCR instance to export OCR result to a spreadsheet document.

Return Value

A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK.

We strongly recommend always checking this status first.

Example
How to save a specific table to an xlsx file.
Dim caption As String = "Example: SaveAsXLSX"
Using gdpictureOCR As GdPictureOCR = New GdPictureOCR
    'Set up your prefered parameters for OCR.
    gdpictureOCR.ResourcesFolder = "\\GdPicture.Net 14\\redist\\OCR"
    If gdpictureOCR.AddLanguage(OCRLanguage.English) = GdPictureStatus.OK Then
        'Set up the image you want to process.
        Dim gdpictureImaging As GdPictureImaging = New GdPictureImaging
        'The standard open file dialog displays to allow you to select the file.
        Dim image As Integer = gdpictureImaging.CreateGdPictureImageFromFile("")
        If (gdpictureImaging.GetStat = GdPictureStatus.OK) AndAlso
           (gdpictureOCR.SetImage(image) = GdPictureStatus.OK) Then
            Dim results As List(Of String) = New List(Of String)()
 
            'Run the first OCR process.
            'Note that gdpictureOCR.OCRMode = OCRMode.FavorSpeed by default.
            Dim resID1 As String = gdpictureOCR.RunOCR
            If gdpictureOCR.GetStat = GdPictureStatus.OK Then
                'Checks if at least one table was found
                If gdpictureOCR.GetTableCount(resID1) > 0 Then
                     Dim spreadsheetOptions As GdPictureOCR.SpreadsheetOptions = New GdPictureOCR.SpreadsheetOptions() With {
                        .SeparateTables = false
                     }
                    'Save the first table.
                    Dim oStream As System.IO.FileStream = New System.IO.FileStream("OCR_result.xlsx", System.IO.FileMode.Create)
                    If gdpictureOCR.SaveAsXLSX(resID1, oStream, 0, spreadsheetOptions) = GdPictureStatus.OK Then
                        MessageBox.Show("The OCR results has been successfully saved.", caption)
                    Else
                        MessageBox.Show("The SaveAsXLSX() method has failed with the status: " + gdpictureOCR.GetStat.ToString, caption)
                    End If
                Else
                    MessageBox.Show("No table was detected on the input document")
                End If
            Else
                MessageBox.Show("The first OCR process has failed with the status: " + gdpictureOCR.GetStat.ToString, caption)
            End If
            'Release the used image.
            gdpictureImaging.ReleaseGdPictureImage(image)
        Else
            MessageBox.Show("The error occurred when setting up the image: " + gdpictureImaging.GetStat.ToString + " or " + gdpictureOCR.GetStat.ToString, caption)
        End If
        gdpictureImaging.Dispose()
    Else
        MessageBox.Show("The AddLanguage() method has failed with the status: " + gdpictureOCR.GetStat.ToString, caption)
    End If
    gdpictureOCR.ReleaseOCRResults()
End Using
string caption = "Example: SaveAsXLSX";
using (GdPictureOCR gdpictureOCR = new GdPictureOCR())
{
    //Set up your prefered parameters for OCR.
    gdpictureOCR.ResourcesFolder = "\\GdPicture.Net 14\\redist\\OCR";
    if (gdpictureOCR.AddLanguage(OCRLanguage.English) == GdPictureStatus.OK)
    {
        //Set up the image you want to process.
        GdPictureImaging gdpictureImaging = new GdPictureImaging();
        //The standard open file dialog displays to allow you to select the file.
        int image = gdpictureImaging.CreateGdPictureImageFromFile("");
        if ((gdpictureImaging.GetStat() == GdPictureStatus.OK) &&
            (gdpictureOCR.SetImage(image) == GdPictureStatus.OK))
        {
            //Run the OCR process.
            //Note that gdpictureOCR.OCRMode = OCRMode.FavorSpeed by default.
            string resID1 = gdpictureOCR.RunOCR();
            if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
            {
                //Checks if at least one table was found
                if (gdpictureOCR.GetTableCount(resID1) > 0)
                {
                    GdPictureOCR.SpreadsheetOptions spreadsheetOptions = new GdPictureOCR.SpreadsheetOptions()
                    {
                        SeparateTables = false
                    };
                    
                    //Save the first table.
                    System.IO.FileStream oStream = new System.IO.FileStream("OCR_result.xlsx", System.IO.FileMode.Create);
                    if (gdpictureOCR.SaveAsXLSX(resID1, oStream, 0, spreadsheetOptions) == GdPictureStatus.OK)
                         MessageBox.Show("The table has been successfully saved.", caption);
                    else
                        MessageBox.Show("The SaveAsXLSX() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
                }
                else
                    MessageBox.Show("No table was detected on the input document");
            }
            else
                MessageBox.Show("The first OCR process has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
 
            //Release the used image.
            gdpictureImaging.ReleaseGdPictureImage(image);
        }
        else
            MessageBox.Show("The error occurred when setting up the image: " + gdpictureImaging.GetStat().ToString() + " or " + gdpictureOCR.GetStat().ToString(), caption);
        gdpictureImaging.Dispose();
    }
    else
        MessageBox.Show("The AddLanguage() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
    gdpictureOCR.ReleaseOCRResults();
}
See Also