473,396 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how can i import excel data into mysql

sukumar 123
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.
Feb 18 '08 #1
9 12808
acoder
16,027 Expert Mod 8TB
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?
Feb 18 '08 #2
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
Feb 19 '08 #3
acoder
16,027 Expert Mod 8TB
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.
Feb 19 '08 #4
How can I make an Email Textbox as a readonly using dojo widget?
Mar 1 '08 #5
acoder
16,027 Expert Mod 8TB
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?
Mar 1 '08 #6
copy and past the codes below save it as read.cfm:

Expand|Select|Wrap|Line Numbers
  1. <!--- default values --->
  2. <cfparam name="form.InputExcelFile" default="">
  3. <cfparam name="form.StartCol" default="A">
  4. <cfparam name="form.EndCol" default="0">
  5. <cfparam name="form.StartRow" default="1">
  6. <cfparam name="form.EndRow" default="0">
  7. <cfparam name="form.Sheet" default="Sheet1">
  8. <cfparam name="form.HeaderRow" default="">
  9. <cfparam name="form.Formula" default="process">
  10. <cfparam name="form.DecimalDigit" default="2">
  11. <cfparam name="form.ProcessMerged" default="true">
  12.  
  13. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  14.  
  15. <html>
  16. <head>
  17.     <title>CFX_Excel Example</title>
  18.     <style type="text/css">
  19.         .textfield {  font-family: "MS Sans Serif"; font-size: 9pt; border: 1px solid #cccccc; }
  20.         .button {  font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; font-weight: bold; color: #FFFFFF; background-color: #000000; cursor: hand}
  21.         .tablestandard { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; }
  22.     </style>
  23. </head>
  24.  
  25. <body>
  26.     <cfoutput>
  27.     <h3>CFX_Excel Example</h3>
  28.     <h4>Read Operation - Convert MS Excel File To ColdFusion Query</h4>
  29.     <hr size=1>
  30.     <table width="100%" cellpadding="2" cellspacing="2" border="0" class="tablestandard">
  31.         <cfform action="example_read.cfm" method="POST" enctype="multipart/form-data">
  32.             <tr>
  33.                 <td nowrap valign="top">Upload Excel file to read:</td>
  34.                 <td width="100%" valign="top">
  35.                     <input type="File" name="InputExcelFile" size="40" class="textfield">
  36.                 </td>
  37.             </tr>
  38.             <tr>
  39.                 <td nowrap valign="top">Sheet name or index##:</td>
  40.                 <td width="100%" valign="top">
  41.                     <cfinput type="Text" class="textfield" name="Sheet" value="#form.Sheet#" size="8">
  42.                 </td>
  43.             </tr>
  44.             <tr>
  45.                 <td nowrap valign="top">Column to process:</td>
  46.                 <td width="100%" valign="top">
  47.                     Start: <cfinput type="Text" class="textfield" name="StartCol" value="#form.StartCol#" size="8">
  48.                     End: <cfinput type="Text" class="textfield" name="EndCol" value="#form.EndCol#" size="8">
  49.                     (type '0' in the end attribute to process all non-empty/edited columns)
  50.                 </td>
  51.             </tr>
  52.             <tr>
  53.                 <td nowrap valign="top">Row to process:</td>
  54.                 <td width="100%" valign="top">
  55.                     Start: <cfinput type="Text" class="textfield" name="StartRow" value="#form.StartRow#" range="1," size="8">
  56.                     End: <cfinput type="Text" class="textfield" name="EndRow" value="#form.EndRow#" size="8">
  57.                     (type '0' in the end attribute to process all non-empty/edited rows)
  58.                 </td>
  59.             </tr>
  60.             <tr>
  61.                 <td nowrap valign="top">Header row:</td>
  62.                 <td width="100%" valign="top">
  63.                     <cfinput type="Text" class="textfield" name="HeaderRow" value="#form.HeaderRow#" validate="integer" range="0," size="4"><br>
  64.                     (Row containing column names, if any)
  65.                 </td>
  66.             </tr>
  67.             <tr>
  68.                 <td nowrap valign="top">Number of decimal digits:</td>
  69.                 <td width="100%" valign="top">
  70.                     <cfinput type="Text" class="textfield" name="DecimalDigit" value="#form.DecimalDigit#" validate="integer" range="0," size="4">
  71.                 </td>
  72.             </tr>
  73.             <tr>
  74.                 <td valign="top">Formula:</td>
  75.                 <td valign="top">
  76.                     <input type="Radio" name="Formula" value="process" #iif(form.Formula is "process",de("checked"),de(""))#>Process<br>
  77.                     <input type="Radio" name="Formula" value="show" #iif(form.Formula is "show",de("checked"),de(""))#>Show<br>
  78.                 </td>
  79.             </tr>
  80.             <tr>
  81.                 <td valign="top">Process merged cells:</td>
  82.                 <td valign="top">
  83.                     <input type="Radio" name="ProcessMerged" value="true" #iif(form.ProcessMerged is "true",de("checked"),de(""))#>True<br>
  84.                     <input type="Radio" name="ProcessMerged" value="false" #iif(form.ProcessMerged is "false",de("checked"),de(""))#>False<br>
  85.                 </td>
  86.             </tr>
  87.             <tr>
  88.                 <td colspan="2">
  89.                     <input type="Submit" value="Convert Excel To CF Query Now" class="button"><br>
  90.                     <br>
  91.                     <font size="1">
  92.                         <a href="example_write.cfm">Click here to see the CFX_Excel write example</a>
  93.                     </font>                    
  94.                 </td>
  95.             </tr>
  96.         </cfform>
  97.     </table>
  98.  
  99.     <cfif form.InputExcelFile neq "">
  100.         <!--- read operation --->
  101.         <hr size="1">
  102.  
  103.         <!--- define temp excel --->
  104.         <cfset strDir=GetDirectoryFromPath(ExpandPath("*.*")) & "/temp">
  105.         <cfset strInExcel=strDir>
  106.  
  107.         <!--- upload image --->
  108.         <cffile action="Upload"
  109.                       filefield="InputExcelFile"
  110.                       destination="#strInExcel#"
  111.                       nameconflict="MAKEUNIQUE" 
  112.                         mode="757">
  113.         <cfset prodThumbDir=file.ServerDirectory>
  114.         <cfset prodThumbFile=file.ServerFile>
  115.         <cfset prodThumbExt=file.serverfileext>
  116.         <cfif (prodThumbExt neq "xls")>
  117.             CFX_Excel accepts .xls file only
  118.         <cfelse>
  119.             <!--- read excel --->
  120.             <cftry>
  121.                 <cfset tickBegin = GetTickCount()>
  122.                 <cfx_excel action="read" 
  123.                                         File="#prodThumbDir#/#prodThumbFile#"
  124.                                         Sheet="#form.Sheet#"
  125.                                         Result="qryResult"
  126.                                         Formula="#form.Formula#"
  127.                                         StartRow="#form.StartRow#"
  128.                                         EndRow="#form.EndRow#"
  129.                                         StartCol="#form.StartCol#"
  130.                                         EndCol="#form.EndCol#"
  131.                                         HeaderRow="#form.HeaderRow#"
  132.                                         ProcessMerged="#form.ProcessMerged#"
  133.                                         DecimalDigit="#form.DecimalDigit#">
  134.                 <cfset tickEnd = GetTickCount()>
  135.                 <cfset loopTime = tickEnd - tickBegin>            
  136.  
  137.                 <!--- show result query --->
  138.                 <h3>Conversion Result:</h3>
  139.                 <cfdump var="#qryResult#">
  140.  
  141.                 <hr size="2">
  142.                 <h3>Performance</h3>
  143.                 Convert time was: #loopTime# milliseconds<br>
  144.                 Query info: #qryResult.recordcount#<br>
  145.                 <cfif looptime gt 0>
  146.                     Approx. speed: #numberformat(qryResult.recordcount/(looptime/1000))# rows/second
  147.                 </cfif>
  148.                 <br><br>
  149.                 <font size="-1">
  150.                     (Please note that our live example is running in a very busy shared hosting environment)
  151.                 </font>
  152.  
  153.             <cfcatch type="Any">
  154.                 <h3>There was a problem while reading '#prodThumbFile#'</h3>
  155.                 Check the file, columns to process, rows to process and other properties,<br>
  156.                 to make sure all source cells can be converted to recordset.
  157.             </cfcatch>
  158.             </cftry>
  159.         </cfif>        
  160.  
  161.         <!--- remove temp excel --->
  162.         <cftry>
  163.             <cffile action="DELETE" file="#prodThumbDir#/#prodThumbFile#">
  164.             <cfcatch type="Any"></cfcatch>
  165.         </cftry>
  166.     </cfif>
  167.     </cfoutput>
  168. </body>
  169. </html>
  170.  

The same with the codes below and save it as viewexcel.cfm:


Expand|Select|Wrap|Line Numbers
  1. <cfparam name="url.ExcelFile" default="">
  2. <cfif listlast(url.ExcelFile,".") neq "xls">
  3.     <cfabort>
  4. </cfif>
  5. <cfset strDir=GetDirectoryFromPath(ExpandPath("*.*"))>
  6. <cfif not fileexists("#strDir#temp/#url.ExcelFile#")>
  7.     <cfabort>
  8. </cfif>
  9. <cfheader name="Content-Disposition" value="inline; filename=#url.ExcelFile#">
  10. <cfcontent type="application/unknown" file="#strDir#temp/#url.ExcelFile#" deletefile="yes">
You can Convert MS Excel File To ColdFusion Query.
Mar 13 '08 #7
acoder
16,027 Expert Mod 8TB
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?
Mar 13 '08 #8
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.
Mar 13 '08 #9
acoder
16,027 Expert Mod 8TB
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'.
Mar 13 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
0
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...
8
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...
1
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....
3
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...
7
nehashri
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...
6
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,...
0
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...
1
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...
2
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.