I often see questions about how to deal with Excel files. I would like to summarize them here.
▲1. Use the Excel Interface★Restrictions: Excel 1.1 and interop must be installed. Reference: Creating an Excel Spreadsheet and Adding Data to It Programmatically http://www.csharphelp.com/archives/archive241.html#1.2、use a reflection technology. Reference: Calling a COM Component From C # (Late Binding) http://www.c-sharpcorner.com/1/call_com.asp
2. output files in csv format compatible with the Excel program (Note 1) as Excel files.★Restrictions: A, can only be used for output. B and csv can only generate single-page Excel files. (Note 2) C. Format cannot be controlled, such as Cell merging.
▲3. Use the xml import function supported by office 2003 to generate xml files that can be imported in Excel.★Restrictions: A, can only be used for output, B, does not support earlier versions.
4. Generate a binary file based on the excel file format (note 3. ▲4.1, use third-party controls, such as Aspose, website http://www.aspose.com.
★Restriction: cost-effective. ▲4.2. Write it by yourself. Refer to examples. If you are planning to take this path, you can go to the http://www.sourceforge.net to search opensource for information on Microsoft Office file formats. In fact, the Aspose mentioned in section 4.1 uses this information, but it uses obfuscators to package it and starts selling money.
★Limitation: heavy workload.
Note 1: Text Format of comma-separated columns and carriage return to separate rows NOTE 2: This method is common for "DataGrid output to Excel", such as an example on the home page of Meng xianhui, he is the Render of the redirection DataGrid, but it is just a gesture and cannot be copied under any circumstances. For example, if there is a CheckBox in the Grid and other complicated things, it won't work, it is better to generate a write loop directly from the DataTable. NOTE 3: Biff (Binary Interchange File Format) Format, refer to FILE: How to Create a BIFF5 File http://support.microsoft.com/default.aspx? Scid = kb; en-us; 150447