Spreadsheet.ExportText

This function exports a spreadsheet to a text file.

Syntax Parameters Return Value
Function Spreadsheet.ExportText( _
    FileName As String, _
    Optional FirstRow As Long = 1, _
    Optional LastRow As Long = 0, _
    Optional FirstColumn As Long = 1, _
    Optional LastColumn As Long = 0, _
    Optional Separator As Integer = 9, _
    Optional UseTextLabels As Boolean = True, _
    Optional CaseNamesToFirstColumn As Boolean = False, _
    Optional VariableNamesToFirstRow As Boolean = False, _
    Optional OverWriteFile As Boolean = True) As Boolean
  • FileName [in]

The fully-qualified pathway to where the text file shall be saved.

Type: String

  • FirstRow [in,optional]

The beginning of the range of cases to export. This parameter defaults to 1.

Type: Long

Default value: 1

  • LastRow [in,optional]

The end of the range of cases to export. This parameter defaults to 0, which implies that you wish to export all of the cases.

Type: Long

Default value: 0

  • FirstColumn [in,optional]

The beginning of the range of variables to export. This parameter defaults to 1.

Type: Long

Default value: 1

  • LastColumn [in,optional]

The end of the range of variables to export. This parameter defaults to 0, which implies that you wish to export all of the variables.

Type: Long

Default value: 0

  • Separator [in,optional]

Which ASCII character code shall be used as a separator in the text file. This parameter defaults to 9, which implies a tab.

Type: Integer

Default value: 9

  • UseTextLabels [in,optional]

Type: Boolean

Default value: True

  • CaseNamesToFirstColumn [in,optional]

Type: Boolean

Default value: False

  • VariableNamesToFirstRow [in,optional]

Type: Boolean

Default value: False

  • OverWriteFile [in,optional]

Whether the output file should be overwritten if it exists.

Type: Boolean

Default value: True

Boolean

C++ Example

Exporting a Spreadsheet as Text in C++:

#include <windows.h>
#include <comdef.h> //needed for COM
//The "#import" directive imports the class library information of the
//specified file. In this case, the file "statist.exe" will give us access to the
//STATISTICA interface and its documents' library. You will either need to include
//this file in your project directory, or hard code the full path to the file in the
//#import directive. Lastly, note that "#import" is a Visual C++ compiler specific
//directive; if you are using a different compiler, then please consult your compiler's
//documentation on how to import a COM interface.
#import "statist.exe"

//Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN

#include <string>
#include <cstdio>
#include <shlobj.h>

using namespace STATISTICA;

//The following example will open Boston2.sta from the examples directory and
//export it as a text file into the same directory

int main()
    {
    //Launch STATISTICA
    //Initialize COM
    ::CoInitialize(NULL);
    //set up a pointer to a STATISTICA application
    STATISTICA::_ApplicationPtr pApp;

    //initialize a new STATISTICA object through COM
    HRESULT hr = ::CoCreateInstance(__uuidof(STATISTICA::Application),NULL,CLSCTX_SERVER,
        __uuidof(STATISTICA::_Application),reinterpret_cast<void**>(&pApp));

    //verify that COM was able to create an instance of STATISTICA
    if (FAILED(hr))
        {
        ::MessageBox(NULL,L"Unable to intialize STATISTICA",
            L"Initialization Failure",MB_ICONHAND);
        return EXIT_FAILURE;
        }

    //get the path of where Boston2.sta is from the path property of the application
    std::wstring SpreadSheetPath = pApp->Path + L"\\Examples\\Datasets\\Boston2.sta";
    //pApp is now the pointer that we use to access the application's library
    //of member methods and (public) variables.

    try
        {
        //Pass in login information to Enterprise.
        //This will need to be customized for your system.
        pApp->SWSInfo(L"Isabelle", L"password123", L"", L"", L"", L"");
        //we will save the text file to the documents folder
        TCHAR MyDocuments[MAX_PATH];
        HRESULT result = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, MyDocuments);
        std::wstring TextFilePath = MyDocuments; TextFilePath += L"\\Boston2.txt";

        _SpreadsheetPtr pSpreadsheet =
            pApp->Spreadsheets->Open(SpreadSheetPath.c_str(), true);

        //export the spreadsheet to a text file
        pSpreadsheet->ExportText(TextFilePath.c_str(),1,pSpreadsheet->NumberOfCases,1,
        pSpreadsheet->NumberOfVariables,9,true,true,true,true);
        }

    //opening and exporting documents will throw a "_com_error" exception if, for example,
    //the document file doesn't exist*/
    catch(_com_error Err)
        {
        ::MessageBox(NULL,Err.Description(),pApp->Name,MB_ICONHAND);
        }

    //clean up after the COM initialization
    pApp.Release();
    ::CoUninitialize();
    return EXIT_SUCCESS;
    }