Click here to Skip to main content
15,916,318 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello there,

Can someone please suggest a suitable data structure for the below problem:

I have row headers and column headers..and the intersecting cells have their respective values.

Note: The col names and row names should also be stored.

I'm extracting the data from an excel sheet using Apache POI and SAX parser. During extraction, I need to output the data in the above format.

What I have tried:

Sample code :
createPDF.addTableContent(incident, "Open", 1);
		createPDF.addTableContent(incident, pe.getOValue("Open&Assigned to Resolver"), 2);
		createPDF.addTableContent(incident, pe.getOValue("Open&Business Action Required"), 1);
		createPDF.addTableContent(incident, pe.getOValue("Open&Monitoring"), 2);
		createPDF.addTableContent(incident, pe.getOValue("Open&Reopened"), 1);
		createPDF.addTableContent(incident, pe.getOValue("Open&Requestor Action required"), 2);
		createPDF.addTableContent(incident, pe.getOValue("Open&RFC Implementation"), 1);
		createPDF.addTableContent(incident, pe.getOValue("Open&Work In Progress"), 2);
		createPDF.addTableContent(incident, Integer.toString(pe.getTotalCount("Open")), 1);	
		createPDF.addTableContent(incident, "In Progress", 1);
		createPDF.addTableContent(incident, pe.getOValue("In Progress&Assigned to Resolver"),2);
		createPDF.addTableContent(incident, pe.getOValue("In Progress&Business Action Required"),1);
		createPDF.addTableContent(incident, pe.getOValue("In Progress&Monitoring"), 2);
		createPDF.addTableContent(incident, pe.getOValue("In Progress&Reopened"), 1);
		createPDF.addTableContent(incident, pe.getOValue("In Progress&Requestor Action required"), 2);
		createPDF.addTableContent(incident, pe.getOValue("In Progress&RFC Implementation"), 1);
		createPDF.addTableContent(incident, pe.getOValue("In Progress&Work In Progress"), 2);
		createPDF.addTableContent(incident, Integer.toString(pe.getTotalCount("In Progress")), 1);
		createPDF.addTableContent(incident, "Pending", 1);
		createPDF.addTableContent(incident, pe.getOValue("Pending&Assigned to Resolver"), 2);
		createPDF.addTableContent(incident, pe.getOValue("Pending&Business Action Required"), 1);
		createPDF.addTableContent(incident, pe.getOValue("Pending&Monitoring"), 2);
		createPDF.addTableContent(incident, pe.getOValue("Pending&Reopened"), 1);
		createPDF.addTableContent(incident, pe.getOValue("Pending&Requestor Action required"), 2);
		createPDF.addTableContent(incident, pe.getOValue("Pending&RFC Implementation"), 1);
		createPDF.addTableContent(incident, pe.getOValue("Pending&Work In Progress"), 2);
		createPDF.addTableContent(incident, Integer.toString(pe.getTotalCount("Pending")), 1);

The current method I've tried is concatenating the col and row name using "&" and storing its value in a hash map.

For example : A&E=1, B&B=6

Problem I'm facing currently
when ever I want to extract a value from the hashmap, I have to use string processing. If I want to get the count of col A, I have to iterate and split the col and row names and add the values. If I have to get the count for row E, again I have to do the same thing.

Is there any efficient way of achieving it.

Sharing the output from my current solution. Data is extracted from the excel and should be displayed to the user as below :[^]

Kornfeld Eliyahu Peter 17-Feb-19 9:33am    
You should think of the ways of access you will use to read the data - if it is know to be simple, you can get a simpler structure, otherwise it can be more complicated...
abisheak Balaji 18-Feb-19 8:14am    
Thanks Kornfeld. Let's say I want to get the total of a column and row without using much iterations. Any specific DS for this ?
Kornfeld Eliyahu Peter 18-Feb-19 8:28am    
It means you need to access your data by row, by column and by cell... So your data should be a two-dimensional-array like (like table)...
You can create one and only convert between ABC to 123 and back... That would be very simple...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900