Hi,
I have many Excel files (more than 200 files). I'm using TOAD to import the Excel files into the Oracle table, but this process is boring and time-consuming especially for this huge number of files.
So, I'd like to do a PHP code which takes the path of the Excel file and imports it automatically into the Oracle table without using TOAD or any other programs.
I'm using PHP OCI8 to handle Oracle queries.
Please help me. Thanks in advance.
4 8664
is your PHP host running on windows?
usually, as Excel is a propriatary file format and most PHP hosts can’t run that, you need some kind of file conversion before that (e.g. xls => csv)
Yes, My PHP HOST is running on Windows Server 2003, IIS 6.0.
OK, after converting it to CSV, how can I read it?
Thanks alot for replying.
on your server you can try to directly load Excel files (via COM), though I have no experience with it (lack of windows)
You can also do this with PHPExcel. Please find the code below which works fine to me.
The code below does not contain a file browser and PHPExcel.php
This can be automated to your system by making loop with reading number of files in a folder - <?php
-
-
/*
-
Author: Rajan Maharjan
-
Website: http://rznmzn.com | http://rajanmaharjan.com.np
-
Date: 2010 December, 25
-
*/
-
include "PHPExcel.php";
-
$ext = pathinfo($_FILES['file_name']['name'], PATHINFO_EXTENSION);
-
$newFileName = (microtime() * pow(10,8)).".".$ext;
-
-
if(! isset($_FILES['file_name']['tmp_name'])){
-
$_SESSION['error_message'] = 'No file selected for upload';
-
header("location:index.php");
-
exit();
-
}
-
-
else if(strtolower($ext) != 'csv' && strtolower($ext) != 'xls' && strtolower($ext) != 'xlsx'){
-
$_SESSION['error_message'] = 'Invalid file format. Please try to upload CSV (Comma Separated Value) file.';
-
header("location:index.php");
-
exit();
-
}
-
-
move_uploaded_file($_FILES['file_name']['tmp_name'],"csvfiles/".$newFileName);
-
-
$csvFileName="csvfiles/".$newFileName; //defined in the page where this is included
-
-
-
if(strtolower($ext) == 'xls' || strtolower($ext) == 'xlsx'){
-
-
$objPHPExcel = PHPExcel_IOFactory::load($csvFileName);
-
-
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
-
$worksheetTitle = $worksheet->getTitle();
-
$highestRow = $worksheet->getHighestRow(); // e.g. 10
-
//$highestColumn = $worksheet->getHighestColumn(); // e.g 'F'
-
//$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
-
-
for ($row = 1; $row <= $highestRow; $row++) {
-
if($row==1)
-
continue;
-
$arrayData = array();
-
$arrayData['first_field'] = $worksheet->getCellByColumnAndRow(1, $row)->getValue();
-
$arrayData['second_field']= $worksheet->getCellByColumnAndRow(2, $row)->getValue();
-
$arrayData['third_field']= $worksheet->getCellByColumnAndRow(3, $row)->getValue();
-
$arrayData['fourth_field'] = $worksheet->getCellByColumnAndRow(4, $row)->getValue();
-
$arrayData['fifth_field'] = $worksheet->getCellByColumnAndRow(5, $row)->getValue();
-
-
-
$object_functions->insert_to_db($arrayData); //insert queries goes here
-
}
-
-
}
-
}
-
else if (strtolower($ext) == 'csv'){
-
$row = 1;
-
if (($handle = fopen($csvFileName, "r")) !== FALSE) {
-
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
-
if($row++ <= 1)
-
continue;
-
-
$arrayData = array();
-
-
$arrayData['first_field'] = $data[1];
-
$arrayData['second_field']= $data[2];
-
$arrayData['black_list_date_np']= $data[3];
-
$arrayData['third_field'] = $data[4];
-
$arrayData['fourth_field'] = $data[5];
-
$arrayData['fifth_field'] = $data[6];
-
-
$object_functions->insert_to_db($arrayData);
-
}
-
-
fclose($handle);
-
}
-
}
-
unlink($csvFileName);
-
echo 'Your data has been imported successfully.';
-
?>
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jake |
last post by:
Hello,
I was wondering if someone had a example of how to import an excel file
into a sql database via asp.net? Thanks in advance.
Jake
|
by: ramnaresh_t yadav via .NET 247 |
last post by:
Hi,
I am pasting the code to import data from Text/Excel files into Database(Oracle ) Table...
I think some one needs this .. they can use.. it...
=======================
Dim dsDB As New DataSet...
|
by: ramyanet |
last post by:
Dear All,
I have to enable feature of users to import thier excel file in my web application.I have used the Asp.net with Vb.
when they click import button file open dialog must appear,then...
|
by: Steve Kershaw |
last post by:
I have a need to extract data from an Oracle database using an SQL
query. The problem is that I need to insert a parameter into the query.
For example:
SELECT EMPLOYEE, DED_CODE FROM QUARTDED...
|
by: harshala |
last post by:
I want to open excel file using open dialogue box and display records in datagrid
|
by: rmsterling |
last post by:
All,
Subject: SQL Server 2005 - How do I import data from an Oracle Data Pump file?
Tried looking in the SQL help for this and it's not very forthcoming on how
you do this.
How do I...
|
by: shenkel55 |
last post by:
I'm using Access and Excel 2003. Using either the import wizard or code, I have the same problem. This problem only happens with Excel files automatically generated by Corp IT. If I try to do an...
|
by: maryanncanor |
last post by:
Hi, I have an input excel file that needs to be imported to Table1. However, the fieldnames or header in the excel file doesnt match the fieldnames in the database. The fieldnames in the excel file...
|
by: giandeo |
last post by:
Hello everybody
I am trying to import an excel file for days into MS SQL Server 2000, unfortunately, I cannot see a ray of hope till now.
I have surfed the WEB for hours, but again no...
|
by: sumanta123 |
last post by:
Dear Sir,
How to export/import the excel file in oracle database using sql promt.
Please guide me the command(export/import) for the neddful.
Thanks in Adavance.
Regards
Sumanta Panda
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |