Export from .xls to .sql / creating sql queries - sql

Okay guys, I've been having this problem for a few weeks now and I'm getting no-where with it. I have OpenOffice and regular Office softwares. Both produce flawed .csv files, or at least phpMyAdmin can't read neither of these. Yes, I've been trying to change server's settings of uploading, etc. I also tried to contact my web hosting service and they claimed that all the .csv files I've produced are flawed.
Anyway, I'm looking for a way to convert .xls table to SQL. Most of the softwares out there cost money that I don't have. Furthermore, I've seen PHP systems that do just that, so I know this is possible.

No need converted to. sql, you can import directly with phpmyadmin or using tools like navicat for mysql in phpmyadmin go to the option to import, find the file, select the file type (csv or csv loaddata), in part below defines the column separator (if you do not know which opens the file with notepad)
if a very large file using navicat.
Flawed is "defective"?. I assume you have problem with excel, maybe you have defined the same column separator for separating thousands or decimals, use openoffice to open the file

Related

Can I export my SQL code (queries) to my computer as a .sql document?

I was asked to analyze a dataset in BigQuery (never used it until now) and I need to export my code as .sql documents. Is there a way to do this?
Big Query lets you save the queries on the cloud so you can use them later, as you may have noticed.
But if you really want to store them as files in your computer, you can always copy the code, paste them in a notepad and them save it as .sql, which can then be imported in platforms like PostgreSQL, etc.
Big Query doesn't allow you to load .sql files, though.

bunch of weird characters instead of text

I really count on your help.
Well, for hours I've been trying to have my excel files inserted in sql database as a table through the msvs and no matter what I have tried, the output data is always some sets of weird characters, boxes and etc. First I thought that it could be the PC language settings, I've tried changing them to my local one, changed the system locale to my own language and etc. But there was no result.
Then I just opened an excel file, typed there a single letter "d" and tried to open it in notepad++ to check whether the result will be the same or not. It was again a big pile of boxes and symbols instead of single letter "d". *Tried to change the encoding in notepad++, didnt work either.
Do you have any idea what can help me? It's really frustrating.
Thanks
Sabuhi.
Of course that happens, this is common behaviour when you are trying to open a compiled program in a text editor.
As #Gary'sStudent suggested, if you want to open the excel file
directly in a text-editor, it needs to be saved as .csv
Ctrl+Alt+S
Select the .csv file type:
Save (may need to adjust your table data to fit the .csv formatting
Either way, it sounds like you're a bit confused with what you're trying to achieve. If you want to export your Excel file as a database (which has it's own quirks and is not exactly the best approach to databases) then you should be able to view your database in your database editor - whatever you're using, after you have imported it and compiled it, instead of trying to open it in a text file!

How to run an sql query on an OpenOffice/LibreOffice spreadsheet from command line?

Well,
The title pretty much says it all. I have a set of ODS spreadsheets and I want to run some SQL queries over these spreadsheets and save the result on CSV files.
I know I can do that from the GUI, but I need to be able to do it from a batch file that will be run on a regular basis.
Solutions that make use of OpenOffice/LibreOffice Basic are acceptable, as well as solutions that require the use of some (free) plug-in.
Thanks in advance.
You could first convert .ods files into .csv files and do what you have to do on .csv files (insert in a real database, read it as plain text, etc.).
libreoffice --convert-to csv *.ods

Exporting hundreds of thousands of records with ColdFusion

Using ColdFusion 9.0.1, I need to export hundreds of thousands of database records to Excel XLSX or CSV (XLSX is preferred). This must be done on demand. So far I've tried using cfspreadsheet but it chokes when exporting more than a couple thousand rows in the XLSX format. However, exporting to XLS works fine (of course there is a ~65,000 row limit).
What are my options to export so many records? Theoretically the users could need to export as many as one million records. I'm also using SQL Server 2008 R2 -- is there a way to somehow export the records to a file there and then send the file through CF to the user? What options do I have? Thanks.
Since you are using SQL Server 2008, you could take advantage of SQL Server Reporting Services (SSRS) and create a report that can be called via web service (or HTTP GET/POST) by ColdFusion. SSRS has the capability to export reports as Excel as well. You'll need to read up on SSRS to make this work, but it's fairly easy to do.
As you've discovered, doing this with ColdFusion's <cfspreadsheet/> tag fails because it builds the entire document in memory, which leads to JVM OutOfMemory errors. What you need is something that buffers output to disk so you don't run out of memory. This suggests CSV, which is far easier to buffer. I imagine there are ways to do it with Excel as well, but I don't know them.
So two options for you:
use a Java library
use ColdFusion's fileOpen(), fileWrite(), fileClose() methods
I'll cover each in turn.
Java Libary
opencsv is my preference. This assumes of course you know how to setup a .jar on the ColdFusion classpath. If you do then it's a matter using its APIs to open a file and specify data for each line. It's really quite simple. Check its docs for examples.
ColdFusion Methods
Be forewarned there be dragons here.
If you are exporting numbers or strings that do not contain any double quotes or commas you can probably do this. If not, figuring out what to escape and how is why you use a library in the first place. Code is roughly as such:
<!--- query to get whatever data you're working with --->
<cfset csvFile = fileOpen(filePath, 'read')>
<cfloop query="yourQuery">
<cfset csvRow = ""><!--- construct a csv row here from the query row --->
<cfset fileWrite(csvFile, csvRow)>
</cfloop>
<cfset fileClose(csvFile)>
If the query data you're working with is also large you may be dealing with a nested loop to chunk it out.
Dustin, I had to investigate this myself, and as of this writing (Summer 2011), POI does a fine job of generating large files, but you have to use xlsx. The 3.8 beta source ships with an example named "BigGridDemo" which generates a 100K, 4-column workbook very quickly. I modified it to generate 300K, 125-column sheet, and it handled it in about 2 minutes. It created a 1.6 GB, 3.6-million-row workbook in a little over half an hour.
Granted, the code isn't the prettiest to look at, but it works. I suspect it'll pretty up a bit when ported to ColdFusion.

Generating Excel file from Cocoa (iPhone app)

I'd like to offer the possibility for users of my app to export to Excel. I don't ever need to read Excel files.
The three ways I know right now is to
make a CSV file, which isn't too great as I'd like to have some custom formatting in the spreadsheet
make an XML file that I don't think people'd recognize as an Excel file
make a template xlsx file, unzip it in the app, do a lot of search-replacing in the files and then zip it back up again
Are there other alternatives? I'm not sure how supported .xlsx files are, and that seems like very much work. Are there any frameworks out there I can lean on, that perhaps even make old-school .xls files?
Cheers
Nik
Some options for you to consider:
1) You may be able to use ooxml http://en.wikipedia.org/wiki/Office_Open_XML_file_formats. You may need the "office compatibility pack" on computers with excel 2003 or lower http://go.microsoft.com/?linkid=5754865.
2) Excel 2000 uses the BIFF file format: http://www.google.com/url?sa=t&source=web&cd=1&ved=0CBcQFjAA&url=http%3A%2F%2Fsc.openoffice.org%2Fexcelfileformat.pdf&ei=iDx0TKOhBIqmnQfckKy7CQ&usg=AFQjCNE2w4xyFSoKmvKdsa7O9TMqynYpbA (pdf). You may be able to create simple documents from the spec or based on other info on the web.