Design Idea of Excel plug-in Class Library

Source: Internet
Author: User

I. Plug-in function: provides various Excel reading methods, such as npoi, COM, and aspose. The Calling interfaces are consistent, including the Excel file path, sheet Name, read whether it contains the column header (that is, whether the first row of Excel is the column header row)


II. Implementation ideas
2.1 define an interface that provides a public method for reading Excel

Public interface iexcelreader {// <summary> // read data from datesheet in Excel to able /// </Summary> /// <Param name = "filepath"> Excel file name </param> /// <Param name = "sheetname"> sheetname </param> /// <Param name = "readheader"> whether to read the first line </Param >/// <returns> </returns> datatable readfromexcel (string filepath, string sheetname = "sheet1", bool readheader = false );}

 

2.2 each excel reading method defines an implementation class separately and is integrated with the public interface.

Public class excelreadernpoiimpl: iexcelreader {// <summary> // read Excel Data and return it as a datatable (npoi Mode) /// </Summary> /// <Param name = "filepath"> </param> /// <Param name = "sheetname"> </param> /// <Param name = "readheader"> whether to include the column header </param> // <returns> </returns> Public datatable readfromexcel (string filepath, string sheetname = "sheet1", bool readheader = false ){...}} public class excelreaderasposeimpl: iexcelreader {// <summary> // read Excel Data and return it as a datatable (aspose) /// </Summary> /// <Param name = "filepath"> </param> /// <Param name = "sheetname"> </param> /// <Param name = "readheader"> whether to include the column header </param> // <returns> </returns> Public datatable readfromexcel (string filepath, string sheetname = "sheet1", bool readheader = false ){...}}

 

2.3 define a strategy class and return the object of a specific implementation method through the static method of this class for the caller to operate. The caller does not need to create a specific class on the client. The new process is implemented by the Strategy class.

/// <Summary> /// select the method for reading Excel content /// </Summary> public class excelreadertypeselect {// <summary> // return an aspose implementation iexcelreader // </Summary> /// <returns> </returns> Public static iexcelreader asposereader () {return New excelreaderasposeimpl ();} /// <summary> /// return an iexcelreader implemented by com /// </Summary> /// <returns> </returns> Public static iexcelreader comreader () {return New excelreadercomimpl ();} /// <summary> /// return an iexcelreader implemented by npoi /// </Summary> /// <returns> </returns> Public static iexcelreader npoireader () {return New excelreadernpoiimpl ();}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.