Self-updating spreadsheet - excel

Is it possible to create a spreadsheet that updates itself on a regular basis (daily, bi-weekly or monthly)? We use PostgreSQL. The content of the sheet is going to be based off a query I wrote.
What's the easiest way to connect an Excel spreadsheet to Postgres?
So far I have looked at:
A Microsoft product: https://support.office.com/en-us/article/Connect-to-a-PostgreSQL-database-Power-Query-bf941e52-066f-4911-a41f-2493c39e69e4
PostgreSQL's ODBC: https://odbc.postgresql.org/
However I can't find a clear explanation of how I am practically going to set up the spreadsheet.

A quick high-level explanation to connect excel to a database:
You can connect to a ODBC enabled DBMS's view or table using Excel's Get External Data buttons. Specifically in the Data tab, the From other Sources button.
To use this, you need to create a new DSN for your connection. Start>>"Search Box">>ODBC and use the 64-bit ODBC administrator to create a new System DSN. The DSN is the thing that will hold your ODBC connection's information, like the server address, username, password, etc...
Back in Excel you click the From Other Sources button in the Data tab and pick that DSN you just made. Then you can find the View you generated in Postgres and tell it which range you want to dump the data. That range then will hold the connection information so you can refresh any time you want.
Then, when you open the workbook you can just refresh the connection and pick up new data lickety-split.
There's other ways to connect Excel to ODBC and OLEDB enabled databases like using ADODB in VBA, but that's more complicated and probably overkill for you needs.

Related

MySQL query from excel without ODBC

Is possible to get connection to mysql server from excel macro, without downloading any ODBC connector? I have found solutions only with this connector. Problem is, that I have to send excel workbook to some people which they don't have this connector in their computer, and it will be a little problem to set it for them.
I need to make only one INSERT query.

Excel Office 365 VBA to add a new PowerQuery "Data Source"

I already have vba that modifies queries on existing data sources. But for adding new data sources (what I would call a new DB connection), I am stumped. When I try to record a macro that adds a new data source, the macro is created but there is no code generated - just an empty sub routine.
The steps I am trying to simulate are:
Click Data
Get Data From Database
[In my case, I choose Oracle, but I suppose all options are working with the same underlying VBA class of object?]
From there, you enter the server. In my case, what works is
HostName:Port/OracleUniverse
If the server is new to the machine, then it prompts you for credentials. Otherwise, it uses cached credentials.
I've attached a picture indicating where the new data source needs to appear:
Note:
I would happily switch to a traditional Windows ODBC User DSN but Oracle drivers are not available on my machine (I work for government and cannot add them).

Refreshable pivot table connected to an external source

I am planning to deploy an Excel file where the users would only need to refresh to see the updated data. I can currently do this by sending out a new Excel file every time.
What I have:
Office 365
MariaDB on Digital Ocean
What I want:
Create a pivot table/data model connected to the database and have the data updated real time upon refresh.
I can do this on my own via ODBC but when sharing the file, it asks for the credentials which is saved on my ODBC file. Ideally, I don't want to share the credentials even though it's read-only.
Is there an alternative to ODBC so I can easily share the refreshable pivot table?

Changing the Power query SQL Server database settings when moving an Excel workbook

I'm working on creating an excel report that collects data from a local copy of a SQL Server database on my maschine, where I use Power Query to retrieve the data. These are then loaded into a PowerPivot data model. Now I'm finished with the development and on my way to put this into production on another server on the customer's server. The Excel workbook must change database settings using sql server database user Connection (not integrated). I had hoped that I could change the database Connection Properties at the Data tab, but there are not any easy way to change the connection string to the new server. Now I can't see any option that going through every Power Query query and change them manually. I have great hope that you Power Query experts have a Nice explaination and an example how I can solve this.
Hope to hear from you soon
Regards Geir F
There isn't a great solution for bulk server rename today, but we're very aware of the customer demand! (I can't promise anything about upcoming features, but at some point in the past I heard the dev team discuss this feature.) I'd recommend showing your support for this feature at https://excel.uservoice.com/
If you need to solve this soon, manually opening each query and editting the server string is what you need to do, sorry :\
(If you're building new reports again, Power BI Desktop lets you parameterize the server name to a top-level query, which would allow for quick rename operations!)
Do you only need to change the server name? If you go to the Data Source Settings window, you can select the SQL Server source you are using and click on the "Change Source..." button. If you change the server name in that dialog, it will change the server name in all of the queries that use that source (assuming it's the first step in the query).

Refreshing Excel Data connection on a Windows Server

I am running an automated Data job on a windows server that outputs a SAS dataset everyday. On top of this, I have an Excel Report connected via Excel's Local Data Provider.
My problem is, that the Data Connection needs to be manually refreshed by a person with SAS installed on their PC. I have tried writing a piece of SAS code that opens the Excel file on the server and then triggers a piece of VBA that did the refreshing, before closing and saving. This works perfectly if I'm logged into the server. But it doesn't seem to work if nobody's signed in. I believe this has something to do with having an active user session.
UPDATE
The process that I use to connect to a local data source from Excel, looks like this:
Data Connection Wizard
Select SAS Local Data Provider from OLE DB Providers
Add the Route to my SAS Dataset as data source
Select My source table and create a Pivot Report
Is there any way to do something like this?
When you want to run Excel unattended, thus no interactive user is logged on, you can do this with a Windows service. You have to ensure some settings for Excel, as well as it is important how you start excel.
Be aware of Microsoft does not support, or even suggest you to do something like this. Excel is a client software, it is exactly the opposite of a piece of software that is easy to maintain running as as service. Read this excellent article Considerations for server-side Automation of Office about the topic. Even when a little old (talking about Office 2003) it is still state of the art.
Please consider these conditions:
You cannot use the System or Network account, you have to let the windows service running under an account that at least have excel started once. This cannot be done with the named ones (as they cannot be used as interactive users)
Excel has to be opened at least once with the user under with the windows service account will run. You'll have to configure dcom settings, open vba once to initialize it, and most probably set some settings like "trust vba model" to be able to programmatically access Excel
last but not least when starting Excel you have to start it with loading the user profile. The Process.Start method in c# allows exactly that by just setting a boolean value to true.
Doing it like this, Excel should just start fine and update data connection with the VBA.
You may want to implement that windows service in c#, as it is really easy, have a look: Creating a Basic Windows Service in C#.
When using c#, be aware of you have to correctly dispose interop objects, pretty good described in How to properly clean up Excel interop objects

Resources