Trying to make a macro

Good evening:

I try to make a macro in Calc to insert a sheet from a file in .txt
format or .csv using the LO process: Record macro.

I did it but the macro run and stop in the directory where the file is,
but not record the select and not open the sheet although I did when I
recorded the macro.

The code that the process wrotten is this, would you please guide me to
finish:

REM ***** BASIC *****

sub Main
rem

Hola jorge : )

On Sat, 27 Aug 2016 05:47:09 +0000, jorge escribió:

Good evening:

' Afternoon.
I'm also interested in importing .txt files into a spreadsheet adequately.

I try to make a macro in Calc to insert a sheet from a file in .txt
format or .csv using the LO process: Record macro.

Mm. A question: are you trying to make a macro because you plan to be
importing a file regularly or is it just a one-time import?

Or are you trying to import it as an exercise on how to make macros?

I did it but the macro run and stop in the directory where the file is,
but not record the select and not open the sheet although I did when I
recorded the macro.

I notice that you call your .csv file a "sheet" and I think it is not
a sheet, yet, but a text file.

The code that the process wrotten is this, would you please guide me to
finish:

I'm afraid I am not that familiar yet with macros, but it seems to me that
at some point the macro will ask you to select which file to import, right?
That is, a dilague window will appear to let you choose the kind of import
(separators, ...) ... Wait, I cannot find an "Import" option in
menus. : ! ?

Let's see:

REM ***** BASIC *****

sub Main
rem
----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem
----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem
----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:InsertSheetFromFile", "",
0, Array())

end sub

There, at the end you have a ".uno:InsertSheetFromFile"

¿How did you manage to "import" a file into your worksheet? I've only
managed it _opening_ a new file which is a .cvs file. And then the import
dialogue appears, I choose the options and the .csv file is correctly
imported into a worksheet.

As I say I'm not familiar with macros and don't know how that is done. But
It seems to me that perhaps you have to open a file instead of trying to
import it : ?

I hope someone who already does what you want illustrates us on what is to
be done and how.

I use LibreOffice version 4.2.8.2 on Ubuntu 14.04 LTS

I'm using LO Versión: 4.3.3.2 on Debian GNU/Linux 8.5.

Felipe : )

Hola Jorge : )

On Sun, 28 Aug 2016 14:08:53 +0200, Felipe escribió:

I notice that you call your .csv file a "sheet" and I think it is not
a sheet, yet, but a text file.

I found the "Import" sheet option in the menus. I found it in "Insertar" >
"Hoja de archivo", which in English should be: "Insert" > "Sheet file" or
"Worksheet"

I think this may be confusing: I saved the imported .csv file to disk and
the original .csv file is 1278 bytes long whereas the .ods is 34912 bytes
long.

-rw-r--r-- 1 philip philip 1278 ago 28 13:41 text_file.csv
-rw-r--r-- 1 philip philip 34912 ago 28 14:12 text_file.ods

They cannot be "the same". Either the program or the translation of the
menu is wrong. Inserting a file equals to importing it, fine. But calling
a .csv file a "sheet" might create confusion. And on top of that trying to
include this in a macro will surely confuse even more.

Could some of you who use LO Calc in English tell me/us what the original
menu says, please?

Thanks a lot.

Felipe : )

On Sun, 28 Aug 2016 14:08:53 +0200, Felipe escribió:

> I notice that you call your .csv file a "sheet" and I think it is not
> a sheet, yet, but a text file.

I found the "Import" sheet option in the menus. I found it in "Insertar" >
"Hoja de archivo", which in English should be: "Insert" > "Sheet file" or
"Worksheet"

My LO Calc has both Insert > Sheet ... and Insert > Sheet From File ...

I think this may be confusing: I saved the imported .csv file to disk and
the original .csv file is 1278 bytes long whereas the .ods is 34912 bytes
long.

-rw-r--r-- 1 philip philip 1278 ago 28 13:41 text_file.csv
-rw-r--r-- 1 philip philip 34912 ago 28 14:12 text_file.ods

They cannot be "the same". Either the program or the translation of the
menu is wrong. Inserting a file equals to importing it, fine. But calling
a .csv file a "sheet" might create confusion. And on top of that trying to
include this in a macro will surely confuse even more.

It seems natural that a .ods file will be bigger than a .csv file that contains the same data corresponding to a single sheet, since the .ods file has a lot of extra overhead.

I haven't been following this thread so I might have missed the point.

- Robert

Hi Felipe:

I interested in make a macro like this because I've had in past jobs to
work with files generated with other system in .txt format. They are a
lot and I had to open and got their data to paste on a spreadsheat for
working with them. Those files generated each month with the same
structure but different information. I could make a macro where I put
the generic name of each file for getting that information. I could
change the name of files generated each month with a program to allow
change names of file in group (To put the generic name that I input in
the macro).

This is why I want to know how make this macro,

Regards,

Jorge Rodríguez