From: Antti Villberg Date: Mon, 6 Apr 2020 13:53:28 +0000 (+0300) Subject: SimanticsExcel interface refresh X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=0c128e8f1ce1dd42d4375b0f91e4e93f02214ccf SimanticsExcel interface refresh gitlab #514 Change-Id: I9c205730f0cbfb8d75f88c69483155dd8cafd4b2 --- diff --git a/bundles/org.simantics.excel/SimanticsExcel_64.dll b/bundles/org.simantics.excel/SimanticsExcel_64.dll new file mode 100644 index 000000000..9be7f04fe Binary files /dev/null and b/bundles/org.simantics.excel/SimanticsExcel_64.dll differ diff --git a/bundles/org.simantics.excel/build.properties b/bundles/org.simantics.excel/build.properties index 9a56e9b7e..4f7390681 100644 --- a/bundles/org.simantics.excel/build.properties +++ b/bundles/org.simantics.excel/build.properties @@ -13,4 +13,5 @@ source.. = src/ output.. = bin/ bin.includes = META-INF/,\ .,\ - SimanticsExcel.dll + SimanticsExcel.dll,\ + scl/ diff --git a/bundles/org.simantics.excel/native/Interface.cpp b/bundles/org.simantics.excel/native/Interface.cpp index 46f894c63..9e67f4aa8 100644 --- a/bundles/org.simantics.excel/native/Interface.cpp +++ b/bundles/org.simantics.excel/native/Interface.cpp @@ -1,31 +1,21 @@ -//#include "stdafx.h" - -//#ifndef _UNICODE -//#define _UNICODE -//#endif - #include #include -//#include -//#include +#include +#include +#include +#include using namespace std; -#import "c:/program files (x86)/common files/microsoft shared/office12/mso.dll" \ - rename( "RGB", "MSORGB" ) - -using namespace Office; - -#import "c:/program files (x86)/common files/microsoft shared/vba/vba6/vbe6ext.olb" \ - -using namespace VBIDE; +// mso.dll +#import "libid:{2df8d04c-5bfa-101b-bde5-00aa0044de52}" auto_rename +// vb6ext.olb +#import "libid:{0002e157-0000-0000-c000-000000000046}" auto_rename +// excel.exe +#import "libid:{00020813-0000-0000-c000-000000000046}" auto_rename -#import "c:/program files (x86)/microsoft office/office12/excel.exe" \ - rename( "DialogBox", "ExcelDialogBox" ) \ - rename( "RGB", "ExcelRGB" ) \ - rename( "CopyFile", "ExcelCopyFile" ) \ - rename( "ReplaceText", "ExcelReplaceText" ) +using namespace Excel; #include "jni2.h" @@ -34,10 +24,10 @@ using namespace VBIDE; #define SIMANTICS_DEBUG(...) -using namespace std; -using namespace Excel; +//using namespace std; +//using namespace Office; -map handles; +map handles; static int handleCounter = 1; void replace(std::string &s, const std::string &s1, const std::string &s2) { @@ -464,7 +454,7 @@ JNIEXPORT jint JNICALL Java_org_simantics_excel_Excel_close(JNIEnv *env, jobject } -/** + JNIEXPORT jdouble JNICALL Java_org_simantics_excel_Excel_getDouble(JNIEnv *env, jobject, jint handle, jint row, jint column) { SIMANTICS_DEBUG("getDouble(%d, %d)\r\n", row, column); @@ -489,7 +479,7 @@ JNIEXPORT jdouble JNICALL Java_org_simantics_excel_Excel_getDouble(JNIEnv *env, } JNIEXPORT jstring JNICALL Java_org_simantics_excel_Excel_getString(JNIEnv *env, jobject, jint handle, jint row, jint column) { - + USES_CONVERSION; //string val = getString(env, value); SIMANTICS_DEBUG("getString(%d, %d)\r\n", row, column); @@ -499,30 +489,30 @@ JNIEXPORT jstring JNICALL Java_org_simantics_excel_Excel_getString(JNIEnv *env, Excel::RangePtr range = sheet->Cells; if(!range) return NULL; - variant_t val = range->Item[row+1][column+1]; - if (val.vt != VT_NULL) { // val.vt seems to be always VT_DISPATCH. - try { + _bstr_t val = _bstr_t(range->Item[row + 1][column + 1]); + //if (val.vt != VT_NULL) { // val.vt seems to be always VT_DISPATCH. + //try { //this call will crash the application, if the cell is empty! - _bstr_t bstrt = val; - TCHAR text[1024]; + //_bstr_t bstrt = val; + //std::string text(val); + //CString text(val); + //text. + //TCHAR text[1024]; // TODO: this uses wide character (16-bit) while NewStringUTF expext regular character (8-bit), hence Java gets only the fisrt charater of the whole string. - _stprintf(text, _T("%s"), (LPCTSTR)bstrt); + //_stprintf(text, _T("%s"), (LPCTSTR)bstrt); //const char *text = bstrt; SIMANTICS_DEBUG("%s\r\n",text); - - // this code returns "??" for all cells. - //BSTR bstr = val.bstrVal; - //const char *text = _com_util::ConvertBSTRToString(bstr); - jstring ret = env->NewStringUTF((const char*)text); - delete[] text; - return ret; - } catch (...) { - return NULL; - } - } - SIMANTICS_DEBUG("%d\r\n",val.vt); - return NULL; + string text(val); + + + return env->NewStringUTF(text.c_str()); + + //} catch (...) { + // return NULL; + //} + //} + //SIMANTICS_DEBUG("%d\r\n",val.vt); + //return NULL; } -*/ \ No newline at end of file diff --git a/bundles/org.simantics.excel/native/SimanticsExcel.sln b/bundles/org.simantics.excel/native/SimanticsExcel.sln index 59c24ad34..bb04a663d 100644 --- a/bundles/org.simantics.excel/native/SimanticsExcel.sln +++ b/bundles/org.simantics.excel/native/SimanticsExcel.sln @@ -1,7 +1,9 @@  -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SimanticsExcel", "SimanticsExcel.vcproj", "{E106958A-412F-4782-81CD-DF380D66BA6B}" +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.40629.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SimanticsExcel", "SimanticsExcel.vcxproj", "{E106958A-412F-4782-81CD-DF380D66BA6B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -11,8 +13,8 @@ Global GlobalSection(ProjectConfigurationPlatforms) = postSolution {E106958A-412F-4782-81CD-DF380D66BA6B}.Debug|Win32.ActiveCfg = Debug|Win32 {E106958A-412F-4782-81CD-DF380D66BA6B}.Debug|Win32.Build.0 = Debug|Win32 - {E106958A-412F-4782-81CD-DF380D66BA6B}.Release|Win32.ActiveCfg = Release|Win32 - {E106958A-412F-4782-81CD-DF380D66BA6B}.Release|Win32.Build.0 = Release|Win32 + {E106958A-412F-4782-81CD-DF380D66BA6B}.Release|Win32.ActiveCfg = Release|x64 + {E106958A-412F-4782-81CD-DF380D66BA6B}.Release|Win32.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/bundles/org.simantics.excel/native/SimanticsExcel.vcxproj b/bundles/org.simantics.excel/native/SimanticsExcel.vcxproj index 77b342183..67c676b43 100644 --- a/bundles/org.simantics.excel/native/SimanticsExcel.vcxproj +++ b/bundles/org.simantics.excel/native/SimanticsExcel.vcxproj @@ -1,14 +1,22 @@  - + Debug Win32 + + Debug + x64 + Release Win32 + + Release + x64 + {E106958A-412F-4782-81CD-DF380D66BA6B} @@ -18,12 +26,27 @@ DynamicLibrary + v120 + false + Unicode + true + + + DynamicLibrary + v120 false Unicode true DynamicLibrary + v120 + false + Unicode + + + DynamicLibrary + v120 false Unicode @@ -33,20 +56,38 @@ + + + + + + - <_ProjectFileVersion>10.0.40219.1 - $(SolutionDir)$(Configuration)\ - $(Configuration)\ - true - false - $(SolutionDir)$(Configuration)\ - $(Configuration)\ - false - false + <_ProjectFileVersion>12.0.30501.0 + + + $(SolutionDir)$(Configuration)\ + $(Configuration)\ + true + false + + + true + false + + + $(SolutionDir)$(Configuration)\ + $(Configuration)\ + false + false + + + false + false @@ -60,8 +101,7 @@ EnableFastChecks MultiThreadedDebugDLL true - - + Level3 EditAndContinue @@ -78,7 +118,64 @@ MachineX86 + + + _DEBUG;%(PreprocessorDefinitions) + false + + + Disabled + WIN32;_WINDOWS;_DEBUG;_USRDLL;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebugDLL + true + + + Level3 + ProgramDatabase + + + _DEBUG;%(PreprocessorDefinitions) + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + + + LinkVerboseLib + .\SimanticsExcel.def + true + Windows + + + + NDEBUG;%(PreprocessorDefinitions) + false + + + MaxSpeed + true + WIN32;_WINDOWS;NDEBUG;_USRDLL;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + Level3 + ProgramDatabase + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + + + .\SimanticsExcel.def + true + Windows + true + true + MachineX86 + + + NDEBUG;%(PreprocessorDefinitions) false @@ -105,7 +202,6 @@ Windows true true - MachineX86 @@ -113,12 +209,11 @@ - - - + + @@ -127,6 +222,9 @@ + + + diff --git a/bundles/org.simantics.excel/native/jni2.h b/bundles/org.simantics.excel/native/jni2.h index d2c7715f0..ba3eeec8b 100644 --- a/bundles/org.simantics.excel/native/jni2.h +++ b/bundles/org.simantics.excel/native/jni2.h @@ -14,9 +14,8 @@ JNIEXPORT jint JNICALL Java_org_simantics_excel_Excel_setString(JNIEnv *env, job JNIEXPORT jint JNICALL Java_org_simantics_excel_Excel_setName(JNIEnv *env, jobject, jint handle, jint row, jint column, jstring value); JNIEXPORT jint JNICALL Java_org_simantics_excel_Excel_setVisible(JNIEnv *env, jobject, jint handle, jboolean value); JNIEXPORT jint JNICALL Java_org_simantics_excel_Excel_close(JNIEnv *env, jobject, jint handle); - -//JNIEXPORT jstring JNICALL Java_org_simantics_excel_Excel_getString(JNIEnv *env, jobject, jint handle, jint row, jint column); -//JNIEXPORT jdouble JNICALL Java_org_simantics_excel_Excel_getDouble(JNIEnv *env, jobject, jint handle, jint row, jint column); +JNIEXPORT jstring JNICALL Java_org_simantics_excel_Excel_getString(JNIEnv *env, jobject, jint handle, jint row, jint column); +JNIEXPORT jdouble JNICALL Java_org_simantics_excel_Excel_getDouble(JNIEnv *env, jobject, jint handle, jint row, jint column); #ifdef __cplusplus } diff --git a/bundles/org.simantics.excel/scl/Excel.scl b/bundles/org.simantics.excel/scl/Excel.scl new file mode 100644 index 000000000..4314025ed --- /dev/null +++ b/bundles/org.simantics.excel/scl/Excel.scl @@ -0,0 +1,19 @@ +importJava "org.simantics.excel.Excel" where + + data Excel + + @JavaName "getInstance" + excelInstance :: () -> Excel + + @JavaName "open2_" + openExcelSheet :: Excel -> String -> String -> Integer + @JavaName "close_" + closeExcelSheet :: Excel -> Integer -> () + @JavaName "setString_" + setExcelString :: Excel -> Integer -> Integer -> Integer -> String -> Integer + @JavaName "getString_" + getExcelString :: Excel -> Integer -> Integer -> Integer -> String + @JavaName "setDouble_" + setExcelDouble :: Excel -> Integer -> Integer -> Integer -> Double -> Integer + @JavaName "getDouble_" + getExcelDouble :: Excel -> Integer -> Integer -> Integer -> Double diff --git a/bundles/org.simantics.excel/src/org/simantics/excel/Excel.java b/bundles/org.simantics.excel/src/org/simantics/excel/Excel.java index bf7ddb5d5..d692206bd 100644 --- a/bundles/org.simantics.excel/src/org/simantics/excel/Excel.java +++ b/bundles/org.simantics.excel/src/org/simantics/excel/Excel.java @@ -45,6 +45,10 @@ public class Excel { private static Excel instance; + public static Excel getInstance() throws ExcelException { + return getInstance(System.out); + } + public static Excel getInstance(PrintStream out) throws ExcelException { if(instance == null) { @@ -89,11 +93,11 @@ public class Excel { File extractDir = context.getDataFile(""); if (extractDir == null) - throw new IOException("Bundle '" + Activator.PLUGIN_ID + " context has no file system support. Cannot extract server executables."); + throw new IOException("Bundle '" + Activator.PLUGIN_ID + " context has no file system support. Cannot extract DLLs."); if (!extractDir.exists()) if (!extractDir.mkdir()) - throw new IOException("Could not create directory '" + extractDir.getCanonicalPath() + "' for storing Balas solver data."); + throw new IOException("Could not create directory '" + extractDir.getCanonicalPath() + "' for communicating with Excel."); return extractDir; @@ -266,7 +270,7 @@ public class Excel { if (!extractDir.exists()) if (!extractDir.mkdir()) - throw new IOException("Could not create directory '" + extractDir.getCanonicalPath() + "' for storing Balas solver data."); + throw new IOException("Could not create directory '" + extractDir.getCanonicalPath() + "' for communicating with Excel."); String asd = ""; ExecEnvironment env = ExecEnvironment.calculate(); @@ -306,8 +310,8 @@ public class Excel { private native int setVisible(int handle, boolean value); private native int close(int handle); -// private native double getDouble(int handle, int row, int column); -// private native String getString(int handle, int row, int column); + private native double getDouble(int handle, int row, int column); + private native String getString(int handle, int row, int column); final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); @@ -331,6 +335,20 @@ public class Excel { }); } + public int open2_(final String fileName, final String sheetName) { + try { + return scheduler.submit(new Callable() { + @Override + public Integer call() throws Exception { + return Integer.parseInt(open(fileName, sheetName)); + } + }).get(); + } catch (Exception e) { + e.printStackTrace(); + return -1; + } + } + public String open_(final String fileName, final String sheetName) { try { return scheduler.submit(new Callable() { @@ -437,32 +455,32 @@ public class Excel { } } -// public double getDouble_(final int handle, final int row, final int column) { -// try { -// return scheduler.submit(new Callable() { -// @Override -// public Double call() throws Exception { -// return getDouble(handle, row, column); -// } -// }).get(); -// } catch (Exception e) { -// e.printStackTrace(); -// return Double.NaN; -// } -// } -// -// public String getString_(final int handle, final int row, final int column) { -// try { -// return scheduler.submit(new Callable() { -// @Override -// public String call() throws Exception { -// return getString(handle, row, column); -// } -// }).get(); -// } catch (Exception e) { -// e.printStackTrace(); -// return null; -// } -// } + public double getDouble_(final int handle, final int row, final int column) { + try { + return scheduler.submit(new Callable() { + @Override + public Double call() throws Exception { + return getDouble(handle, row, column); + } + }).get(); + } catch (Exception e) { + e.printStackTrace(); + return Double.NaN; + } + } + + public String getString_(final int handle, final int row, final int column) { + try { + return scheduler.submit(new Callable() { + @Override + public String call() throws Exception { + return getString(handle, row, column); + } + }).get(); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } }