Read through excel files and creating a csv file

kwood30

Member
Joined
Feb 25, 2018
Messages
6
Programming Experience
Beginner
I am really new to all this and I have have taken on a project that now seems abit out of my depth. I have found snippets of code through browsing and put them in some structure for what I beleive in need as you see below. the excel files have rows of data that I need to read and transfer over. The first row will have the same information in a particular number of columns, the next rows will then contain different data, but after checking so many rows, which will likely be blank, there is likely to be the same data as the first row, and so on and this could go on for many rows in one files. So I am trying to read all this to then store in memory and return it to a csv files. I have been reading up and looks like i need to use foreach and do loops with whiles in etc. This is the bit i am not understanding. Hope this makes sense. Any help would be apprciated.

C#:
Records = openExcelFile
List<csv> csv //this is the starting point, getting my files ready and open to read

Foreach (record in records)
{
   // what type of row we have?
    rowType = ValiateRow(record);

    switch (rowTYpe)
      {
        Case RowType.Header:
        Continue;    //move to the next record
        Case RowType.Blank:
        blankRows++;
        
if (blankRows > maxBLankRows)
               return;   // We are at the end
          else
            continue;             //next record
               Case RowType.Valid:
                DAF daf = ConvertTOCSV(record)
           If (CSV!= null)
            
 CSV.add(csv);
            Continue;
               }             
}  // can this be done for each record/file?
 
You should plan what you're going to write before writing anything. Start by forgetting the fact that it's a programming problem. Pick up a pen and paper and write down a set of steps to be performed that you could give to someone with no prior experience with the problem and that they could then follow to produce the desired output manually. Once you can follow those instructions and get the desired output, rewrite them in pseudo-code. Once you have pseudo-code that you can follow, THEN you should start writing C# code and the control structures to be used should be obvious.
 
Thank you for your response.
I have done what you said I just can't/ don't understand how to intemperate it into code. My structure is (And i believe this is probable simple to do for someone who knows how);
Loads all Excel files from an input directory,
Once loaded the Excel files are then transformed into a CSV structure by;
validating the excel file, if not valid, label as bad,
read the rows X number of columns (as there is the same number of columns in each excel file)
If rows are bland check for X number of times and if still blank move onto next file.
once all files are checked, convert or save to CSV.
 
The reason that you can't see what the code to do that would be like is because it's far too course-grained. That's a start but you need to break it down into far more detail.
 
If you don't know what steps would be involved, how could you ever possibly write code to do it? If you can actually do the work then you must know what steps are involved in doing the work - because you're doing them.
 
Thanks for your comment, I believe i broke it down to the best i could, and I knoe what I want, just couldn't do it in code as I have only just started learning it. I beleive I have now managed to achieve what I wanted, I just need to tweak it and test it.
Thanks again :)
 

Latest posts

Back
Top Bottom