I am also tied to search in google. Finally am never get any article .am getting all article in ASP.NET exporting from gridview .
coming to the point now am giving the code to export html files data to excel file .from a folder .my requirement
so the bellow code works for me.
Add the:
Microsoft.Office.Interop.Excel.dll u can download from internet .
After click event my code works here:
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System;
- using System.IO;
- using Excel = Microsoft.Office.Interop.Excel;
- namespace ExportData
- {
- public partial class Form1: Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string path = textBox1.Text + "/";
- var d = new DirectoryInfo(path);
- if (textBox1.Text.Length > 0)
- {
- var files = d.GetFiles("*.html");
- foreach(var file in files)
- {
- var app = new Excel.Application();
- try
- {
- var fullPathnew = d + file.Name;
- var wb = app.Workbooks.Open(fullPathnew);
- wb.SaveAs(d + file.Name.Replace(".html", ".xls"), Excel.XlFileFormat.xlExcel7);
- wb.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- finally
- {
- app.Quit();
- }
- }
- }
- }
- }
- }
You can download the same solution bellow link.