473,394 Members | 1,679 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,394 software developers and data experts.

How read all Excel file row into mysql database by .NET

Hello everyone!
I have a project as to read the Excel file and load into mySQL database, but my coding is to read only 100 first rows, how can we read all rows from .XLS sheet. Please, anyone can help me. Thanks a lot in advance. my coding as below:
for (int row = 1; row <= document.WorkBook.Worksheets[0].LastRow; row++)

{

// And column in first Worksheet
for (int col = 0; col <= document.WorkBook.Worksheets[0].LastColumn; col++)
{
// Append cell value to StringBuilder
builder.AppendFormat("{0}\t", document.WorkBook.Worksheets[0].Cell(row, col).Value );
//


}

builder.AppendLine();
}



// Save StringBuilder to file
File.WriteAllText("C:\\MINH.txt", builder.ToString());
Feb 28 '08 #1
5 2886
SammyB
807 Expert 512MB
Assuming that you have data in the first row,
document.WorkBook.Worksheets[0].UsedRange.Rows.Count
will give you the last row. HTH --Sam
Feb 29 '08 #2
Thanks Sam, But still no work coz I used ByteCount.xls has no UsedRange, any other help please
Mar 1 '08 #3
SammyB
807 Expert 512MB
Thanks Sam, But still no work coz I used ByteCount.xls has no UsedRange, any other help please
Every worksheet has a UsedRange. Post all of your code that reads the workbook and I'll fix it. Here is an example of C# Excel code. http://support.microsoft.com/kb/306683 It does different things, but shows how to do automation in C#.
Mar 1 '08 #4
Thanks a lot SAM, hers is my code Please help me
protected sub DumpExcelFile(string strFilePath)
{
// Create new XLSDocument from SimpleReport.xls file
XLSDocument document = new XLSDocument(strFilePath);

// Create new StringBuilder
StringBuilder builder = new StringBuilder();


// For each row
for (int row = 1; row <= document.WorkBook.Worksheets[0].LastRow; row++)

{


// And column in first Worksheet
for (int col = 0; col <= document.WorkBook.Worksheets[0].LastColumn; col++)
{
// Append cell value to StringBuilder
builder.AppendFormat("{0}\t", document.WorkBook.Worksheets[0].Cell(row, col).Value );
//


}

builder.AppendLine();
}



// Save StringBuilder to file
File.WriteAllText("C:\\MINH.txt", builder.ToString());
}
Mar 1 '08 #5
SammyB
807 Expert 512MB
It will be Monday before I have a computer setup to do Excel with Visual Studio. Look at the link that I gave you and try to make your code look like that. Also look at this thread: http://www.thescripts.com/forum/post2587984-2.html. Notice that in C# you cannot string stuff together like document.WorkBook.Worksheets[0].Cell(row, col). You have to cast each item into an object: first get an Excel Application object, then get a Workbooks collection, then get a Workbook via Open (don't forget the oMissing's), then get the Worksheets collection, then get the Worksheet, then get the UsedRange. Let me know on Monday how you are doing. --Sam
Mar 1 '08 #6

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

Similar topics

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...
3
by: bawar | last post by:
Hey, I can say I belong to the newbies in this subject. I own my own website with mySQL-databases, but now I have to show one table of those mySQL-databases in an excel worksheet. It is the...
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...
6
by: chiya | last post by:
plz anybody help me in uploading data from excel file to mysql database. data in excel sheet is in vertical format not horizontally. I mean to say that the columns of mysql tables are in rows in...
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,...
5
by: Sport Girl | last post by:
Hi everybody. I am new in PERL language and working in it since little hours, actually i am still a trainee and i need help please. In fact, i need a script in PERL that enables me to retrieve...
1
by: Sport Girl | last post by:
Hi everybody , i have the task of developing in Perl a script that retrieves data from 3 tables ( bugs, profiles, products) from a MySQL database called bugs and display them in an excel sheet...
6
by: Sport Girl | last post by:
Hi all , i need to write into an excel sheet file the data retreived from the database. i have the script but the problem is that i can't get the data written in the excel file. Can anybody help...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
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...
0
marktang
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,...
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
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...

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.