Page 1
Page 1
Started By
Message

Iterating through Excel and adding to specific ArrayLists (C#) PAGING MAMOUTIGER

Posted on 4/23/15 at 4:21 pm
Posted by Hu_Flung_Pu
Central, LA
Member since Jan 2013
22164 posts
Posted on 4/23/15 at 4:21 pm


I have an excel sheet that shows jobs that are going through a rebuild process. Order is from left to right with the processing time beside it. I want to Iterate through to assign to certain ArrayLists in C#. These include Milling (M) CNC (C) Drilling (D) and Finishing (F). S# is the step in the process. I want to go rows first then columns (down the right). How would I do that? Is there a better way to store it? I want it to look like this...



Notice under Milling that J2S3 is 4 not 3. This is because under Drilling, J2S2 is 3 since J2S3 is after J2S2 in sequence to the job (can't run at same time).

Then I need to start adding the times in to get a schedule. I think I would like to store all of the Jobs end times (JobEndTime) into another ArrayList. This way it will continually update the previous steps end time.

To assign the scheduling time, I would reference to JobEndTime and take the max of Jobs last end time and previous stations end time then add the processing time of the new end time. How do I go about doing this?

Been stressing about this problem for weeks.
This post was edited on 4/23/15 at 4:25 pm
Posted by CAD703X
Liberty Island
Member since Jul 2008
78081 posts
Posted on 4/23/15 at 4:43 pm to
quote:

How do I go about doing this?


damn dude, you learn SQL

seriously you are putting excel through its paces here.
Posted by Hu_Flung_Pu
Central, LA
Member since Jan 2013
22164 posts
Posted on 4/23/15 at 5:34 pm to
Thanks cad..... The 5.1 traitor
Posted by Brisketeer
Texas
Member since Aug 2013
1435 posts
Posted on 4/23/15 at 7:18 pm to
I'm assuming you know this, but you need to reference the Com interoperability library for excel. Define a range object that covers the table in the sheet you want to inspect. Then iterate the rows in the range. Within each row loop, iterate the columns of the current row.
Posted by Hu_Flung_Pu
Central, LA
Member since Jan 2013
22164 posts
Posted on 4/23/15 at 7:53 pm to
quote:

'm assuming you know this, but you need to reference the Com interoperability library for excel.


Yeah I knew that. I was gonna do a for loop and nest another one for rows.

I got those basics, I guess. I just don't know how to execute the loops and separate them into the array lists.
Posted by MamouTiger65
Baton Rouge, La
Member since Oct 2007
794 posts
Posted on 4/23/15 at 8:01 pm to
If you are using Office.Interop.Excel then check out this site LINK

Office Interop is really slow, uses lots of memory and requires Office to be installed on the server you deploy it to. An alternative would be OpenXML. You can read how to use it here LINK

If this is a small project and the computer running it will have Excel installed, then Interop should be fine.

Either way when you are looping through the columns and rows you can write to your arrays.
This post was edited on 4/23/15 at 8:06 pm
Posted by TigerRagAndrew
Check my style out
Member since Aug 2004
7217 posts
Posted on 4/23/15 at 8:15 pm to
ClosedXML is a simpler wrapper around OpenXML. Try that as well.
LINK
Posted by Hu_Flung_Pu
Central, LA
Member since Jan 2013
22164 posts
Posted on 4/23/15 at 8:36 pm to
quote:

Either way when you are looping through the columns and rows you can write to your arrays. 


How do I assign to different arrays using another column to determine which array to in?
Posted by MamouTiger65
Baton Rouge, La
Member since Oct 2007
794 posts
Posted on 4/23/15 at 9:39 pm to
I just played around with it and the easiest thing for me was to make a 2d array using Jobs and Hours.

Each hour can use up to 4 stations. None of the stations can be the same, and each job can only have one station per hour. If a station has already been used in a given hour then increment it to the next hour.

May need some tweaking but hope that helps.

This post was edited on 4/23/15 at 9:41 pm
Posted by Hu_Flung_Pu
Central, LA
Member since Jan 2013
22164 posts
Posted on 4/23/15 at 9:48 pm to
Would it work if it was two separate times? I only did 1hour for all to be easier during testing
Posted by MamouTiger65
Baton Rouge, La
Member since Oct 2007
794 posts
Posted on 4/23/15 at 10:07 pm to
I think it would. For each job, each hour you would track the station and the time it takes to complete.

If a station takes 2 hours then mark the current hour and the next hour with that station for the given job.

If that station is set to be used in the same step of another job, then just increment down by the time of the first and start marking at that point.

Without playing with it much more I'm going to stick with the job X hours array. It will just be key to have checks to make sure a station is only used once per row and tracking how far to increment for each job.

Posted by Hu_Flung_Pu
Central, LA
Member since Jan 2013
22164 posts
Posted on 4/24/15 at 9:27 am to
Brilliant man. I worked through one manually to see if it correlates with the other schedule and it does! I think that would be easier. Is there a preferred method of checking within an ArrayList for certain substrings?

Here is what I had as the ArrayList.


Like I wanna take

J3M3
//Search for previous J3 (J3C2) = 3
//Search for previous or equal M (J2M3) = 4
Take max of both and add processing time to max
Posted by Hu_Flung_Pu
Central, LA
Member since Jan 2013
22164 posts
Posted on 4/25/15 at 12:51 pm to
Sat crew bump
Posted by yankeeundercover
Buffalo, NY
Member since Jan 2010
36373 posts
Posted on 4/25/15 at 1:06 pm to
No shite, he's re-engineering the wheel for real...
Posted by TigerRagAndrew
Check my style out
Member since Aug 2004
7217 posts
Posted on 4/25/15 at 3:07 pm to
Why arraylists? Why not generic lists?
Posted by Hu_Flung_Pu
Central, LA
Member since Jan 2013
22164 posts
Posted on 4/25/15 at 3:25 pm to
quote:

No shite, he's re-engineering the wheel for real...


It's so I can run all of it from a windows form. Excel is just the basis to hold the info.
first pageprev pagePage 1 of 1Next pagelast page
refresh

Back to top
logoFollow TigerDroppings for LSU Football News
Follow us on Twitter, Facebook and Instagram to get the latest updates on LSU Football and Recruiting.

FacebookTwitterInstagram