Click here to Skip to main content
Click here to Skip to main content

Excel XML Writer /Reader

By , 2 Aug 2010
 

Introduction

This is an Excel XML Writer/Reader which enables to generate Excel XML with hidden columns and look-ups.

The main objective of this tool is to generate the Excel datasheet from data-table and to read the Excel sheet back to the data-table (Duplex communication between data-table and Excel sheet). Since we are going to use XML to get the Excel data, you no longer need to reference Excel interop component, so the performance should be good.

See the screen-shot below to get a quick view of this tool.

Exceler.png

Background

Basic ASP.NET 2.0, Generics, XML knowledge required

Using the Component

Here, I will explain how to consume the component to generate the Excel sheet and to read the Excel sheet back to the data-table (I mean .NET datatable). In a later section, I will explain the code flow in detail.

Excel XML Writer Component

public static void exportToExcel(DataTable source, int? nHdnColumnStart, 
    int? nLookupSrcColStart, List<int> lstLookupCounts, List<int> lstDestLookupCols)

Excel XML ReaderComponent

public static DataTable ReadExcelXML(string ExcelXmlFile)

Client Call to Excel XML Writer

XMLExcelWriter.exportToExcel(ds.Tables[0], 11, 11, lstLookupCounts, lstDestLookupCols);

Client Call to Excel XML Reader

DataTable dt=XMLExcelReader.ReadExcelXML("D:\ExcelFile.xls");		  

Explanation on Component Call

public static void exportToExcel(DataTable source, int? nHdnColumnStart, 
    int? nLookupSrcColStart, List<int> lstLookupCounts, List<int> lstDestLookupCols)
  1. exportToExcel is a method name.
  2. source is a datatable you need to pass to the ExcelXML writer component.
  3. nHdnColumnStart is the int parameter that expects the start column to hide a range of columns. For Example: if you provide 5 then 5,6,7., will be hidden in the Excel sheet.
  4. nLookupSrcColStart is an interesting feature in the Writer component. It allows us to configure the lookup source columns in Excel. Here you need to tell the start column of the lookup source. The system will take the contiguous columns as the lookup sources. For example: if you provide 8 then 8,9,10., will be accounted as lookup sources.
  5. lstLookupCounts – This is to show the lookup source column data counts.
  6. lstDestLookupCols – This list will have the destination point for the source lookups. Please make sure that the sequence of this range is matching the sequence of nLookupSrcColStart. Example: I want to have the Name, SHOBBY, SJOB to be configured as lookup for a name column, then I will give the lstDestLookupCols as 1,7,8 and nLookupSrcColStart 11 (from 11th column onwards I am taking the lookup sources, see the db script to get the clarity).

Points of Interest

Preparing tools using sqlserver and ASP.NET, application performance tuning

License

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

About the Author

rajeshitpro
Software Developer (Senior) Cognizant Technology Solutions
India India
Member
Expertise in Asp.Net,Worked in variety of domains.
Have fair knowledge in using design patterns.
Presently he is working as Senior developer with cognizant India.His interest is to develop tools using Sqlserver,C#.Net.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5memberMember 917615427 Jun '12 - 19:51 
Questionwhat about Excel format?memberbatsword13 Sep '11 - 15:47 
AnswerRe: what about Excel format?memberFilipKrnjic24 Oct '11 - 22:10 
GeneralMy vote of 5memberseenit6 Sep '11 - 18:39 
GeneralMy vote of 5memberShubha_India7 Apr '11 - 8:04 
GeneralPlease correct link to codememberBo Vistisen1 Aug '10 - 21:46 
GeneralRe: Please correct link to codememberrajeshitpro2 Aug '10 - 7:44 
GeneralSource code link is brokenmemberTony Bermudez30 Jul '10 - 18:05 
GeneralRe: Source code link is brokenmemberrajeshitpro2 Aug '10 - 7:44 
GeneralRe: Source code link is brokenmemberGabriel X27 Jun '12 - 19:56 
GeneralMore Details are NeededmemberGil Fink25 Jul '10 - 8:25 
GeneralRe: More Details are Neededmemberrajeshitpro30 Jul '10 - 17:39 
GeneralAdd more details...mentorSandeep Mewara25 Jul '10 - 7:31 
GeneralFew tips for you..mvpMd. Marufuzzaman25 Jul '10 - 5:30 
GeneralRe: Few tips for you..memberrajeshitpro30 Jul '10 - 17:40 
GeneralRe: Few tips for you..mvpMd. Marufuzzaman30 Jul '10 - 18:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 2 Aug 2010
Article Copyright 2010 by rajeshitpro
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid