Macro Import .csv into Calc

Does anyone have a macro that will import a .csv file into the active sheet and append the contents either to the top or bottom of the active sheet. Appending the data to the top of the page would be preferred.

Please don’t use Answer function on this site, if you actually don’t answer a question. Use “add a comment” or “edit” your original question, if you are adding more details to support an answer to your original question .

Hello,

why to create a macro, if everything can be done without? Use Sheet -> Link to External Data, browse for your CVS file, select the options to be used for the import and it will be imported. In addition, if you add

  1. Option “Always (from trusted locations)” in Tools -> Options -> LibreOffice Calc -> General -> Cat: Updating – and
  2. the path of your file (not the .csv file) to trusted locations in Tools -> Options -> LibreOffice -> Security -> Button: Macro Security -> Tab: Trusted Sources -> Cat: Trusted File Locations

your csv data will be updated every time you open the file.

Note The data will be imported starting with the cell where your cursor was in (cell focus) when you started the Link to External Data-procedure.


Update 1: Menu Link To External Data:

Tested using LibreOffice:

Version: 6.3.0.4, Build ID: 057fc023c990d676a43019934386b85b21a9ee99
CPU threads: 8; OS: Linux 4.12; UI render: default; VCL: kde5; 
Locale: en-US (en_US.UTF-8); UI-Language: en-US, Calc: threaded  

Update 2: Menu Link To External Data in LibreOffice 6.0.7 on Ubuntu

Referring to your "Answer*: I have installed LibreOffice 6.0.7 on an Ubuntu 18.04 system and the Link to External Data is on the same menu, as in my answer above.


Update 3: Linking to External Data (.csv File) on LibreOffice 6.0.7*

The procedure described above does not work on LibreOffice 6.0.7. Use Sheet -> Insert Sheet from File ... instead and tick option Link in the related dialog to allow for automatic updates. The drawback is, that this action creates a new sheet and you cannot place the csv data to a desired cell of an existing sheet.

image description

If the answer is correct or helped you to fix your problem, please click the check mark (:heavy_check_mark:) next to the answer.

1 Like

Much thanks!! I am trying to link to a local file. The “OK” button is grayed out. I’m able to Sheet → Insert Sheet from File, but NOT Sheet—> Link to External Data.

Which LO Version are you using? Please see Update in my answer:

Referring to your "Answer*: I have installed LibreOffice 6.0.7 on an Ubuntu 18.04 system and the Link to External Data is on the same menu, as in my answer Update.

Version: 6.0.7.3 Build ID: 1:6.0.7-0ubuntu0.18.04.9 CPU threads: 4; OS: Linux 4.15; UI render: default; VCL: gtk3; Locale: en-US (en_US.UTF-8); Calc: group

Yes the “Link to External Data” is there, but when I choose a local file. It pulls up the dialog and everything looks to be going forward, but the “OK” button is grayed out. In other words, unable to link file due to not being able to click ok. I am able to “Insert Sheet from File” on the same .csv file. Did you try to link to external data with a local .csv file?

Sure - I use this for years on my documents. Are you sure you have access to your csv file?

Pretty sure access is there as I’m able to “Insert Sheet from File” on the same .csv file. Have to to work, so will try it again this evening. Thanks for all the posts.

Updated and feature works. This is a very cool feature.

Scenario:
File A is the external data that is linked to Presentation document.
File B is new data that comes in that must be copy and pasted at the next open cell of File A. Is there a way to do this in an easy fashion without having to manually copy and pasting?

No - see my answer on how it is working on newer versions of LibreOffice. And on newer version you can place the external data to start where you want 'em to start.

Please don’t forget to click the check mark (:heavy_check_mark:) next to the answer, if the answer is correct or helped you to solve your problem

All checked. Opaque, you’ve been a great help and I do thank you.