Spreadsheet.ExportText
This function exports a spreadsheet to a text file.
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; }
Copyright © 2020. Cloud Software Group, Inc. All Rights Reserved.