I think it works. I have done something similar in the past with one enhancement:-
Use an excel sheet as a template to drive your code. Your user should be able to create a template excel file with multiple sheets. Each sheet should have a SQL statement on the first row, header on the second row, and column names on the third row. Your program can open the template, and for each sheet,
a) read the SQL statement, execute it,
b) read the second row, and put the headers in the output sheet,
c) read the columns named from third row. Now iterate over your result set and put the data from the columns specified in the template into your output sheet
If you like, you can allow your users to put excel formulas and values in the template too. You will have to find a way that you can identify which cells have column names. Maybe column named can be surrounded by ${....} You just copy the cells that don;t have column names
Needless to say,
you should give this to only super-trusted users, because you don't want your users to run just about any SQL on your database. We used this to create a
test framework for our testers. They excel template told our framework what the input and expected output was, and we used to pull data from the database into the sheet to compare actual output with expected output.