66using log4net ;
77using GeneXus . Application ;
88using GeneXus . Office . Excel ;
9+ using GxClasses . Helpers ;
10+
911
1012namespace GeneXus . Office . ExcelLite
1113{
@@ -368,7 +370,16 @@ public class ExcelDocument : IGxError, IExcelDocument
368370 {
369371 static readonly ILog log = log4net . LogManager . GetLogger ( System . Reflection . MethodBase . GetCurrentMethod ( ) . DeclaringType ) ;
370372 public static string nmspace ;
373+ #if NETCORE
374+ public static string license = "FREE-LIMITED-KEY" ;
375+ const string LoadMethod = "Load" ;
376+ const string SaveMethod = "Save" ;
377+ #else
371378 public static string license ;
379+ const string LoadMethod = "LoadXls" ;
380+ const string SaveMethod = "SaveXls" ;
381+ #endif
382+
372383 public static Assembly ass ;
373384
374385 public short Init ( string previousMsgError )
@@ -381,17 +392,25 @@ public short Init(string previousMsgError)
381392 {
382393 if ( nmspace == null )
383394 {
395+ #if NETCORE
396+ ass = AssemblyLoader . LoadAssembly ( new AssemblyName ( "GemBox.Spreadsheet" ) ) ;
397+ #else
398+
384399 ass = loadAssembly ( Path . Combine ( GxContext . StaticPhysicalPath ( ) , "GemBox.Spreadsheet.dll" ) ) ;
385400 if ( ass == null )
386401 {
387402 ass = loadAssembly ( Path . Combine ( GxContext . StaticPhysicalPath ( ) , "bin" , "GemBox.Spreadsheet.dll" ) ) ;
388403 }
404+ #endif
389405 if ( ass != null )
390406 {
391407 nmspace = "GemBox.Spreadsheet" ;
392408 }
393409 else
394410 {
411+ #if NETCORE
412+ ass = AssemblyLoader . LoadAssembly ( new AssemblyName ( "GemBox.ExcelLite" ) ) ;
413+ #else
395414 if ( ass == null )
396415 {
397416 ass = loadAssembly ( Path . Combine ( GxContext . StaticPhysicalPath ( ) , @"GemBox.ExcelLite.dll" ) ) ;
@@ -400,6 +419,7 @@ public short Init(string previousMsgError)
400419 {
401420 ass = loadAssembly ( Path . Combine ( GxContext . StaticPhysicalPath ( ) , "bin" , "GemBox.ExcelLite.dll" ) ) ;
402421 }
422+ #endif
403423 if ( ass != null )
404424 {
405425 nmspace = "GemBox.ExcelLite" ;
@@ -409,11 +429,15 @@ public short Init(string previousMsgError)
409429 }
410430 else
411431 {
432+ #if NETCORE
433+ ass = AssemblyLoader . LoadAssembly ( new AssemblyName ( nmspace ) ) ;
434+ #else
412435 ass = loadAssembly ( Path . Combine ( GxContext . StaticPhysicalPath ( ) , nmspace + ".dll" ) ) ;
413436 if ( ass == null )
414437 {
415438 ass = loadAssembly ( Path . Combine ( GxContext . StaticPhysicalPath ( ) , "bin" , nmspace + ".dll" ) ) ;
416439 }
440+ #endif
417441 }
418442 GXLogging . Debug ( log , "nmspace:" + nmspace ) ;
419443
@@ -434,6 +458,7 @@ public short Init(string previousMsgError)
434458 GXLogging . Error ( log , @"Error setting license." , e ) ;
435459 }
436460 }
461+
437462 }
438463 return 0 ;
439464 }
@@ -458,7 +483,6 @@ private Assembly loadAssembly(string fileName)
458483 {
459484 return null ;
460485 }
461-
462486 }
463487 public short Open ( String fileName )
464488 {
@@ -479,7 +503,11 @@ public short Open(String fileName)
479503 if ( stream != null )
480504 {
481505 stream . Position = 0 ;
482- GxExcelUtils . Invoke ( ef , "LoadXls" , new object [ ] { stream } ) ;
506+ #if NETCORE
507+ GxExcelUtils . InvokeStatic ( ass , classType . FullName , LoadMethod , new object [ ] { stream } ) ;
508+ #else
509+ GxExcelUtils . Invoke ( ef , LoadMethod , new object [ ] { stream } ) ;
510+ #endif
483511 }
484512 }
485513 else
@@ -495,7 +523,12 @@ public short Open(String fileName)
495523 if ( stream != null )
496524 {
497525 stream . Position = 0 ;
498- GxExcelUtils . Invoke ( ef , "LoadXls" , new object [ ] { stream } ) ;
526+
527+ #if NETCORE
528+ ef = GxExcelUtils . InvokeStatic ( ass , classType . FullName , LoadMethod , new object [ ] { stream } ) ;
529+ #else
530+ GxExcelUtils . Invoke ( ef , LoadMethod , new object [ ] { stream } ) ;
531+ #endif
499532 }
500533 }
501534 else
@@ -523,8 +556,14 @@ public short Save()
523556 {
524557 GxFile file = new GxFile ( Path . GetDirectoryName ( xlsFileName ) , xlsFileName , GxFileType . Private ) ;
525558 MemoryStream content = new MemoryStream ( ) ;
526- GxExcelUtils . Invoke ( ef , "SaveXls" , new object [ ] { content } ) ;
527- content . Position = 0 ;
559+
560+ #if NETCORE
561+ object saveOption = GxExcelUtils . GetEnumValue ( ExcelDocument . ass , ExcelDocument . nmspace + ".SaveOptions" , "XlsDefault" ) ;
562+ GxExcelUtils . Invoke ( ef , SaveMethod , new object [ ] { content , saveOption } ) ;
563+ #else
564+ GxExcelUtils . Invoke ( ef , SaveMethod , new object [ ] { content } ) ;
565+ #endif
566+ content . Position = 0 ;
528567 file . Create ( content ) ;
529568 }
530569 catch ( Exception e )
0 commit comments