Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Help me to read excel data with following header style

-----------------------------------------------------------
       Main Heading 1     |     Main heading 2              |
------------------------------------------------------------
Sub Head 1   | sub head 2 |     sub head 3                  |
-------------------------------------------------------------
             |            |                                 |


[EDIT - copied from comment]
Month |  Domestic | International
      |-------------------------------
      |	D1	D2 	  | I1		I2
-------------------------------------
Jan		12	13		11		9.5
Feb		8.5	7.4		6.5		4.5


Domestic & International columns are the main headers. D1 & D2 are sub header under Domestic. similarly I1 & I2 are under International header
Posted
Updated 16-Nov-15 8:50am
v2
Comments
ZurdoDev 16-Nov-15 14:03pm    
OK. How can we help you?
[no name] 16-Nov-15 14:27pm    
Hello Ryan,

Please find the sample excel data

Month| Domestic | International
========================
D1 D2| I1 I2
=================================
Jan 12 13 11 9.5
Feb 8.5 7.4 6.5 4.5

Domestic & International columns are the main headers. D1 & D2 are sub header under Domestic. similarly I1 & I2 are under International header


I want to read this data and insert in to data base.
ZurdoDev 16-Nov-15 14:28pm    
You repeated what you want. You haven't told us where you are stuck.
[no name] 16-Nov-15 14:30pm    
I got stuck in how I can read the columns which are merged.
[no name] 16-Nov-15 14:35pm    
I saw one sample code
const string testFileName = @"C:\Users\koo\Desktop\test\test\Test.xlsx";
string sheetName = "Sheet1";
using (SpreadsheetDocument document = SpreadsheetDocument.Open(testFileName, true))
{
WorkbookPart wbPart = document.WorkbookPart;

Sheet theSheet = wbPart.Workbook.Descendants<sheet>().Where(s => s.Name == sheetName).FirstOrDefault();

WorksheetPart wsPart = (WorksheetPart)(wbPart.GetPartById(theSheet.Id));

MergeCells mcs = wsPart.Worksheet.Descendants<mergecells>().First();

var mcl= mcs.ChildElements.ToList();
foreach (MergeCell mc in mcl)
{

}

}

Will this help to read the merge columns?

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