Localization :: Reading A CSV File Created By Excel?
May 27, 2010
I am reading a CSV file created by Excel. the string I am reading needs to be encoded (it shows small boxes instead of hebrew characters) so I wrote a lil routine to convert the string -
Function encodeName(ByVal name As String) As String
Dim src As Encoding = Encoding.UTF8
Dim dest As Encoding = Encoding.Default
Dim srcBytes() As Byte
srcBytes = src.GetBytes(name)
Dim asciiBytes() As Byte = Encoding.Convert(src, dest, srcBytes)
Dim mychars(dest.GetCharCount(asciiBytes) - 1) As Char
dest.GetChars(asciiBytes, 0, asciiBytes.Length, mychars, 0)
Dim asciiString As New String(mychars)
End Function
From what I read FileStream.ReadLine reads the text with encoding UTF8 so I try to convert from UTF8 to Encoding.Default buy instead of little boxes I get question marks.
I have a flat file with text that has a special character like this: "RIBA® Generic Strip Labeling." so the registerd symbol is coming as square when i am simply reading the file in c#. is there a way to read the symbol as is and print on screen? i am working in on a console application. Also other german characters, not all but a few are showing as squares as well.
I have a web application project with a App_GlobalReousrces folder which contains a *.resx file that I would like to access (read) from a separate class library project.
I have web form, wich has to post its data to different server, if data i post is valid, target server creates xml file. How can i read the created file from my original site?
Only way i can think off so far is to create iframe in wich postback is made, and somehow after postback page wich contains iframe would read the xml..
In my application, i have one fileupload control which will take excel file. I want to read this excel file and want to store in datatable. How will i do this. I am using visual studio 2008.
I am reading an excel file in C#.NET. The data is being read successfully but there is problem with some hyperlinks stored in the excel file. I can read their text but i dont know how to get the underlying link/url of the column. I couldnt find much help on google as well. if someone has worked in a similar situation please let me know what can be done.edit::: i am using OleDb namespace for establishing a connection with the Excel file so if someone can post a solution which applies to this situation
I have some code that reads records from an excel file and then imports that data into an sql database. The issue only happens when the excel file has more then 350 rows in it. In the middle of the import it just stops executing and I get directed to the 'Internet Explorer cannot display the webpage' page or just a blank page when using firefox.
I dont get any time out errors or any error at all but still I tried messing around with the script timeout settings but still does the same thing at about the 2 min 30 sec mark.
I need to be able to read an excel file from a file upload control but I can not save the file to disk first, it must be done in memory.
[Code]....
Above is my code for reading the data file if it IS saved to disk, but again, I have to be able to do this without saving the file to disk, it must be done in memory. I have not been able to find any sample code anywhere on how to do this from memory, everything seems to force the file be uploaded, saved to disk, and then read in the connection string, which again I can not do.
I understand how to use a connection string object to read excel sheets. What I don't know is how to follow a hyperlink inside excel, grab matching data from the linked page and return it to my database. Essentially, the spreadsheet has two columns:
Title | Class#
Class# has the hyperlink which links to an internal web site. The connected page has a course description and any pre-required classes that must be taken before you can take this class. This is where I'm rather stumped as I've not had to do this type of thing before.
But some times the file that is read, reports that there is more rows than there actually are. i.e. I only have 300 lines of data but the read reads in 500. My question is, and I am sure I have seen this somewhere but I cannot find it now, is how do I get the reader to stop reading at the first blank line?
in my application i have to read from an excel files and check the value of every cell i'm using an OleDb connection to open it and reading but i have this issue if some of the cells in the excel sheet is having this warning when i try to read it returns DBNull ??could any one give me a clue ....knowing that i can not force the user for not having this warning ...i have to solve this within my code .
I am using reading data from excel file and inserting into sql server using following article, it seems to be working correctly except when I do page refresh normally, it again execute the the btnUpload_click. I want that once the record imported and if user refresh the page again it should ask for enter file name again. let me know how do I resolve this? [URL]
I need to read an Excel work book with 2 sheet which have more than 60,000 records. The application is an ASP.Net application so the performance matters.
Which approach should I take? Sohuld I do it using Microsoft.Office.Interop.Excel or should I do it using OLEDB in ADO.Net?
I can directly use to read and display Excel or CSV files using asp web control(GridView, sqldatasource etc). I do NOT want to upload the file first to an sql database before reading them, I just want to read the files directly. I am using asp.net 2.0 and c#.
I know this is probably a pretty easy thing to do and it is if I can upload the file and store it onto the hard drive of the server. What I need to do is read the text file into memory and then parse through it one line at a time. Anyone have any code that demonstrates that?
I have a Webcontrol, that I create completely dynamically and it contains radiobuttonList. How can I acces this radibuttonlist values, on pages where I register this control?
public class MyControl: WebControl pnContainer = new Panel(); rbl = new RadioButtonList(); liResume = new ListItem("Resume", "Resume"); liReopen = new ListItem("ReOpen", "ReOpen"); rbl.Items.Add(liResume); rbl.Items.Add(liReopen); pnContainer.Controls.Add(lblReOpenTitle); pnContainer.Controls.Add(rbl); this.Controls.Add(pnContainer);
How do we determine which country I'm.Let's say I created the application and i want to have a flag in upper right of the page.if the user browse my page it display the flag where he from.let's say he's browsing my page in america the American Flag will be displayed.if i browse my page here in the Philippines the Philippine Flag will be displayed.
In the above mentioned article at "[URL]"Â instead of selecting the existed table in dbserver is it possible to create a dynamic database table based upon the structure of the excel file to be loaded??
I would like ask you for some ideas how can I write mechanism that will be automatically read files from folder. I don't know how to schedule the write task. I want to check for new file everyday and if the new file is in the folder read it.
I have a scenario where I have to read an excel file to dump records in a mysql database. The code generates an exception Sheet1 not found. I have pasted the code below. Please let me know the solution to the exception. I have given the correct read/write/modify settings to my excel file.
if (fileUpload1.PostedFile.FileName.EndsWith(".xls") || fileUpload1.PostedFile.FileName.EndsWith(".XLS")) { string fileName = Server.MapPath(fileUpload1.PostedFile.FileName); string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties=Excel 8.0"; // Create the connection object OleDbConnection oledbConn = new OleDbConnection(connString); try { // Open connection oledbConn.Open(); // Create OleDbCommand object and select data from worksheet Sheet1 OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Sheet1$]" , oledbConn); // Create new OleDbDataAdapter OleDbDataAdapter oleda = new OleDbDataAdapter(); oleda.SelectCommand = cmd; // Create a DataSet which will hold the data extracted from the worksheet. DataSet ds = new DataSet(); // Fill the DataSet from the data extracted from the worksheet. oleda.Fill(ds, "RestaurantExcelData"); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { Response.Write("Data: " + ds.Tables[0].Rows[i].ItemArray[0].ToString() + ""); } } catch(Exception e1) { } finally { // Close connection oledbConn.Close(); } } else { Response.Write("File Not Excel (xls||XLS)"); }
But it shows me an errormessage when I run this query:
string query = "Select * from [IO_Definition$]";
IO_Definition is the name of the spreadsheet in my excel file. I also added the excel file to the App_Data folder of the website.
The error is:
The Microsoft Jet database engine could not find the object 'IO_Definition$'. Make sure the object exists and that you spell its name and the path name correctly.
The thing is, when I write the absolute path of the excel file in the connectionString it does work. Is there anyway I can make it work without writing the absolute path?