I am looking for a way to automate an entire process that uses Excel & ODBC queries. I know that Excel can use to a ODBC driver to run queries against a Mysql database. But I need this query to be triggered programmatically.
The individual steps the program or script should be able to do are:
1. Open Excel file
2. Run Mysql query (query will not change but the values the query hits the database for will come from the excel file)
3. Save results of the query to the Excel file as a sheet
4. Use the results to do vlookups against another sheet in the same excel file
5. save results of vlookups and close the file
Flexible on the language or any add-ons necessary. Anything out there that would help? I am looking to run this both on windows and mac.
What you want to do is probably possible using COM (Python tutorial). It will be messy, hard to code and hard to debug. And no way it'll work on a mac.
Instead, if I was you I would try and take the problem out of excel. For instance in Python, I would first directly access mysql. I would then parse my second xls file using xlrd. With the results of the mysql query and the parsed xls file both in Python data structures, replicating the behaviour of VLOOKUP is easy. I would then write the results to my output xls file using xlwt.
Related
I have been wondering whether or not it is possible to write VBA to an excel file using php? I ask this question for this reason -> I want to generate an excel report every monday when our users log in. The reports will pull data from our sql db, and write the data to an excel file.
My question is multi-part.
1) Is it possible to write data to an excel file and save that data without the user seeing it?
If I can, then I know how to have it attached using php mailer.
2) If it has to open as a result of using headers, can i write a vba script to minimize or make active workbook close. (I'm highly doubtful as it is because I think excel docs open up as csv when writing sql results to them.
I am trying to build a data management system online using mysql/php/javascript/etc.
I have used Access for this in the past and it works great for the part I am struggling with. Data comes from an HPLC (lab instrument), and the software that determines the results auto exports this as an excel file, but can also do csv. After the export, the HPLC software runs a command file that opens access and runs a form which imports the file and places the data in the correct fields with proper identifiers.
I am now wanting to have all data on a web-based db. This will allow for better access off-site, and an easier to maintain system, especially off site. My problem is, I am not sure how to get the data from the HPLC to the database.
I think it may be possible to use mysql commands to upload the .csv file, but then to format and use proper table relations for the data, I am stuck! How can I upload the data AND run a program to normalize?
Export to .csv.
Write an MySQL programm which
creates a temporary table for your .csv input;
uploads the data from the .csv file with the LOAD DATA statement;
normalizes the data to your structured database tables by selecting them from the grand table with the csv data and inserting into your various tables.
Here's my clients scenario my client wants to put a excel file on server now from a PHP form
sends data to the file runs a formula in this excel file and get the results.
I don't know if this is possible.
If so direct me to a library best was PHP, or some other possible solutions.
It's perfectly possible: take a look at the PHPExcel library which has a built-in calculation engine for handling most Excel formulae
There's an example of populating an Excel file with data (in this case from a form input) then rendering a formula in that Excel file to generate a result an ddisplaying it to a web browser in the /Tests/ directory of the distribution. This simple example /Quadratic.php solves a quadratic equation; but the principle is similar enough
EDIT
See my response to this question for some indication of the limitations of PHPExcel's calculation engine
EDIT 2
The PHPExcel is deprecated, hence now you can use PhpSpreadsheet
You are thinking in the wrong direction. Instead trying to send the data to the excel file, read the excel file in you PHP script and do the math there.
Trying to send dynamic data into a static XLS file wont work.
And you can add a regular cronjob, that checks if the XLS file data has changed, if it has, then run your calculation again.
hi i want to converted my excel file into sql file can any one know what should i do for converting? i dont know how to converted.
thanks
Use sql convertor from below link
http://www.sqlconverter.com/
OR
You need to convert the .xls file to .csv(comma seperated file) and then use the loader to load the data if you want to load the .xls data to database.
Try Navicat products.
I used Navicat for MySQL for example and it provides great flexibility in Importing Excel sheets in Mysql tables.
From there you can run any type of SQL query
Here is web application tool that allows fast Excel to MySQL conversion.
Excel data does not have a Schema by default and this tool allows you to define it interactively with the help of a wizard.
Input
An Excel (xls / xlsx) data file, whose format is given in the documentation they provide.
Output
A .sql export file (which can be imported into a MySQL database) is available for download after the conversion is done. (And it works pretty fast)
The other option is to export to CSV first. Excel can export to CSV and then MySQL can import CSV via LOAD command or PHPMyAdmin. The schema should be defined before. Its a little longer process.
This question already has answers here:
How to import an excel file in to a MySQL database
(15 answers)
Closed 9 years ago.
my boss wants me to create a mysql database for an existing excel file. I was wondering if there are any ways to do convert or import excel file? I have searched google but didn't find anything useful. I appreciate for any reply....Thanks.
Save as CSV
Use a COPY sql statement
Profit
If you have a web server up and running with PHP support, I highly recommend phpMyAdmin.
Configure it to connect to MySQL
Create the Database and table
Click the import tab and you can import a CSV.
If this is a simple one-time import this probably isn't worth the effort. If, on the other hand, you will ever have to work with MySQL again, you will never regret the time to install and configure phpMyAdmin.
PHPMyAdmin can import CSV files, as well as Excel files (though I've never tried it)
First you need to create your datebase, and add a table. There must be as many fields in that table as there are columns in your Excel document (yes, I know you know)
Then select that database and table in phpmyadmin and use the "Import" tab.
I wrote a tool that will let you do sql queries against a csv file. The output is saved as a csv as well. Maybe you will find it useful.
http://whitlock.ath.cx/EasyCSV/
From Excel, export the sheet as a text file. In MySQL, use LOAD DATA INFILE to import the text file.
easiest way to do it would be this:
insert into Table (col 1,col 2,col 3...col n) values (val1,...valn);
basically:
do 2 for loops in your excel:
dim i,j
dim sqlString,sqlBase
sqlString=""
sqlBase="insert into yourTable (col1....coln) values ("
for i=1 to myRowVariable
sqlString=""
for j=1 to myColVariable
if j=myColVariable then
sqlString=sqlString & Cells(i,j).value & ");"
else if j=1 then
sqlString=sqlBase & sqlString & ","
else
sqlString=sqlString & Cells(i,j).value & ","
end if
Next j
Next i
'write sqlString into a txt or something
this will do what you need in a bootstrap but fast and very intuitive way.
You can use an ODBC driver to "mount" an Excel file as database and then make SQL queries to it. All you need then, is a simple migration tool, to copy the tables to another databases system.
I believe there's even an mysqldump-like tool for ODBC driven databases.
A low tech solution would be to use the concatenation function in excel to convert the data into a series of insert statements and then copy and paste them into mysql query analyzer or whatever client you are using.