need to import Excel data into Mysql database using coldfusion script. How can i do it. Is there any utility or any script can do it. Thanks in advance.
9 12854 acoder 16,027
Recognized Expert Moderator MVP
Welcome to TSDN!
You can use the Excel file as a datasource. Loop over the rows and insert them into the database.
What format is the data in?
Welcome to TSDN!
You can use the Excel file as a datasource. Loop over the rows and insert them into the database.
What format is the data in?
The datas are Dotted IP and its corresponding decimal value...And also The sheet included two other columns like country code and country name..
For an Eg:
Dot ip Dec Coucode Couname
19.2.2.2 11111111 Ja Japan
acoder 16,027
Recognized Expert Moderator MVP
Set up the Excel file as a data source. Use cfquery to get the data and then loop over it as you would with a normal query and insert each row into the MySQL database. If you get stuck, post your code.
How can I make an Email Textbox as a readonly using dojo widget?
acoder 16,027
Recognized Expert Moderator MVP
How can I make an Email Textbox as a readonly using dojo widget?
That's a different problem. Did you manage to solve the original problem?
copy and past the codes below save it as read.cfm: - <!--- default values --->
-
<cfparam name="form.InputExcelFile" default="">
-
<cfparam name="form.StartCol" default="A">
-
<cfparam name="form.EndCol" default="0">
-
<cfparam name="form.StartRow" default="1">
-
<cfparam name="form.EndRow" default="0">
-
<cfparam name="form.Sheet" default="Sheet1">
-
<cfparam name="form.HeaderRow" default="">
-
<cfparam name="form.Formula" default="process">
-
<cfparam name="form.DecimalDigit" default="2">
-
<cfparam name="form.ProcessMerged" default="true">
-
-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-
-
<html>
-
<head>
-
<title>CFX_Excel Example</title>
-
<style type="text/css">
-
.textfield { font-family: "MS Sans Serif"; font-size: 9pt; border: 1px solid #cccccc; }
-
.button { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; font-weight: bold; color: #FFFFFF; background-color: #000000; cursor: hand}
-
.tablestandard { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; }
-
</style>
-
</head>
-
-
<body>
-
<cfoutput>
-
<h3>CFX_Excel Example</h3>
-
<h4>Read Operation - Convert MS Excel File To ColdFusion Query</h4>
-
<hr size=1>
-
<table width="100%" cellpadding="2" cellspacing="2" border="0" class="tablestandard">
-
<cfform action="example_read.cfm" method="POST" enctype="multipart/form-data">
-
<tr>
-
<td nowrap valign="top">Upload Excel file to read:</td>
-
<td width="100%" valign="top">
-
<input type="File" name="InputExcelFile" size="40" class="textfield">
-
</td>
-
</tr>
-
<tr>
-
<td nowrap valign="top">Sheet name or index##:</td>
-
<td width="100%" valign="top">
-
<cfinput type="Text" class="textfield" name="Sheet" value="#form.Sheet#" size="8">
-
</td>
-
</tr>
-
<tr>
-
<td nowrap valign="top">Column to process:</td>
-
<td width="100%" valign="top">
-
Start: <cfinput type="Text" class="textfield" name="StartCol" value="#form.StartCol#" size="8">
-
End: <cfinput type="Text" class="textfield" name="EndCol" value="#form.EndCol#" size="8">
-
(type '0' in the end attribute to process all non-empty/edited columns)
-
</td>
-
</tr>
-
<tr>
-
<td nowrap valign="top">Row to process:</td>
-
<td width="100%" valign="top">
-
Start: <cfinput type="Text" class="textfield" name="StartRow" value="#form.StartRow#" range="1," size="8">
-
End: <cfinput type="Text" class="textfield" name="EndRow" value="#form.EndRow#" size="8">
-
(type '0' in the end attribute to process all non-empty/edited rows)
-
</td>
-
</tr>
-
<tr>
-
<td nowrap valign="top">Header row:</td>
-
<td width="100%" valign="top">
-
<cfinput type="Text" class="textfield" name="HeaderRow" value="#form.HeaderRow#" validate="integer" range="0," size="4"><br>
-
(Row containing column names, if any)
-
</td>
-
</tr>
-
<tr>
-
<td nowrap valign="top">Number of decimal digits:</td>
-
<td width="100%" valign="top">
-
<cfinput type="Text" class="textfield" name="DecimalDigit" value="#form.DecimalDigit#" validate="integer" range="0," size="4">
-
</td>
-
</tr>
-
<tr>
-
<td valign="top">Formula:</td>
-
<td valign="top">
-
<input type="Radio" name="Formula" value="process" #iif(form.Formula is "process",de("checked"),de(""))#>Process<br>
-
<input type="Radio" name="Formula" value="show" #iif(form.Formula is "show",de("checked"),de(""))#>Show<br>
-
</td>
-
</tr>
-
<tr>
-
<td valign="top">Process merged cells:</td>
-
<td valign="top">
-
<input type="Radio" name="ProcessMerged" value="true" #iif(form.ProcessMerged is "true",de("checked"),de(""))#>True<br>
-
<input type="Radio" name="ProcessMerged" value="false" #iif(form.ProcessMerged is "false",de("checked"),de(""))#>False<br>
-
</td>
-
</tr>
-
<tr>
-
<td colspan="2">
-
<input type="Submit" value="Convert Excel To CF Query Now" class="button"><br>
-
<br>
-
<font size="1">
-
<a href="example_write.cfm">Click here to see the CFX_Excel write example</a>
-
</font>
-
</td>
-
</tr>
-
</cfform>
-
</table>
-
-
<cfif form.InputExcelFile neq "">
-
<!--- read operation --->
-
<hr size="1">
-
-
<!--- define temp excel --->
-
<cfset strDir=GetDirectoryFromPath(ExpandPath("*.*")) & "/temp">
-
<cfset strInExcel=strDir>
-
-
<!--- upload image --->
-
<cffile action="Upload"
-
filefield="InputExcelFile"
-
destination="#strInExcel#"
-
nameconflict="MAKEUNIQUE"
-
mode="757">
-
<cfset prodThumbDir=file.ServerDirectory>
-
<cfset prodThumbFile=file.ServerFile>
-
<cfset prodThumbExt=file.serverfileext>
-
<cfif (prodThumbExt neq "xls")>
-
CFX_Excel accepts .xls file only
-
<cfelse>
-
<!--- read excel --->
-
<cftry>
-
<cfset tickBegin = GetTickCount()>
-
<cfx_excel action="read"
-
File="#prodThumbDir#/#prodThumbFile#"
-
Sheet="#form.Sheet#"
-
Result="qryResult"
-
Formula="#form.Formula#"
-
StartRow="#form.StartRow#"
-
EndRow="#form.EndRow#"
-
StartCol="#form.StartCol#"
-
EndCol="#form.EndCol#"
-
HeaderRow="#form.HeaderRow#"
-
ProcessMerged="#form.ProcessMerged#"
-
DecimalDigit="#form.DecimalDigit#">
-
<cfset tickEnd = GetTickCount()>
-
<cfset loopTime = tickEnd - tickBegin>
-
-
<!--- show result query --->
-
<h3>Conversion Result:</h3>
-
<cfdump var="#qryResult#">
-
-
<hr size="2">
-
<h3>Performance</h3>
-
Convert time was: #loopTime# milliseconds<br>
-
Query info: #qryResult.recordcount#<br>
-
<cfif looptime gt 0>
-
Approx. speed: #numberformat(qryResult.recordcount/(looptime/1000))# rows/second
-
</cfif>
-
<br><br>
-
<font size="-1">
-
(Please note that our live example is running in a very busy shared hosting environment)
-
</font>
-
-
<cfcatch type="Any">
-
<h3>There was a problem while reading '#prodThumbFile#'</h3>
-
Check the file, columns to process, rows to process and other properties,<br>
-
to make sure all source cells can be converted to recordset.
-
</cfcatch>
-
</cftry>
-
</cfif>
-
-
<!--- remove temp excel --->
-
<cftry>
-
<cffile action="DELETE" file="#prodThumbDir#/#prodThumbFile#">
-
<cfcatch type="Any"></cfcatch>
-
</cftry>
-
</cfif>
-
</cfoutput>
-
</body>
-
</html>
-
The same with the codes below and save it as viewexcel.cfm: - <cfparam name="url.ExcelFile" default="">
-
<cfif listlast(url.ExcelFile,".") neq "xls">
-
<cfabort>
-
</cfif>
-
<cfset strDir=GetDirectoryFromPath(ExpandPath("*.*"))>
-
<cfif not fileexists("#strDir#temp/#url.ExcelFile#")>
-
<cfabort>
-
</cfif>
-
<cfheader name="Content-Disposition" value="inline; filename=#url.ExcelFile#">
-
<cfcontent type="application/unknown" file="#strDir#temp/#url.ExcelFile#" deletefile="yes">
You can Convert MS Excel File To ColdFusion Query. acoder 16,027
Recognized Expert Moderator MVP
copy and past the codes below save it as read.cfm:
... You can Convert MS Excel File To ColdFusion Query.
It makes use of a custom tag to do the job. Did the code contain any copyright information?
It makes use of a custom tag to do the job. Did the code contain any copyright information?
No there is no Copyright. it's on the web for free. I used it befor so I thought it may be hany.
acoder 16,027
Recognized Expert Moderator MVP
No there is no Copyright. it's on the web for free. I used it befor so I thought it may be hany.
OK, just making sure. Thanks.
It does use cfx_excel which is a custom tag, though. So it wouldn't work 'out of the box'.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Damien |
last post by:
Hi to all,
I need to design an import/export system. Data comes from a filemaker
pro DB in a big CSV file. Some alterations are made on the data as it is
imported into my mysql table. Data is something like :id,text1html,
text1raw,... .
Problems :
1. Texts can contain html tags, including entities (" etc), so
using only the ';' as...
|
by: Phil Perrin |
last post by:
------=_NextPart_000_0001_01C3663D.5E3EAD70
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
I'm a relative newbie to MySql, and I've got a small project I'm working
on and hopefully you folks can either point me in the proper direction
or give me a little help.
I have multiple spreadsheets in Excel format...
|
by: Johnny |
last post by:
I was looking for information on how to import an excel file or other
text file into a MySql database. I have done this with both access
and SQL Server and am looking for a way to do this in MySql. I have
several hundred items i want to import into a parts database that is
currently in an excel file but can be saved as comma separated or...
|
by: dimitri |
last post by:
i try to copy data from excel into my MySql database which runs on a
linux.
i use MS Access to access the database. i need to optain the unique id
number, and this is where i have some troubles.
how can i either insert data, so my unique id number is continuing
or, how can i access my MySql database with MS Access without a "Unique...
|
by: fkulaga |
last post by:
Hi all,
I have a problem with the issue in the subject, i have all data in one
big excel file,
in a denormalized form, and on the other side, i have mysql database
with many tables, which is already in production, and it is of course
in the 3rd NF. How do i go about importing that excel file , is there
any good tool i could use to handle...
| |
by: nehashri |
last post by:
hello
i have my data stored in different Ms Excell sheets. now I am planning to make a database of the data i have. but i m confused whether to use Postgresql or mySQL for the same. i had plans to import data directly to Ms Access but there is problem with my access for now so i have to think of other choises.
i wanted to know whether it is...
|
by: vj83 |
last post by:
Hi,
I have a C#.net application in which i have read the datas from excel sheet and displayed in a datagrid in my Aspx form.
The code is here
private void Button2_Click(object sender, System.EventArgs e)
{
try
|
by: kelvenng |
last post by:
Hi all hope some one can help me solve my problem.
Actually I want import data from excel to my MYSQL server by using VB6
I facing the problem on my coding and system show me the error.
below is my VB coding hope some one can tell me my error.
Thanks
Dim cn As ADODB.Connection
Dim sql As String
Dim lngrecsaff As Long
|
by: arshigill |
last post by:
I want to import data from excel file inot mysql database table but unable to solve this problem.
I have searched google and find an example of importing of CSV excel file.
But when I modify it for my own requirements it does not work.
Please help me with an example to import data in colums in exel file into mysql table columns.
Thank
PHP...
|
by: thesti |
last post by:
hello,
how to programmatically from VB .net / php. to import data from an EXCEL file?
is there's no programmatic way, how to automated the process. as i search, the process is:
Simply export data from excel as TXT or CSV. Than use MySQL command
LOAD DATA INFILE 'path/file.txt' INTO TABLE your_table;
so,
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |