Download SQL results in CSV and PDF - excel

I want to download the results fetched from SQL query in Excel(CSV) and PDF format.
SQL Query
$sql = 'SELECT name, address, phone, city FROM users';
I want this records in CSV and PDF. When user clicks Excel then the Excel file will be downloaded and when clicks PDF then the PDF file will be downloaded.
please help me to do this. Thanks

First, you need to convert the results of the SQL into the format required for each. .CSV is relatively simple as you just need a comma separated list of results and a row separator (\n will work just nicely).
You'll want to set the content-type of the file before returning the result:
header('Content-Type:text/csv');
// code to output sql in csv format here
PDF will require some kind of library like TCPDF: https://tcpdf.org/examples/example_011/
The premise remains the samde though: Make your query then use the results to add rows to the table using the PDF library.

If you are looking for a long term solution, the best option would be to use SQL Server Reporting Services.
The user will have the option to download the result-sets in all the formats you mentioned.

Related

Power Query to open XML file formatted as Excel would open it

I have an XML file generated by EasyPower (electrical software). If I open the file in Excel it comes up as a series of formatted sheets like the image below. It appears this way without any prompts or dialogs.
I’m creating a Power Query routine that can extract the data from the sheets. Unfortunately when I use the Power Query wizard to select the XML file as a source, it doesn’t see the data as sheets, but rather a table with columns of Tables, seemingly an infinite number of levels deep. Digging through them I’m unable to clearly see the data. This is not a very good approach.
A work-around is for me to manually open the XML file with Excel and save it as XLSX, then it’s easy to work with the data in Power Query. I know a VBA script could be used to this but my question is, is there a way for Power Query to open an XML file and interpret the layout the same way that Excel does? This way would allow my script to also work within Power BI.
Edit: A sample file has been requested. This link will provide a very simple example containing two worksheets when opened in Excel. EasyPower_Test_Schedule.xml

Excel for Mac: Run Web Query with Text to Columns

I'm making a Web Query on Excel by doing the following:
Create a Word file, paste the web URL.
Save the Word as .iqy with .txt format.
Choose MS-DOS as coding.
Create an Excel file and click "Data >Get External Data >Run Web Query
Is there a way to separate the text by columns when running the query?
Thank you.

How to convert Excel file with multiple sheets to CSV at once using azure logic app?

I want to convert Excel file with multiple sheets to csv at once using logic app , Im able to convert perticular sheet(only 1 at a time) from excel file to csv but not all of them at once. Any help/suggestion would be appreciated
Thanks in advance
Hope you are using Get Tables action, then it returns all the tables in any of the worksheets.
You can now loop in through the output of Get Tables action and use "list rows present in a table" action.
On the Table option Select Enter custom value and Select the dynamic content Name of your previous "Get Tables" action.
As you have already mentioned that you were able to convert one table to csv. The next actions should be inside the same, use FOR LOOP to save the table rows to csv.
Reference: https://learn.microsoft.com/en-us/answers/questions/514894/how-to-convert-excel-file-with-multiple-sheets-to.html

How do I store Excel data into Firebase?

I have an Excel sheet of all my data (thousands and thousands of rows). How do I get that "loaded" into Firebase to be used?
I've created a Firebase project and tried to look at some tutorials for the realtime database but that's not quite what I want. I don't want real-time data quite yet. I just want data that I have to be loaded in first. How do I go about doing that?
Thanks!
I figured this out on my own.
First, take the Excel spreadsheet and clean it up in such a way that the first row contains the headers and everything else is the actual data. Remember that Firebase keys (which correspond to column headers) must be UTF-8 encoded which means that it cannot contain . $ # [ ] / or ASCII control characters 0-31 or 127.
Then, save it as a CSV file. For example, on Excel 2013 it would be: File > Export > Change File Type > CSV.
Then, visit various resources online that can do CSV to JSON conversion. The one I used was: http://codebeautify.org/csv-to-xml-json
Finally, take that .json file and load it into the Firebase database. Voila!
STEPS TO UPLOAD COUNTRY LIST IN FIREBASE:
download country list with country code, currency code and currency name what you require:
convert it into csv.
convert csv into json from (https://codebeautify.org/csv-to-xml-json#).
validate json from https://jsonlint.com/
save in a file say test.json.
open firebase with login.
select database.
click on (...) in verticle, beside + - sign,
click on import.
browse and select test.json file
import
now it is great!!!!!!! cheers!

ODBC Connection to Flat file

What is the best way to take a database and make it a flat file?
I am have an ODBC driver and need to pull the data out into a file file.
Excel, Access? OpenOffice?
I'd suggest Excel as the fastest way to export data from any datasource that supports ODBC or OLEDB and write it out to a flat file.
The tools in Excel are helpful in shaping the query to the database.
Once you get it into Excel, you can then choose to Save As to .csv, .txt or transform it however you like.
If you want to set up relationships and to manipulate the data database-style, Access offers a range of import options, at least as many as Excel.
As an alternative, you could run a SQL command from the database to create the csv file. This has the advantage of allowing you to use complex SELECT statements. Here is a simple example using MySQL:
select emp_id, emp_name from emps
into outfile 'c:/test.txt';

Resources