Hi,
cfile:="d:\tmp\my.xls")
if (oCalc := SunCalcObj()) <> nil
oDesktop := oCalc:CreateInstance( "com.sun.star.frame.Desktop" )
aprop:={}
AAdd(aProp,GetPropertyValue(oCalc, "Hidden", .T. ) )
oBook := oDesktop:LoadComponentFromURL(ALLTRIM(cfile) , "_blank", 0, aprop )
oSheet := oBook:GetSheets():GetByIndex( 0 )
end
// LoadComponentFromURL(ALLTRIM(cfile), argument error
Tks !
Shuming Wang
Ocalc:how to open an exist file?
-
ShumingWang
- Posts: 477
- Joined: Sun Oct 30, 2005 6:37 am
- Location: Guangzhou(Canton),China
- Contact:
Ocalc:how to open an exist file?
http://www.xtech2.top
Mobile:(86)13802729058
Email:[email protected]
QQ:100200651
Weixin: qq100200651
Mobile:(86)13802729058
Email:[email protected]
QQ:100200651
Weixin: qq100200651
- Antonio Linares
- Site Admin
- Posts: 44515
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
-
ShumingWang
- Posts: 477
- Joined: Sun Oct 30, 2005 6:37 am
- Location: Guangzhou(Canton),China
- Contact:
Re: Ocalc:how to open an exist file?
Thank you! But I can't open this China mainland forbidden site.
Shuming Wang
Shuming Wang
http://www.xtech2.top
Mobile:(86)13802729058
Email:[email protected]
QQ:100200651
Weixin: qq100200651
Mobile:(86)13802729058
Email:[email protected]
QQ:100200651
Weixin: qq100200651
Re: Ocalc:how to open an exist file?
Code: Select all | Expand
cfile := "d:\tmp\my.xls" )
IF ( oCalc := SunCalcObj() ) <> nil
oDesktop := oCalc:CreateInstance( "com.sun.star.frame.Desktop" )
aprop := {}
AAdd( aProp, GetPropertyValue( oCalc, "Hidden", .T. ) )
oBook := oDesktop:LoadComponentFromURL( AllTrim( cfile ), "_blank", 0, aprop )
oSheet := oBook:GetSheets():GetByIndex( 0 )
END
// LoadComponentFromURL(ALLTRIM(cfile), argument error
The error LoadComponentFromURL( AllTrim( cfile ), argument error in your CODE suggests an issue WITH the arguments passed TO the LoadComponentFromURL METHOD in the OpenOffice / LibreOffice Basic ( StarBasic ) or Automation context. This METHOD is used TO load a document ( in this CASE, an Excel FILE my.xls ) into the office suite. Let's analyze the issue and provide a solution.
Problem Analysis
The LoadComponentFromURL METHOD has the following signature:
vb
oDesktop:LoadComponentFromURL( sURL, sTargetFrameName, nSearchFlags, aArgs )
sURL: The FILE PATH converted TO a URL FORMAT ( e .g., file:// /d:/tmp/my.xls).
sTargetFrameName: The name of the frame where the document should be loaded ( e .g., "_blank" FOR a NEW frame ).
nSearchFlags: An integer specifying search options ( usually 0 FOR no special flags ).
aArgs: An array of property values ( e .g., FOR options LIKE Hidden ).
The error likely stems FROM one of the following issues:
Invalid URL format: The FILE PATH d:\tmp\my.xls needs TO be converted TO a proper file:// URL format.
Incorrect array FOR aProp: The aProp array may not be correctly structured or may contain invalid property values.
CASE sensitivity or METHOD availability: The METHOD or property names might be case - sensitive or not properly initialized.
FILE PATH issues: The FILE PATH may not exist, or there may be permission issues.
Corrected CODE
Here's a corrected version of your code, addressing the potential issues:
vb
cfile := "file:///d:/tmp/my.xls" // Convert to file URL format
IF ( oCalc := SunCalcObj() ) <> nil
oDesktop := oCalc:CreateInstance( "com.sun.star.frame.Desktop" )
aProp := {} // Array for properties
AAdd( aProp, GetPropertyValue( oCalc, "Hidden", .T. ) ) // Add Hidden property
oBook := oDesktop:LoadComponentFromURL( cfile, "_blank", 0, aProp )
IF oBook <> nil
oSheet := oBook:GetSheets():GetByIndex( 0 )
ELSE
MsgBox( "Failed to load the document!" )
ENDIF
ENDIF
KEY Fixes and Explanations
FILE URL Format:
Changed cfile := "d:\tmp\my.xls" TO cfile := "file:///d:/tmp/my.xls". The LoadComponentFromURL METHOD requires a proper URL FORMAT. FOR LOCAL files, USE file:// / followed by the path, with forward slashes (/) instead of backslashes (\).
Example: d:\tmp\my.xls becomes file:// /d:/tmp/my.xls.
Trimming the FILE Path:
The original CODE used AllTrim( cfile ). Ensure that cfile does not have leading / trailing spaces. However, since the FILE PATH is hardcoded, ALLTRIM may not be necessary unless cfile is dynamically generated.
Property Array ( aProp ):
The GetPropertyValue FUNCTION is assumed TO CREATE a com .sun. star .beans. PropertyValue STRUCTURE. Ensure this FUNCTION is correctly defined. A typical implementation looks LIKE this:
vb
FUNCTION GetPropertyValue( oService, sName As String, vValue As Variant ) As Object
Dim oProp As Object
oProp = oService.CreateInstance( "com.sun.star.beans.PropertyValue" )
oProp.Name = sName
oProp.Value = vValue
GetPropertyValue = oProp
End Function
The Hidden property SET TO .T. ( true ) ensures the document is loaded without displaying the UI, which is VALID FOR background processing.
Error Handling:
Added a CHECK TO ensure oBook is not NIL before accessing the sheets. This helps catch errors IF the document fails TO load ( e .g., FILE not found or invalid format ).
CASE Sensitivity:
Ensure METHOD and service names LIKE com .sun. star .frame. Desktop and LoadComponentFromURL match exactly, as OpenOffice / LibreOffice APIs are case - sensitive.
Additional Considerations
FILE Existence: Verify that the FILE d:\tmp\my.xls exists and is accessible. IF the FILE is missing or the PATH is incorrect, the METHOD will fail.
FILE Format: Ensure my.xls is a VALID Excel FILE compatible WITH OpenOffice / LibreOffice. IF it's a newer .xlsx FORMAT, ensure the office suite supports it.
Permissions: CONFIRM that the application has READ permissions FOR d:\tmp\my .xls.
SunCalcObj: The SunCalcObj FUNCTION is assumed TO RETURN a VALID service manager object. Ensure it is correctly implemented and returns a non - NIL object.
Debugging: IF the error persists, add error handling TO capture the specific exception:
vb
Try
oBook := oDesktop:LoadComponentFromURL( cfile, "_blank", 0, aProp )
Catch e
MsgBox( "Error loading document: " + e.Message )
End Try
Testing the CODE
Verify the FILE PATH and convert it TO a file:// / URL.
Ensure the GetPropertyValue FUNCTION is correctly defined.
RUN the CODE in an environment WITH OpenOffice / LibreOffice installed.
CHECK the CONSOLE or MESSAGE BOX FOR any error messages.
IF you still encounter issues, please provide:
The EXACT error MESSAGE.
The definition of the SunCalcObj and GetPropertyValue functions.
Details about the environment ( e .g., OpenOffice or LibreOffice version ).
This should resolve the argument error and allow the document TO load correctly.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Re: Ocalc:how to open an exist file?
I copy paste for you from Grok:ShumingWang wrote: Sun Jul 06, 2025 9:02 am Thank you! But I can't open this China mainland forbidden site.
Shuming Wang
The error LoadComponentFromURL(ALLTRIM(cfile), argument error in your code suggests an issue with the arguments passed to the LoadComponentFromURL method in the OpenOffice/LibreOffice Basic (StarBasic) or Automation context. This method is used to load a document (in this case, an Excel file my.xls) into the office suite. Let’s analyze the issue and provide a solution.
Problem Analysis
The LoadComponentFromURL method has the following signature:
Code: Select all | Expand
vb
oDesktop:LoadComponentFromURL(sURL, sTargetFrameName, nSearchFlags, aArgs)
- sURL: The file path converted to a URL format (e.g., file:///d:/tmp/my.xls).
- sTargetFrameName: The name of the frame where the document should be loaded (e.g., "_blank" for a new frame).
- nSearchFlags: An integer specifying search options (usually 0 for no special flags).
- aArgs: An array of property values (e.g., for options like Hidden).
- Invalid URL format: The file path d:\tmp\my.xls needs to be converted to a proper file:// URL format.
- Incorrect array for aProp: The aProp array may not be correctly structured or may contain invalid property values.
- Case sensitivity or method availability: The method or property names might be case-sensitive or not properly initialized.
- File path issues: The file path may not exist, or there may be permission issues.
Corrected Code
Here’s a corrected version of your code, addressing the potential issues:
Code: Select all | Expand
vb
cfile := "file:///d:/tmp/my.xls" // Convert to file URL format
if (oCalc := SunCalcObj()) <> nil
oDesktop := oCalc:CreateInstance("com.sun.star.frame.Desktop")
aProp := {} // Array for properties
AAdd(aProp, GetPropertyValue(oCalc, "Hidden", .T.)) // Add Hidden property
oBook := oDesktop:LoadComponentFromURL(cfile, "_blank", 0, aProp)
if oBook <> nil
oSheet := oBook:GetSheets():GetByIndex(0)
else
MsgBox("Failed to load the document!")
endif
endif
- File URL Format:
- Changed cfile := "d:\tmp\my.xls" to cfile := "file:///d:/tmp/my.xls". The LoadComponentFromURL method requires a proper URL format. For local files, use file:/// followed by the path, with forward slashes (/) instead of backslashes (\).
- Example: d:\tmp\my.xls becomes file:///d:/tmp/my.xls.
- Trimming the File Path:
- The original code used ALLTRIM(cfile). Ensure that cfile does not have leading/trailing spaces. However, since the file path is hardcoded, ALLTRIM may not be necessary unless cfile is dynamically generated.
- Property Array (aProp):
- The GetPropertyValue function is assumed to create a com.sun.star.beans.PropertyValue structure. Ensure this function is correctly defined. A typical implementation looks like this:
Code: Select all | Expand
vb Function GetPropertyValue(oService, sName As String, vValue As Variant) As Object Dim oProp As Object oProp = oService.CreateInstance("com.sun.star.beans.PropertyValue") oProp.Name = sName oProp.Value = vValue GetPropertyValue = oProp End Function - The Hidden property set to .T. (true) ensures the document is loaded without displaying the UI, which is valid for background processing.
- The GetPropertyValue function is assumed to create a com.sun.star.beans.PropertyValue structure. Ensure this function is correctly defined. A typical implementation looks like this:
- Added a check to ensure oBook is not nil before accessing the sheets. This helps catch errors if the document fails to load (e.g., file not found or invalid format).
- Ensure method and service names like com.sun.star.frame.Desktop and LoadComponentFromURL match exactly, as OpenOffice/LibreOffice APIs are case-sensitive.
- File Existence: Verify that the file d:\tmp\my.xls exists and is accessible. If the file is missing or the path is incorrect, the method will fail.
- File Format: Ensure my.xls is a valid Excel file compatible with OpenOffice/LibreOffice. If it’s a newer .xlsx format, ensure the office suite supports it.
- Permissions: Confirm that the application has read permissions for d:\tmp\my.xls.
- SunCalcObj: The SunCalcObj function is assumed to return a valid service manager object. Ensure it is correctly implemented and returns a non-nil object.
- Debugging: If the error persists, add error handling to capture the specific exception:
Code: Select all | Expand
vb Try oBook := oDesktop:LoadComponentFromURL(cfile, "_blank", 0, aProp) Catch e MsgBox("Error loading document: " + e.Message) End Try
- Verify the file path and convert it to a file:/// URL.
- Ensure the GetPropertyValue function is correctly defined.
- Run the code in an environment with OpenOffice/LibreOffice installed.
- Check the console or message box for any error messages.
- The exact error message.
- The definition of the SunCalcObj and GetPropertyValue functions.
- Details about the environment (e.g., OpenOffice or LibreOffice version).
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
BCC5.82/BCC7.3
xHarbour/Harbour
-
ShumingWang
- Posts: 477
- Joined: Sun Oct 30, 2005 6:37 am
- Location: Guangzhou(Canton),China
- Contact:
Re: Ocalc:how to open an exist file?
It works!
cfile:="file:///"+StrTran(Alltrim(cfile),"\","/")
// can convert like "d:\tmp\file1.xls" , "\\127.0.0.1\tmp\file1.xls" into url .
Thank Antonio,karinha,hua!
Shuming Wang
cfile:="file:///"+StrTran(Alltrim(cfile),"\","/")
// can convert like "d:\tmp\file1.xls" , "\\127.0.0.1\tmp\file1.xls" into url .
Thank Antonio,karinha,hua!
Shuming Wang
http://www.xtech2.top
Mobile:(86)13802729058
Email:[email protected]
QQ:100200651
Weixin: qq100200651
Mobile:(86)13802729058
Email:[email protected]
QQ:100200651
Weixin: qq100200651