If you create an open component by the method StarDesktop.loadComponentFromURL()
you need to assign what it returns as its result to a variable, e.g. sheetDocFromCsv = ...
The component you started with is accessible via the predefined variable ThisComponent
. Generally you will have assigned it to an extra variable with a shorter name like (traditional) oDoc
or (in my case) doc0
.
If you started a Basic routine while the components you want to work with were already loaded, you can access them via = StarDesktop.Components
. You then need to indentify the one you need based on some individual “label” like the URL or a specific content or…
[edit 2021-01-20 about 14:55UTC]
It’s a puzzle for me from where you (OQer) got the code in your comment, or what guesses you applied. At least the way you try to pass the partly optional parameters to loadComponentFromURL
cannot work. There is only one array-parameter for the purpose.
Generally:
If you intend to continue with programming for LibreOffice in Basic using its API, you will need to study the famous texts by Andrew Pitonyak. I would suggest to downlad the pdf versions from the table on this page. Also try to get familiar with this API site.
Concerning the specific case there are two groups of facts you need to regard:
So-called csv-files:
There is no reliable standard. Technically such files are simply “plain text”, and LibreOffice can load each into a text document or into a spreadsheet document depending on your choice. To get the sheet you need to use a different “filter”. Beyond that you need to specify the field(column)-separators and the text-delimiters (if any). In addition there is an option for the used character set (try 0), for the first line to import (mostly 1), and for a code per column usable for datatype/formatting information. The last option position left empty will apply automatic guessing (imo).
I rarely used the filter scalc: Text - txt - csv (StarCalc)
and may have missed a lot - or be on error concerning some details.
The “shift focus” part of the question:
In fact you cannot use the ordinary moveCells
or copyRange
methods across documents.
Having opened the csv creating a new single-sheet-document in the RAM, you need to select there what you want to use in a differend spreadsheet document, and to use either the system’s clipboard (and the dispatcher) or the methods of XTransferable
to get a copy of it and to be able to insert the transferable content elsewhere.
Alternatives: Linked sheet, linked range …
I took the time to make a raw example for you consisting of an .ods
serving as the target document for the data, and containing the code as well, and a .csv
with a few data to serve as a source. Both files are zipped together and must be expanded into the same empty folder. Since the site refuses to upload .zip
I had to append a fake extension. I chose .odg
. Remove it after download.
loadCSVexample.zip.odg
[/edit]