PHP --> SQL Server + Excel file upload from a specific row - php

I have a requirement in which, i need to upload an excel file into SQL Server database. It is working well till this point.
But sometimes i am getting excel file in such a way, that the first 2 rows and columns are empty rows. That is not even fixed every time. so the format of the table after upload is not as expected. It is assigning F1, F2 as column names for the table in SQL Server.
It varies from file to file. I want to program it in such away so that the user can enter the row number and the column number from where the actual data is starting. So that while upload it should from line 3 and column 2.
I don't know how to specify that row and column while uploading.
Please help me to solve the same.

You could use http://phpexcel.codeplex.com/
You can use this to check if and where the data you expect is located in the excel.
If not you could try to find the first column/row with data and work from there.

First of all you can ask your user before starting upload (in form with input type="file") and after user uploads file and you show him an parsed excel data (by your script)..
To more concrete answer you should at least say, by what do you parse excel files and what excel format do you use...

Related

php resume file import

i have a client requirement with resume-able file import.i will tell the use case file imported is csv that corresponds to 3 mysql-table datas. during upload if any kind of warnings occure like name too long,description too long it should stop execution and show the warning to client.client have 2 options ignore and re upload if he ignores then file upload will resume from the point where error happens and other option is simple just re upload the file.how should i continue the script execution after showing error msg ? how should i track no of csv lines get completed?
now lets explain my plan. i an using jquery ajax in first place.after saving each line of code save the no of lines executed in a session variable.if the user ignore the warning. then i will reupload csv and wait until the line no matches the one in session variable.is this the elegant way of doing things? reason why i put this question is each time user ignore the error msg according to my logic he/she needs to wait until the line stored in session reached. pls explain with an example if their is a better solution to this problem. thanks in advance.
A possible workflow
Analyze each line of the CSV file and load it into an empty table specially created for this purpose. The table should have the columns to store only the columns you import from the CSV file. It can also contain additional columns to store data that is computed during the import; f.e. if the processing and validation of the input data requires lookups
into the data that already exists in the database, the values found should be also stored in the import table to avoid running the same queries again.
Ignore the lines from the CSV file that cannot be imported but keep track of their information (content, failure reason etc). You'll need the info to display it to the user.
If there are no errors in the CSV file then move the (validated) data from the special table into the destination tables and call it a success.
If there are errors show them to the user.
If the user decides to reload the CSV then start over with step 1.
If the user decides to ignore the errors then resume with step 3.
Advantages
There is no need to upload the CSV file again.
There is no need to keep track of the progress.
Disadvantages
A lot of work is done then discard if the file is large, the error is at the beginning of CSV file and the user decides to upload it again. This can be improved in the algorithm by using an extra database table that contains the raw lines of the CSV file and an extra step (step 0): load the CSV file into it then use this table instead of the CSV file as input data for step 1. When a line is valid remove it from the CSV table; when a line is not valid then skip to step 4. When the user decides to ignore the error then resume with step 1.

insert value from specific position in .dat file into mysql

I have a .dat file that contains a bunch of text information. What I need to do via php is be able to upload the .dat file to the server which I know how to do already. However once it is uploaded to the server I am not sure how in PHP to open the file and get what ever value is at the 180th position in the file.
The files should all be one row although even if its not I still just need the value from the first row 180th position and take that value and insert it into a mysql database table.
I am looking for any tutorial or documentation on how to do this
Thanks all

Read the data in table from a PHP URL and write it to a text file

We have a local site written in PHP, which contains some data in table format (index.php). It is a dynamically generated data/table, so I'm not able to access the database behind it.
Is there any way I can read the table in that web page, and write it to a text file in the same table format using perl/php/python?
The table is a huge one with around 1000 rows. But I need only the top 10 rows (sorted based on one of the columns).
Please help.
In PHP you can use file_get_contents() function to get the whole html of any page, than you can filter your required content and save it in a text file using fopen() and fwrite().

.csv file into mysql

The server I'm using does not allow me to use LOAD DATA INFILE or even save a file as a .txt file. I have a .csv file that is just one column, with a name in each row. I want to insert this data into the name column of a table named people with name as one column and location as the other… where the locations will be updated at a later time.
It's a weird way to do this. But I need to do it this way and not using those previous commands.
Does anybody have any ideas? This has been giving me a problem for many hours. I can't figure out how to load the csv into my table column without using those previously mentioned methods that I can't use on my server.
Based on your issue and lack of general permissions you will have to do the following:
Replace the DOS carriage returns with unix new lines:
$contents=preg_replace('/(\r\n|\r|\n)/s',"\n",$contents);
Save the contents to the file, and then loop through each line, building an INSERT command that you execute to MySQL.

program to convert sheet1(excel) into standard sheet2(excel)

Is it possible to write a program that change the order of columns in sheet1(excel) based on a table in standard sheet2(excel)?
Sheet1 have the same header of each column as sheet2 but the position of columns is not same and also it is possible that some more columns are present in sheet(1). Finally I have to store the standard sheet into the database.
Yes it possible to change the order of columns.
Steps:
Change the excel sheet format file to csv file.
Write a PHP code to arrange the random columns as per the standard sheet.
Write a code to enter this data into the database. Each time you receive the new column append it at the last of the standard column.
Make the respective change in the PHP code for the same.
This is probably a dumb answer, but back in the day I used VB code inside of Excel workbooks to manipulate data including culling information from one worksheet and creating another based on contents.
Try http://msdn.microsoft.com/en-us/library/office/ee814737(v=office.14).aspx for more information.

Categories