|
|
||||||
|
#1
|
|
|
|
|
Hello.
I'm Reading data from an excel (CSV) file with header row and its fine. Now I have a file with one more line in the start (above the header) and it giving me a lot of problems. is there a way from C# to open the csv file and remove the first line? If not as excel then maybe I'll just open it as a text file and remove it (I know whats the string I want to remove). Whats the fasted way to remove a string from the beggining of a txt file? Thanks. |
|
|
|
#2
|
|
|
|
|
"nicknack" <roezohar> wrote in message
news:e3cc > I'm reading data from a CSV file with a header row What method are you using to read the CSV file? |
|
#3
|
|
|
|
|
On 5 מאי, 11:08, "Mark Rae [MVP]" <m> wrote:
> "nicknack" <roezo> wrote in message > > news:e3cc > > > I'm reading data from a CSV file with a header row > > What method are you using to read the CSV file? > > -- > Mark Rae > ASP.NET MVPhttp://www.markrae.net Hi, I'm connecting useing an oledb connection and filling a dataTable with dataAdapter. But the problem is that I need to remove the line before the reading start since its a line with only one cell with a text. I need to first remove the line, save the file and only then read it with the oledb. Thats what I think but I don't know how to remove it. Thanks. |
|
#4
|
|
|
|
|
"nicknack" <roezohar> wrote in message
news:1c4f >>> I'm reading data from a CSV file with a header row >> >> What method are you using to read the CSV file? > I'm connecting using an OleDb connection and filling a dataTable with > dataAdapter. > But the problem is that I need to remove the line before the reading > starts since it's a line with only one cell with a text. > > I need to first remove the line, save the file and only then read it > with the oledb. As you've no doubt discovered, the OleDb connection string for Excel contains a HDR=Yes option, but that only tells ADO.NET that there is *one* header row - there doesn't appear to be an option for more than one header row. Therefore, I would probably just open the file with the System.IO classes, read each line one by one, discard the first line, and then write out the remaining lines to a new file. Either that, or read the lines one by one, split them into an array, and then carry on the processing from there. It's simple enough to populate a DataTable manually in code: http://www.akamarketing.com/blog/256-csv-datatable.html |
|
#5
|
|
|
|
|
Hi Mark,
Thanks for the reply. The "HDR" doesn't work as you said, for more then one row. What I did at the end was to read the file (file.readAllLines) and then create it again after discarding the first line. Not very elegant but work :) Thanks again! roy. |
|
#6
|
|
|
|
|
"nicknack" <roezohar> wrote in message
news:7f6a > Not very elegant but works :) Sometimes that's all that matters... |
|
|
| Similar Threads | |
| how to remove line numbers in excel I am fairly new to excel and need to know how to remove the line numbers and the alphabetical cell letters at the top of my page. They appear when I print my report and I... |
|
| How to read a text file line by line and remove some line Can anyone please help me in writing the code in C++ : I want a read a file line by line,remove the lines which have length of a particular field in a line exceeding 63... |
|
| how to: remove last line from file 1 and append t0 file 2 subject says it all. how do i remove the last line from "file1" and append it to file2? my solution: use tail -1 and sed '$d' to get/remove the last line. because file1 is... |
|
| How do I remove line breaks in Excel cells? I have a series of cells in Excel with line breaks embedded within them. When I go to save the worksheet as a .txt file, this corrupts the data. Search and replace does not... |
|
|
All times are GMT. The time now is 07:32 AM. | Privacy Policy
|